Skip to content

Instantly share code, notes, and snippets.

@jlongster
jlongster / Gruntfile.js
Last active Aug 29, 2015
example Gruntfile for grunt-sweet.js
View Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
sweetjs: {
options: {
modules: ['es6-macros'],
sourceMap: true,
nodeSourceMapSupport: true
},
src: {
@julianlam
julianlam / gist:a4e9c4c9458e0ccdd459
Created Oct 20, 2014
[nodebb-script-ajaxify-disable] Disable the Single Page Application aspect of NodeBB
View gist:a4e9c4c9458e0ccdd459
<script>
ajaxify.go = function(url) {
window.location.href = RELATIVE_PATH + '/' + url;
};
</script>
@vvo
vvo / the-simplest-config-module.js
Last active Aug 29, 2015
The simplest configuration module you will ever need
View the-simplest-config-module.js
// This module will load ./process.env.APP_ENV.json and exports it
// And will also read args from command line and merge them, i.e.:
// node index.js --server.hostname=192.168.56.1
// will work.
// Usually this module should be in ./config/index.js
// And then you use var config = require('./config');
// You must set an APP_ENV
if (!process.env.APP_ENV) {
View shellql.py
#!/usr/bin/env python2.7
try:
import simplejson as json
except ImportError:
import json
import tempfile
import sqlite3
import subprocess
@bmaddy
bmaddy / gist:912632
Created Apr 10, 2011
Continuation monad in javascript
View gist:912632
function M(){};
M.contResult = function(value){
return function(cont){
console.log('in result: ' + value);
return cont(value);
}
}
M.contBind = function(mValue, mFunc){
@disnet
disnet / scheme.sjs
Created Oct 8, 2012
start of scheme in sweet.js (modified from http://pastebin.com/0nPBg8LY)
View scheme.sjs
macro sexp {
case () => {
;
}
case ($p) => {
$p
}
case ($x $y) => {
$x($y);
}
View monad.coffee
Maybe = (@value) ->
Maybe::ret = -> @value
Maybe::bind = (fn) ->
if @value? then (fn @value) else undefined
Maybe.lift = (fn) -> (val) -> new Maybe (fn val)
addOne = (val) -> val + 1
maybeAddOne = Maybe.lift addOne
@bahmutov
bahmutov / index.js
Last active Apr 7, 2016
Is it pure?
View index.js
// A: is this pure function?
function sum(a, b) { return a + b }
// B: is this a pure function?
const k = 2
function addK(a) { return a + k }
// C: is this a pure function?
function sub(a, b) { return sum(a, -b) }
// D: is this a pure function?
function sub(a, b, summer) { return summer(a, b) }
// E: is this a pure function?
@matthewp
matthewp / gist:3099268
Created Jul 12, 2012
XMLHttpRequest wrapped into a promise
View gist:3099268
function xhr(options) {
var deferred = Q.defer(),
req = new XMLHttpRequest();
req.open(options.method || 'GET', options.url, true);
// Set request headers if provided.
Object.keys(options.headers || {}).forEach(function (key) {
req.setRequestHeader(key, options.headers[key]);
});
@emilbjorklund
emilbjorklund / breakpoints_via_css.html
Created Apr 24, 2012
Width detection via sneaky CSS rules
View breakpoints_via_css.html
<!DOCTYPE html>
<!--[if IE 8]> <html lang="sv-SE" class="no-js ie8"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="sv-SE" class="no-js"> <!--<![endif]-->
<head>
<meta charset="UTF-8">
<title>Breakpoint detection test</title>
<style type="text/css" media="screen">
@media screen and (min-width: 320px) {
#page:after {
content: 'smallest'; /* represent the current width-bracket */