Skip to content

Instantly share code, notes, and snippets.

@jlongster
jlongster / Gruntfile.js
Last active August 29, 2015 13:56
example Gruntfile for grunt-sweet.js
module.exports = function(grunt) {
grunt.initConfig({
sweetjs: {
options: {
modules: ['es6-macros'],
sourceMap: true,
nodeSourceMapSupport: true
},
src: {
@julianlam
julianlam / gist:a4e9c4c9458e0ccdd459
Created October 20, 2014 14:29
[nodebb-script-ajaxify-disable] Disable the Single Page Application aspect of NodeBB
<script>
ajaxify.go = function(url) {
window.location.href = RELATIVE_PATH + '/' + url;
};
</script>
@vvo
vvo / the-simplest-config-module.js
Last active August 29, 2015 14:08
The simplest configuration module you will ever need
// 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) {
#!/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 April 10, 2011 19:17
Continuation monad in javascript
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 October 8, 2012 19:02
start of scheme in sweet.js (modified from http://pastebin.com/0nPBg8LY)
macro sexp {
case () => {
;
}
case ($p) => {
$p
}
case ($x $y) => {
$x($y);
}
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 April 7, 2016 14:08
Is it pure?
// 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 July 12, 2012 16:50
XMLHttpRequest wrapped into a promise
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 April 24, 2012 16:03
Width detection via sneaky CSS rules
<!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 */