Skip to content

Instantly share code, notes, and snippets.

@imaman
imaman / show_hiearchy.bash
Last active May 28, 2018 13:22
print hierarchy of JS classes
node -e "var p = 'src/locators/selectors'; var kids = fs.readdirSync(p).map(x => fs.readFileSync(p + '/' + x, 'utf-8')).join('\n').split('\n').filter(x => x.match(/class .*{/)).map(x => x.replace('class ', '').replace(' {', '').replace(' extends ', ' ')).map(x => x.split(' ')).reduce((kids, p) => { kids[p[1]] = kids[p[1]] || []; kids[p[1]].push(p[0]); return kids; }, {}); function pr(indentation, k) { console.log(indentation + k); (kids[k] || []).forEach(x => pr(indentation + ' ', x)); }; pr('');"
@imaman
imaman / combined.log
Created November 15, 2018 10:17
update error: log + error message "cannot be executed in its current status of [CREATE_IN_PROGRESS]"
This file has been truncated, but you can view the full file.
2018-11-12T22:04:14.366Z [main] silly: Packagr.run(spec_compiled, spec_compiled, undefined)
2018-11-12T22:04:14.368Z [main] info: Compiling /home/imaman/code/data-platform/metric-machine/backend/a.servicemix.ts
2018-11-12T22:04:14.368Z [main] silly: Executing:
2018-11-12T22:04:16.591Z [main] silly: Packagr.run(build, build, undefined)
2018-11-12T22:04:16.591Z [main] info: Compiling /home/imaman/code/data-platform/metric-machine/backend/src/store/compute
2018-11-12T22:04:16.591Z [main] silly: Executing:
2018-11-12T22:04:20.684Z [main] silly: Packagr.run(build, build, undefined)
2018-11-12T22:04:20.684Z [main] info: Compiling /home/imaman/code/data-platform/metric-machine/backend/src/support/errorSink
2018-11-12T22:04:20.684Z [main] silly: Executing:
2018-11-12T22:04:22.158Z [main] silly: Packagr.run(build, build, undefined)
@imaman
imaman / combined.log
Created November 15, 2018 10:17
update error: log + error message "cannot be executed in its current status of [CREATE_IN_PROGRESS]"
This file has been truncated, but you can view the full file.
2018-11-12T22:04:14.366Z [main] silly: Packagr.run(spec_compiled, spec_compiled, undefined)
2018-11-12T22:04:14.368Z [main] info: Compiling /home/imaman/code/data-platform/metric-machine/backend/a.servicemix.ts
2018-11-12T22:04:14.368Z [main] silly: Executing:
2018-11-12T22:04:16.591Z [main] silly: Packagr.run(build, build, undefined)
2018-11-12T22:04:16.591Z [main] info: Compiling /home/imaman/code/data-platform/metric-machine/backend/src/store/compute
2018-11-12T22:04:16.591Z [main] silly: Executing:
2018-11-12T22:04:20.684Z [main] silly: Packagr.run(build, build, undefined)
2018-11-12T22:04:20.684Z [main] info: Compiling /home/imaman/code/data-platform/metric-machine/backend/src/support/errorSink
2018-11-12T22:04:20.684Z [main] silly: Executing:
2018-11-12T22:04:22.158Z [main] silly: Packagr.run(build, build, undefined)
@imaman
imaman / gist:2f990c0aa214b198054e6c76eea20bab
Created November 18, 2018 17:34
AWS lambda node.js context object
callbackWaitsForEmptyEventLoop;done;succeed;fail;logGroupName;logStreamName;functionName;memoryLimitInMB;functionVersion;getRemainingTimeInMillis;invokeid;awsRequestId;invokedFunctionArn"
@imaman
imaman / gist:0c428ccc0eac32b76f493fcaa7985571
Last active November 20, 2018 08:19
ts unit testing boilerplate
npm install --save-dev mocha ts-node chai chai-subset @types/chai @types/mocha @types/chai-subset
cp /dev/stdin src/u.test.ts <<EOF
import * as chai from 'chai';
import chaiSubset = require('chai-subset');
chai.use(chaiSubset);
const {expect} = chai;
@imaman
imaman / cdp.js
Created December 25, 2018 13:49
Drill info iframes which are not SAME_ORIGIN
const CDP = require('chrome-remote-interface');
const chromeLauncher = require('chrome-launcher');
// cdp.js: a playground for using chrome-devtools-protocol.
// Plug-in your own code at the run() function, below.
//
// Usage:
// $ node scripts/cdp.js
//
// This program requires node version >= 8.
@imaman
imaman / cdp.js
Last active June 24, 2024 05:41
iframe inspection w/o getFlattenedDocument()
const CDP = require('chrome-remote-interface');
const chromeLauncher = require('chrome-launcher');
const util = require('util');
// cdp.js: a playground for using chrome-devtools-protocol.
// Plug-in your own code at the run() function, below.
//
// Usage:
// $ node scripts/cdp.js
//
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)
@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”.
@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"