Skip to content

Instantly share code, notes, and snippets.

@grayrest
grayrest / dumb_graph.js
Created October 11, 2012 19:17
Simple JS implementation of Prismatic's blog post about Graph
function sum (fn, xs) {
var toRet = 0;
for (var i = 0, ii = xs.length; i < ii; i++) {
toRet += fn(xs[i], i, xs);
}
return toRet;
}
function update(t, o) {
for (var k in o) {
@tcr
tcr / gist:4416956
Last active November 29, 2017 03:38
Make a callable() object in all browsers and Node.js
if (!Object.__proto__) {
var sandbox = function () {
// create an <iframe>
var iframe = document.createElement("iframe");
iframe.style.display = "none";
document.documentElement.appendChild(iframe);
return frames[frames.length - 1];
}
var iframe = sandbox();
@iamamused
iamamused / publisher.rb
Last active January 6, 2017 13:32
Post publishing plugin for Jekyll
module Jekyll
class PostPublisher < Generator
safe false
def replace(filepath, regexp, *args, &block)
content = File.read(filepath).gsub(regexp, *args, &block)
File.open(filepath, 'wb') { |file| file.write(content) }
end
def generate(site)
@wolfeidau
wolfeidau / online.js
Created March 14, 2013 03:57
Online variance algorithm
exports.update = function (accumulator, value) {
accumulator.n++;
var delta = value - accumulator.mean;
accumulator.mean += delta / accumulator.n;
accumulator.m2 += delta * (value - accumulator.mean);
};
exports.variance = function (accumulator) {
return accumulator.m2 / (accumulator.n - 1)
};
@mkuklis
mkuklis / gist:5294248
Last active September 7, 2021 21:39
auto curry in JavaScript
function toArray(args) {
return [].slice.call(args);
}
function autocurry(fn) {
var len = fn.length;
var args = [];
return function next() {
args = args.concat(toArray(arguments));
return (args.length >= len) ?
@chikamichi
chikamichi / gist:5417680
Last active December 16, 2015 10:08
A fully-fledged CoffeeScript boilderplate for authoring jQuery plugin. It abides by the guidelines found at http://docs.jquery.com/Plugins/Authoring#Namespacing
###
FooBar jQuery Plugin v1.0 - It makes Foo as easy as coding Bar (?).
Release: 19/04/2013
Author: Joe Average <[email protected]>
http://github.com/joeaverage/foobar
Licensed under the WTFPL license: http://www.wtfpl.net/txt/copying/
###
(($, window, document) ->
@CrossEye
CrossEye / composeVariadic.js
Last active October 24, 2017 07:28
Variadic compose by multiple calls
var compose = function compose(f) {
var queue = f ? [f] : [];
var fn = function fn(g) {
if (arguments.length) {
queue.push(g);
return fn;
}
return function() {
var args = Array.prototype.slice.call(arguments);
queue.forEach(function(func) {
@thomsbg
thomsbg / compile_templates.js
Last active December 22, 2015 20:29
Loop through all the view prototype objects in a namespace, transforming their templateId into a template function.
var compileTemplates = function() {
_.each(App.Views, function(View) {
if (View.prototype.templateId) {
// The templateId references the id of a DOM element containing
// the content of the template
var html = jQuery('#' + View.prototype.templateId).html() || '';
View.prototype.template = _.template(html);
}
});
}
@thomsbg
thomsbg / comment.js
Last active December 22, 2015 22:39
Using this.ajax inside a model
App.Models.Comment = Backbone.Model.extend(_.extend({}, App.Mixins.Ajax, {
urls: {
flag: '/comments/flag_comment/:id'
},
flag: function(formData) {
this.set('is_flagged', true);
return this.ajax('flag', {
data: formData,
error: function() {
@dherman
dherman / realms-api.md
Last active September 7, 2024 17:42
ES6 Realms API

Notational Conventions

This section describes the conventions used here to describe type signatures.

A [T] is an array-like value (only ever used read-only in this API), i.e., one with an integer length and whose indexed properties from 0 to length - 1 are of type T.

A type T? should be read as T | undefined -- that is, an optional value that may be undefined.

Realms