Skip to content

Instantly share code, notes, and snippets.

executeApplicationScript: function(message, sendReply) {
for (var key in message.inject) {
window[key] = JSON.parse(message.inject[key]);
}
loadScript(message.url, sendReply.bind(null, null));
}
function loadScript(src, callback) {
var script = document.createElement('script');
script.type = 'text/javascript';
function runServer(options, readyCallback) {
var app = connect()
.use(loadRawBody)
.use(openStackFrameInEditor)
.use(getDevToolsLauncher(options))
.use(statusPageMiddleware)
// Temporarily disable flow check until it's more stable
//.use(getFlowTypeCheckMiddleware(options))
.use(getAppMiddleware(options));
@sghiassy
sghiassy / gist:4333140
Created December 18, 2012 23:44
block_time_exceptions
array
0 =>
array
0 =>
object(stdClass)[288]
public 'block_time_id' => string '492413' (length=6)
public 'exception_date' => string '2012-12-10' (length=10)
1 =>
array
0 =>
@sghiassy
sghiassy / gist:4333244
Created December 18, 2012 23:59
Marc sucks
array
492413 =>
array
0 =>
object(stdClass)[288]
public 'exception_date' => string '2012-12-10' (length=10)
492414 =>
array
0 =>
object(stdClass)[289]
@sghiassy
sghiassy / StringPermutation.js
Last active June 17, 2017 05:38
A string permutation example written in JavaScript (ES6)
// NOTE: This is written using ES6 - make sure your JavaScript compiler is ES6 compliant
class StringPermutation {
constructor(str) {
this.originalString = str.slice(); // deep copy string
}
printAllPermutationsWithDuplicates() {
this.permutate(
class Node {
constructor(value = "", parent = undefined) {
this.value = value;
this.parent = parent;
this.children = [];
if (this.parent != undefined) {
this.parent.children.push(this);
}
}
@sghiassy
sghiassy / dec2bin.js
Created July 1, 2017 03:53
JavaScript utility function to output full 32 bit representations of binary digits
function dec2bin(dec){
var str = (dec >>> 0).toString(2);
return (str.length < 32) ? Array(32 - str.length).fill(0).join('').concat(str) : str;
}
@sghiassy
sghiassy / reservoir_sampling.js
Created July 15, 2017 03:52
A simple JavaScript implementation of Reservoir Sampling with any K length (http://www.geeksforgeeks.org/reservoir-sampling/)
class Node {
constructor(value, next) {
this.value = value;
this.next = next;
}
}
function getRandom(list, k) {
const reservoir = new Array(k);
class Spec: QuickSpec {
override func spec() {
beforeSuite {
print("☕️ before suite")
}
afterSuite {
print("🗑 after suite")
}
@sghiassy
sghiassy / StringPermutations.js
Last active March 19, 2018 04:56
A JavaScript (ES6) implementation of printing all Permutations of a String
// Print all permutations of a string in JavaScript (ES6)
// O(2^n) runtime
class StringSubsets {
constructor(str) {
this.str = str;
}
print() {
const map = new Map();