pushing to remote branch with different name -- 08.09.2021 %
Some times you rename a branch locally and want to push it to a remote branch with a different name. This is how:
$ git push -u origin localBranch:remoteBranch
source: stack-overflow
Snippets are one of my favorite parts of programming. The shear endless depth of command line tricks and customizations is so exciting! Here is a collection I maintain for myself to comeback to.
Also navigable by list of snippet types here.
Some times you rename a branch locally and want to push it to a remote branch with a different name. This is how:
$ git push -u origin localBranch:remoteBranch
source: stack-overflow
How fast is that new function?
import { xx } from 'xx';
+import { performance } from 'perf_hooks';
@@ -160,7 +161,10 @@ const userSessionMiddleware = async (req: XRequest, res: ExpressResponse, ne
+ var t0 = performance.now();
req.isBot = headersIndicateBot(req.headers);
+ var t1 = performance.now();
+ console.log('Took', (t1 - t0).toFixed(4), 'milliseconds to calculate is bot');
source: https://www.sitepoint.com/measuring-javascript-functions-performance/
Some servers at work require yubikey authentication and for some reason I have to fetch and verify every time I want to use it.
$ export SSH_AUTH_SOCK=~/.gnupg/S.gpg-agent.ssh
$ gpg --card-edit
fetch
verify
enter key
via pass yubikey
quit
$ ssh-add -L
$ ssh travis@serverX
Today I had a .js file that I needed to import into the rest of a TypeScript app but could not convert it to a .ts file. To get around this limitation I added an accompanying .d.ts file.
countryConfig.js
const countries = [
{
code: 'de',
domainExtension: '.de'
},
...
];
exports.countries = countries;
countryConfig.d.ts
interface Country {
code: string;
domainExtension: string;
}
export const countries: Array<Country>;
app.ts
import countries from './countryConfig'
...
source: https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-d-ts.html
How to browse git diff of two hashes but exclude some files. In this case any file with test in the name won’t be in the diff.
gd xxxsha001xxx...xxxsha002xxx -- $(gd --name-only xxxsha001xxx...xxxsha002xxx | rg --invert-match test)
“gd” == “git diff”, via zsh git plugin
At work we use istanbul js for code coverage but at times the cli output is not enough to debug. Luckily istanbul also outputs a HTML report that can be viewed with the following command:
$ npx http-server ./coverage/lcov-report
I use the Bear Notes app on IOS which has a nice markdown export feature. From there it is easy to air drop the file to my mac then I paste it into my org notes after converting it.
$ pandoc -f markdown -t org -o note.org /tmp/md_note.md && pbcopy < /tmp/md_note.md
source: stackexchange
How to use a GPG key stored on a flash drive to encrypt files? I was perplexed for sometime. Eventually I figured out instead of exporting, importing, file system linking.. you just use a remote key ring that contains the keys you want!
$ gpg --full-generate-key --homedir /Volumes/usb_flash_stick/key_homedir
$ gpg --encrypt-files --homedir /Volumes/usb_flash_stick/key_homedir -r XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ./file_a
This also bring the possibility of only storing the public key locally and having the secret key safe on the USB. See how to move keys snippet.
Before putting a tar file somewhere hard to access like S3 Glacier I note what is in it. I create a manifest file. Simply list the file names within:
$ tar tvf example.tar
With more automation worked in I came up with this:
$ for x in $(fd -e tar) ; do (tar tvf "$x" && echo "\n") ; done > /tmp/example_manifest
To prevent upload errors to S3 Glacier I keep my files ~500mb. So larger ones must be split.
$ split -b 500mb example.txt example.txt.part