Skip to content

Instantly share code, notes, and snippets.

View zeusdeux's full-sized avatar
👾
i wear my sunglasses at night so i can — so i can justify the money spent on 'em

Mudit zeusdeux

👾
i wear my sunglasses at night so i can — so i can justify the money spent on 'em
View GitHub Profile
@zeusdeux
zeusdeux / simple-vm.go
Created November 21, 2015 19:04 — forked from tomnomnom/simple-vm.go
Simple VM in Go
package main
import (
"fmt"
"log"
"strings"
)
// Ops
const (
@zeusdeux
zeusdeux / ES5vsES6.js
Last active September 6, 2023 15:03
ES5 inheritance vs ES6 inheritance
/* ES6/ES2015 classes */
class A {
constructor() {
this.a = 10
}
print() {
console.log(this.a, this.b)
}
}
@zeusdeux
zeusdeux / slim-redux.js
Created October 20, 2015 06:52 — forked from gaearon/slim-redux.js
Redux without the sanity checks in a single file. Don't use this, use normal Redux. :-)
function mapValues(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
result[key] = fn(obj[key], key);
return result;
}, {});
}
function pick(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
if (fn(obj[key])) {
@zeusdeux
zeusdeux / tdz-1.js
Created October 13, 2015 18:42 — forked from rwaldron/tdz-1.js
Temporal Dead Zone
{
// The block has begun, we're in a new block scope. The TDZ for the "a" binding has begun
var f = function() {
// 2. Because f() is evaluated before `a` is actually declared,
// an exception will be thrown indicating to the author that
// `a` is not yet defined.
console.log(a);
};
@zeusdeux
zeusdeux / flexbox-grid.scss
Created October 3, 2015 17:22
flexbox based simple grid system
/* Simple flexbox based grid system */
$columns: 12;
@mixin layout-cols($device) {
@for $i from 1 through 12 {
.l-#{$device}-col-#{$i} {
flex: 0 0 $i / $columns * 100%;
}
}
@zeusdeux
zeusdeux / git-branch-simplify.md
Last active May 5, 2017 14:43 — forked from datagrok/git-branch-simplify.md
How to simplify the graph produced by git log --graph

Ideas for improvements to git log --graph

I will maybe someday get around to dusting off my C and making these changes myself unless someone else does it first.

Make the graph for --topo-order less wiggly

Imagine a long-running development branch periodically merges from master. The git log --graph --all --topo-order is not as simple as it could be, as of git version 1.7.10.4.

It doesn't seem like a big deal in this example, but when you're trying to follow the history trails in ASCII and you've got several different branches displayed at once, it gets difficult quickly.

@zeusdeux
zeusdeux / README.md
Last active August 28, 2015 08:59 — forked from HenrikJoreteg/README.md
Minimalist routing in Redux

Why would you want to do this? Because you often don't need more. It's nice to not have to think about your "router" as this big special thing.

Instead, with this approch, your app's current pathname is just another piece of state, just like anything else.

This also means that when doing server-side rendering of a redux app, you can just do:

var app = require('your/redux/app')
var React = require('react')
@zeusdeux
zeusdeux / lookupInsertionIndex.js
Last active August 29, 2015 14:26
Use binary search to find the index where the given element needs to be inserted into the given sorted array
// use binary search to return index where given element needs to be inserted in the input array (must be sorted)
function binarySearchForInsertionIndex(arr, el, index = 0) {
const mid = ~~(arr.length / 2)
if (!arr.length || arr[mid] === el) return index
if (el < arr[mid]) return binarySearchForInsertionIndex(arr.slice(0, mid), el, mid + index - 1)
if (el > arr[mid]) return binarySearchForInsertionIndex(arr.slice(mid + 1), el, mid + index + 1)
}
@zeusdeux
zeusdeux / prettyTraces.js
Created July 24, 2015 16:48
Pretty indented stack traces
/*
#
# Example final output:
#
# 1000 main
# 1000 workLoop
# 900 read
# 900 __sys_read
# 100 parse
# 100 strcmp
@zeusdeux
zeusdeux / flatten.js
Last active August 6, 2017 23:41
Flatten nested arrays
function flatten(arr) {
return arr.reduce(
(acc, c) => acc.concat(Array.isArray(c) ? flatten(c) : c),
[]
);
}