Skip to content

Instantly share code, notes, and snippets.

@oakfang
oakfang / fetchmid.js
Created February 16, 2016 09:49
Redux middleware for simple fetches
const asyncFetchMiddleware = store => next => action => {
let {type, request} = action;
if (type.endsWith('_ASYNC')) {
fetch(request)
.then(response => response.json())
.then(payload => store.dispatch({
type: type.replace(/ASYNC$/, 'SUCCESS'),
payload
}))
.catch(payload => store.dispatch({
@oakfang
oakfang / js.py
Last active April 7, 2023 04:45
How to import js modules into python
import sys
import jiphy # pip install
from os import path
from types import ModuleType
class JsFinder(object):
def find_module(self, name, m_path):
name += '.js'
if m_path is not None:
@oakfang
oakfang / d.hs
Last active December 4, 2015 01:11
A Numenera attack roller written in Haskeel for infix functions
import ArgParse
import Dice.IO
import Dice.Pure
handleOptions :: Option -> IO ()
handleOptions (Level level) = rollAgainst level >>= (\result -> putStrLn $ rollMessage result)
main = do
argparse handleOptions
function exporter(publics, privates) {
privates = privates || {};
var all = Object.assign({}, publics, privates);
publics.__test = function (t) {
var str = t.toString().match(/\{((.|\s)*)\}/)[1];
with (all) {
eval(str);
}
};
return publics;
@oakfang
oakfang / wat.js
Created November 3, 2015 15:07
Prototype and for...in
// using ES5, but still relevant
var map = {
a: 1,
b: 2
};
Object.prototype.thisIsReallyReallyPrivate = 'foo'
for (var key in map) {
console.log(key);
@oakfang
oakfang / webworker.js
Last active October 19, 2015 13:52
WebWorker module
function functionToBlob(func) {
return new Blob([`(${func.toString()})()`]);
}
function importAsBlob(func) {
return new Blob([`var ${func.name} = ${func.toString()}`]);
}
function getFunctionUrl(func, imported) {
return URL.createObjectURL((imported ? importAsBlob : functionToBlob)(func));
from pluginable import Pluginable
class MyClass(Pluginable):
pass
@oakfang
oakfang / main.pony
Created May 5, 2015 13:14
My first pony script
interface Shouter
fun shout(env: Env)
class Person
let name: String
var age: U8
new create(name': String, age':U8) =>
name = name'
age = age'
@oakfang
oakfang / git-blog
Created April 28, 2015 12:25
Git commands to make life easier
# Show all commits of current branch since its beginning
# Add flags as though it were git log
git log $(git parent)..HEAD $*
@oakfang
oakfang / gist:ab514fa869225bc1b56b
Last active August 29, 2015 14:14
Turn your beautiful style sheep into CSS style sheets with ease!
/*
sheep.js
Turn your beautiful style sheep into CSS style sheets with ease!
*/
(function (globals) {
var forEachDOM = function (selector, callback) {
Array.prototype.forEach.call(document.querySelectorAll(selector), callback);
};