Skip to content

Instantly share code, notes, and snippets.

@imaman
imaman / simple-prompt.sh
Created May 29, 2021 10:35
simple bash prompt
BLUE="\[\033[01;34m\]"
~/code/sample-monorepo$ WHITE="\[\033[01;00m\]"
~/code/sample-monorepo$ PS1="${debian_chroot:+($debian_chroot)}$BLUE\w\$ $WHITE"
@imaman
imaman / my-public-key
Created September 20, 2020 05:31
my public key
require('crypto').publicEncrypt("-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAxm6YetHJ5gdhv7TmD9uD\nl4XErogLhypON/Hi0Qvsy3QVXukbziVKBB4pgtNU303NMTVYuakUpYuyVuOiwaTv\nXVf8gyB6MzhbaUpVkPQimbt24kAXVmIUAA/7Hg6QqfssBFfwB+vBmPPzoZflHz1M\n+sx6pdyKwM1hK41evnTzjfY11Xhc3RmmLtPxWOSF2oR+hZ2lCtDgc5CKWQ5f5ade\n4s3RNiIKaV8U0oR4SKf1ty0PSW7/C+RPO2b7NlHKurLDIsCmTjxOkyYboQlJhH3W\nevjHrDF9Oli2mRsHPMidjkTgdjdugwda38rNS6ZvFbhNWd55HtRNCxjblFhIbs0X\nln/I86fbhOPNBt3VKBhE2lV6cgFg76JI7vS12uiQmtdj1RixulrgH8xrD+gpyyoi\nORgAYtflgr1DRHFerBqGCzds/bbR6FG/Luy3yK2zzBDVPRbM4hks3/sAZf3LVtED\nWDRB9E+Vb8SRWytidkp33l5d+2V03EE4+WalpG9FRVJCFQYSXd/ebT1qVfZMECZB\nsNrZxuznBOl8cPYA2Tros/k9hE10xCDMZbWi0Q4IKqgmCW7z9HR+D22HPwyXRsVH\nK1jyT8/1r7Qg6eEHDaGWYP5QbdrXxFUx6kFSBsglKajjaQO06VGb4XnBBArDG9Hp\nV8g3LLykdaFU592oN57DkfcCAwEAAQ==\n-----END PUBLIC KEY-----\n", Buffer.from('plain-text')).toString('hex')
@imaman
imaman / crypto-example.js
Created September 20, 2020 05:19
node crypto public/private keys
var keys = {}
crypto.generateKeyPair('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
@imaman
imaman / resolves vs. await
Created August 13, 2020 10:55
why I don't like .resolves
// with .resolves
expect(received).resolves.toBeDefined()
Received promise rejected instead of resolved
Rejected to value: [RequestError: Invalid authorization token provided: Bearer 0a933cd4bceffa68993ca34d58f31684d0923d31]
50 | })
51 |
> 52 | await expect(driver.runPr()).resolves.toBeDefined()
@imaman
imaman / grpcy.js
Created May 19, 2020 14:31
grcpy syubby grpcurl
const https = require('https');
const child_process = require('child_process')
const JSON5 = require('json5')
const argv = process.argv.slice(2).map(x => x.trim()).filter(Boolean)
if (argv.length !== 3) {
console.log(`Usage: ${process.argv[1]} <groupId>:<artifactId> <GRPC-method> <payload>`)
process.exit(1)
}
@imaman
imaman / kebab-case.js
Last active January 14, 2020 13:14
kebab-case
const fs = require('fs')
const path = require('path')
const dirs = [
'src/misc',
'src/cimonorepo',
'src/fingerprinting',
'src/graphs',
'__tests__/unit-tests/misc',
'__tests__/unit-tests/cimonorepo',
@imaman
imaman / commit_message_legend.txt
Last active December 9, 2019 13:06
my commit message legend
_ "tiny insignifcant changes"
_1 "dead code removal"
_2 "followups of the previous commit, trying to make it work"
_3 "refactoring"
@imaman
imaman / gist:4fe328270389642130a9d358b5ac3ad0
Created December 9, 2019 09:00
my commit message legend
_ "tiny insignifcant changes"
_1 "dead code removal"
_2 "followups of the previous commit, trying to make it work"
@imaman
imaman / gist:a74d33c55fc313561d59f40863007b47
Created July 14, 2019 08:34
exceptions are referentially transparent
So a common conception (perhaps I should say “misconception”) about Exceptions in Scala is that they should be avoided due to lack of referential transparency (see “do not throw exceptions” and “referential transparency”). I think this topic is a bit subtler that one might initially think.
The argument goes as follows: “you should be able to inline/extract variables without changing the program’s behavior. But Exceptions are not like that.”
The text-book example goes as follows:
def f1(n: Int): Int =
if (n == 0) throw new RuntimeException("zero") else n + 1
def f2(n: Int): Int = {
val x = throw new RuntimeException("zero");
if (n == 0) x else n + 1
}
The only difference between these two functions is that the throw expression was extracted into a variable. However, the two functions are not equivalent (f1(4) succeeds but f2(4) fails), hence … “exceptions should be avoided”.
Outdated stub in index: jar:///home/imaman/code/hackathon-sample/wix-framework/bazelbeam-intellij-projects/wixrpc_21/libs/bazelbeam_1.jar!/com/wixpress/greyhound/config/Configuration.class indexed at 1555508993369 with document size -1, doc=null, docSaved=true, wasIndexedAlready=true, queried at 1555508993369
indexed lengths={chars=-1, bytes=8138}
doc length=-1
file length=0
cached PSI class org.jetbrains.plugins.scala.lang.psi.impl.ScalaFileImpl
projects with file: 1
java.lang.Exception
at com.intellij.psi.stubs.StubTreeLoaderImpl.diagnoseLengthMismatch(StubTreeLoaderImpl.java:180)
at com.intellij.psi.stubs.StubTreeLoaderImpl.checkLengthMatch(StubTreeLoaderImpl.java:150)