Skip to content

Instantly share code, notes, and snippets.

var MyCollection = Backbone.Collection.extend({
reset: function(models, options) {
return Backbone.Collection.reset.call(this, models.results, options);
}
});
<?php
function mailer($smtpHost) {
return function($from, $to, $subject, $content) use ($smtpHost) {
mail(...);
};
}
$myMailer = mailer('smtp.google.com');
@xat
xat / jquery-fork.js
Last active August 29, 2015 14:03
jQuery fork
$('li', 'ul')
.fork(
$.branch('.active').show(),
$.branch(':not(.active)').hide()
);
var speak = function(text, cb) {
var u = new SpeechSynthesisUtterance();
u.text = text;
u.lang = 'de-DE';
u.rate = 1;
if (cb) u.onend = cb;
speechSynthesis.speak(u);
};
@xat
xat / gist:76ab2e78806c33f1d2e9
Last active August 29, 2015 14:04
js lookup
var data {
id_1: true,
id_2: true,
id_3: true
};
var lookup = function(dict) {
return function(key) {
return dict[key];
};
@xat
xat / gist:4f05f3e0d1f54c2daeda
Created September 12, 2014 13:21
jquery sort elements
$.fn.sorty = function(fn) {
return this.each(function() {
var $el = $(this);
$el.html($el.children().sort(fn));
});
};
var spawn = require('child_process').spawn;
var tailStream = function(file) {
return spawn('tail', ['-f', file]).stdout;
};
tailStream('./blah.txt').pipe( ... );
@xat
xat / gist:3ad9e6637944082b46ef
Last active August 29, 2015 14:06
simple flood script
var net = require('net');
var HOST = 'localhost';
var PORT = 7777;
var WORKERS = 1;
var TIMEOUT = 30; // sec
var data = 'FLOODATTACK';
var counter = 0;
var circulate = function(arr) {
var localfiles = function(opts, player, type, next) {
if (type !== 'launch') return next();
if (isUrl(opts.path)) return next();
// start local webserver, change the path to an url
};
var defaultmedia = function(opts, player, type, next) {
player.on('app-launch-pre', function(err, app) {
@xat
xat / gist:9ccf5eab2d0adb34fe8d
Created October 12, 2014 19:07
start playback of a youtube clip on chromecast using castv2
var castv2Cli = require('castv2-client');
var inherits = require('util').inherits;
var Application = castv2Cli.Application;
var RequestResponseController = castv2Cli.RequestResponseController;
var extend = require('xtend');
var noop = function() {};
var slice = Array.prototype.slice;
var Api = function(client, session) {
var that = this;