Skip to content

Instantly share code, notes, and snippets.

View paulmand3l's full-sized avatar
🚀

Paul Mandel paulmand3l

🚀
View GitHub Profile
@paulmand3l
paulmand3l / .babelrc
Last active September 19, 2018 00:48
The result of transforming pegjs's parser.js file with metro-react-native-babel-preset
{
"presets": ["module:metro-react-native-babel-preset"],
}
catRef = new Firebase(...)
class Cat
constructor: (@name) ->
catRef.push
name: @name
pounce: ...
///////////////
// CONSTANTS
///////////////
var DATE = 0,
FB_LINK = 1,
HOSTS = 2,
DJS = 3,
INSTRUCTORS = 4,
DOOR = 5,
NOTES = 6,
var a = [1, 2, 3, 4, 5];
var b = [6, 7, 8, 9, 0];
a.forEach(function(var) {
b.forEach(function(val) {
console.log(var + val);
});
});
(function() {
var fs, getBridge, getUser, getUsernameForBridge, hslLights, hue, keypress, mod, q, startKeypress, toggleWarmWhite, _;
fs = require('fs');
_ = require('underscore');
hue = require("node-hue-api");
q = require("q");
# Create dataset
people = [{'salary': i} for i in range(20000)]
for person in people:
person['friends'] = [(i + person['salary']) % 20000 for i in range(10)]
# people = [..., {'salary': 12308, 'friends': [12308, 12309, 12310, 12311, 12312, 12313, 12314, 12315, 12316, 12317]}, ...]
for person in people:
total_salary = 0
for friend in person.nominated_friends:
@paulmand3l
paulmand3l / cancelableDownload.coffee
Last active December 31, 2015 19:08
Downloading a large file with window XHR so that we can follow redirects/proxies/etc. How to let the user cancel the download?
downloadChunk = (url, start, end) ->
xhr = new window.XMLHttpRequest()
deferred = Q.defer()
xhr.open "GET", url, true
xhr.setRequestHeader "range", "bytes=" + start + '-' + end
xhr.onload = ->
if @status == 200
defer.resolve @response
@paulmand3l
paulmand3l / keepGoing.coffee
Created December 18, 2013 02:11
Promise Retry Pattern
doThisUntilItWorks = () ->
doSomethingAsync().then (result) ->
doSomething result
, (reason) ->
console.warn "Retrying"
deferred = Q.deferred()
setTimeout (->
deferred.resolve(doThisUntilItWorks())
), retryDelay
@paulmand3l
paulmand3l / solveit.py
Created December 2, 2013 03:48
Puzzle solving
a = 'welldone'
b = 'tinyurl.com'
def get_letter_for_number(n):
""" Return the alphabet letter for index n
>>> get_letter_for_number(1)
a
>>> get_letter_for_number(26)