Skip to content

Instantly share code, notes, and snippets.

@clawtros
clawtros / gist:5038140
Created February 26, 2013 12:37
Easeljs SpriteSheet loaded on a Leafletjs Marker
L.HtmlSpriteIcon = L.Icon.extend({
options: {
/*
spritesheet: (String) (required)
animation: (String) (required)
iconAnchor: (Point)
popupAnchor: (Point)
*/
},
currentFrame: 0,
import requests
import simplejson
def getactors():
baseurl = 'http://en.wikipedia.org/w/api.php?cmtitle=Category:American_film_actors&action=query&list=categorymembers&cmlimit=500&cmprop=title|sortkey|timestamp&format=json'
results = []
cont = ""
while True:
r = requests.get(baseurl + cont)
@clawtros
clawtros / gist:5773033
Created June 13, 2013 11:34
Dragon curve in generator form
def dragon_generator():
count = 0
fold_index = 0
curve = []
while True:
fold_index -= 1
count += 1
if fold_index < 0:
fold_index = count - 1
@clawtros
clawtros / gist:6082272
Last active December 20, 2015 05:59
Worst Phonetic Dictionary Generator
from nltk.corpus import cmudict
def char_range(c1, c2):
for c in xrange(ord(c1), ord(c2)+1):
yield chr(c)
candidates = [e for e in cmudict.entries() if e[0][0].lower() != e[1][0][0].lower()]
separated = {}
for l in char_range('a', 'z'):
separated[l] = [e for e in candidates if e[0][0].lower() == l]
@clawtros
clawtros / gist:6161102
Created August 6, 2013 00:56
turtacular blueberries
import turtle
import math
turtle.clear()
turtle.setposition(0, 0)
turtle.speed("fastest")
for i in range(500):
turtle.left(math.sin(i / (2*math.pi)) * (180 / math.pi))
turtle.forward(math.sqrt(i))
import turtle
import math
MIN_X = -math.pi * 2
MIN_Y = -2
MAX_X = math.pi * 2
MAX_Y = 2
TURTLE_STEP = 0.1
import sys
def is_valid(p):
# words must be at least 3 characters
padded = '1' + p + '1'
return "101" not in padded and "1001" not in padded
def groups(size):
current = ""
'use strict';
function convolve(arr, vs, size, x, y) {
const hl = parseInt(arr.length / 2);
return arr.map((row, offY)=>row.map((m, offX)=>vs[indexOf(x + offX - hl, y + offY - hl, size)] * m))
}
function position(index, size) {
return [Math.floor(index % size), Math.floor(index / size)]
}
from bs4 import BeautifulSoup
import requests
url = "https://leapmanifesto.org/en/whos-on-board/"
soup = BeautifulSoup(requests.get(url).text)
signatories = {}
for signatory_container in soup.find_all("div", class_="section-wrap signatories"):
def shift_loss_fn(x):
return x_tile_scale * tf.reduce_sum(tf.square(x)) / float(width) / float(height)
x_tile_loss_layer = keras.layers.Lambda(
shift_loss_fn,
output_shape=lambda input_shape: [1]
)
x_tile_difference = keras.layers.add([pyramid_model.outputs[0], x_tile_shifter(pyramid_model.outputs[0])])