Skip to content

Instantly share code, notes, and snippets.

@z-------------
z------------- / chain.js
Last active September 4, 2015 11:38
Little function that makes it easy to connect a simple linear chain of things.
var chain = function(nodes, func) {
for (var i = 0; i < nodes.length - 1; i++) {
func(nodes[i], nodes[i + 1]);
}
};
/**
* example:
* chain([source, filter, gain, output], function(a, b) {
* a.connect(b);
/**
* Send HTTP requests using XMLHttpRequest
* @param {string} url The url to which to send the request
* @param {object} options Configuration like verb and parameters
* @param {function} callback The function to run after a response is received
* @returns undefined
* @example
* xhr("http://example.com/api/endpoint", { params: { hello: "world", tau: "2pi" } }, function(res, headers) { doStuff(); } );
*/
@z-------------
z------------- / dartSetTabLength.coffee
Created August 15, 2015 03:07
Set the tab length to 2 for all .dart files, as per the style conventions. For Atom editor.
path = require "path"
atom.workspace.observeTextEditors (editor) ->
if path.extname(editor.getPath()) is ".dart"
editor.setTabLength(2)
console.log "set tab length to 2", editor
else
tabLength = atom.config.get "editor.tabLength" || 4
editor.setTabLength(tabLength)
console.log "set tab length to " + tabLength, editor
@z-------------
z------------- / PITHON.md
Last active August 29, 2015 14:24
Ways of computing the value of Pi in Python (Pithon. geddit?)

Ways of computing the value of Pi in Python (Pithon. geddit?)

Featuring:

  • Gregory-Leibniz series
  • Nilakantha's series
  • math.pi (this counts, right?)
  • possibly more in the future
var arachnid = {};
arachnid.init = function(elems, callback) {
var a = {
callback: (typeof callback === "function" ? callback : function(e) { console.log(e) }),
elems: []
};
var sectionHistory = [null, null];
@z-------------
z------------- / elementAnimate.js
Last active August 29, 2015 14:23
element.animate() plus a couple improvements
HTMLElement.prototype.animateBase = HTMLElement.prototype.animate;
HTMLElement.prototype.animate = function(keyframes, options) {
function isNothing(thing) {
return thing === null || typeof thing === "undefined";
}
var elem = this;
var opts = {
* {
font-family: inherit;
}
._2fug {
background-image: url(https://storage.googleapis.com/material-icons/external-assets/v1/icons/svg/ic_settings_white_24px.svg);
background-position: center;
}
._2sdm * {
@z-------------
z------------- / template.py
Last active August 29, 2015 14:22
Python script for making files with content from a template
#!/usr/bin/env python3
import sys
import getpass
templates_dir = "/home/{user}/Templates/".format( user=getpass.getuser() )
arg = sys.argv[1]
output_filename = sys.argv[1]
var shrinkDimensions = function(a, b, m) {
if (a * b > m) {
var k = a/b; // a = bk , b = a/k
var A, B;
// let ab = m
// b^2 * k = m
// b^2 = m/k
B = Math.sqrt(m/k);
// a = bk
A = B * k;
@z-------------
z------------- / cysm.py
Created May 24, 2015 04:39
Get result from canyouseeme.org from the command line. Requires Python3 and BeautifulSoup
#!/usr/bin/env python3
import sys
import urllib.request
import urllib.parse
from bs4 import BeautifulSoup
request_url = "http://www.canyouseeme.org/"
request_data = urllib.parse.urlencode({ "port": sys.argv[1] }).encode("utf-8")