Skip to content

Instantly share code, notes, and snippets.

View jpanganiban's full-sized avatar

Jesse Panganiban jpanganiban

View GitHub Profile
def circle(people, i=0):
killer = people[i % len(people)]
i = (i + 1) % len(people)
killed = people.pop(i)
return circle(people, i) if len(people) > 1 else people.pop()
print circle(range(1, 101))

Get started with [Mocha] testing

Make a package.json file if you don't have one yet:

npm init
# just keep pressing enter.
# this will create the file `package.json`
@turtlemonvh
turtlemonvh / tasks.py
Created August 8, 2014 21:14
Dynamically add celery tasks
## THIS IS UNTESTED
from worker.models import TaskType
from website.celery import app
import importlib
# Dynamically add registered tasks
# Celery._tasks is a task registry object
# https://github.com/celery/celery/blob/34c43244b1681a59540936748800aaa504786a35/celery/app/base.py#L162 - _tasks
@marksteve
marksteve / throttle.js
Last active August 29, 2015 14:03
Decorator to limit function calls to every `cd` ms
var throttle = function(f, cd) {
var _cd = new Date;
return function() {
if (_cd - new Date < 0) {
_cd = new Date(new Date().getTime() + cd);
return f.apply(this, arguments);
}
};
};
@cdiener
cdiener / asciinator.py
Last active January 5, 2023 17:24
Convert image to ascii art
import sys; from PIL import Image; import numpy as np
chars = np.asarray(list(' .,:;irsXA253hMHGS#9B&@'))
if len(sys.argv) != 4: print( 'Usage: ./asciinator.py image scale factor' ); sys.exit()
f, SC, GCF, WCF = sys.argv[1], float(sys.argv[2]), float(sys.argv[3]), 7/4
img = Image.open(f)
S = ( round(img.size[0]*SC*WCF), round(img.size[1]*SC) )
img = np.sum( np.asarray( img.resize(S) ), axis=2)
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@justinabrahms
justinabrahms / colortest.py
Created June 26, 2011 17:10 — forked from graven/colortest.py
Small utility to test terminal support for 256-color output.
#!/usr/bin/env python
# Ported to Python from http://www.vim.org/scripts/script.php?script_id=1349
print "Color indexes should be drawn in bold text of the same color."
print
colored = [0] + [0x5f + 40 * n for n in range(0, 5)]
colored_palette = [
"%02x/%02x/%02x" % (r, g, b)
for r in colored