Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# scrape complex systems article pdfs | |
# requires bs4: `pip install beautifulsoup4` | |
import os | |
import re | |
import json | |
from urllib import urlopen as get, urlretrieve as save | |
from bs4 import BeautifulSoup as bs |
/* post-fx pass by blending a solid white fullscreen quad, no texture required */ | |
/*uniform*/ float fmin = 0.7; | |
void main(void) | |
{ | |
float fmod = mod(gl_FragCoord.y, 2.0); | |
float fstep = fmin + (1.0 - fmin) * fmod; | |
gl_FragColor = vec4(1.0, 1.0, 1.0, fstep); | |
} |
#!/usr/local/bin/python3 | |
# one-off scraper for egghead.io videos in a series | |
# usage: chmod +x grabber.py && ./grabber.py <series stub> | |
# requires youtube-dl (`brew install youtube-dl`) | |
import os | |
import subprocess | |
import json | |
import argparse | |
from urllib.request import urlretrieve |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
import re | |
from datetime import datetime as dt | |
fake_dates = '10-Jan-2011, 01-Feb-02, ##-Bla-##, 01-Bla-2014' | |
# you can probably do some lookahead assertion at the end of the regex to only capture 2 digits or the last 2 digits | |
# instead of the mess below [1] | |
date_finder = re.compile('(\d{2}-(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-\d{2,4})') | |
dates = re.findall(date_finder, fake_dates) |
Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.
$ python -m SimpleHTTPServer 8000
import React, { Component } from 'react' | |
class Blink extends Component { | |
constructor () { | |
super() | |
this.state = { visible: true } | |
this.blink = this.blink.bind(this) | |
this.interval = null | |
} | |
blink () { |
import re | |
from sys import argv | |
from bs4 import BeautifulSoup as bs | |
from pyquery import PyQuery as pq | |
from lxml import etree | |
filename = argv[-1] | |
anchors = re.compile('<a.+?>.+?<\/a>', re.DOTALL|re.I) | |
with open(filename, 'r') as infile: |
const radians = deg => deg * Math.PI / 180 | |
// @param {Number} z Offset from radius | |
export default function convertLatLngToSphere (lat, lng, baseRadius, z) { | |
// radians | |
const phi = radians(lat) | |
const theta = radians(lng - 180) | |
const radius = baseRadius + z | |