Skip to content

Instantly share code, notes, and snippets.

View asfaltboy's full-sized avatar

Pavel Savchenko asfaltboy

View GitHub Profile
@asfaltboy
asfaltboy / gist:9345869
Created March 4, 2014 12:48
get all app.Model in a Django project, excluding some models as required
from django.db import models
app_names = []
excuded = ['SomeModel', ...]
for app in models.get_apps():
for model_class in models.get_models(app):
if model_class.__name__ in :
continue

Bubble charts encode data in the area of circles. Although less perceptually-accurate than bar charts, they can pack hundreds of values into a small space. Implementation based on work by Jeff Heer. Data shows the Flare class hierarchy, also courtesy Jeff Heer.

@asfaltboy
asfaltboy / README.md
Last active August 29, 2015 14:01 — forked from mbostock/.block

The tree layout implements the Reingold-Tilford algorithm for efficient, tidy arrangement of layered nodes. The depth of nodes is computed by distance from the root, leading to a ragged appearance. Cartesian orientations are also supported. Implementation based on work by Jeff Heer and Jason Davies using Buchheim et al.'s linear-time variant of the Reingold-Tilford algorithm. Data shows the Flare class hierarchy, also courtesy Jeff Heer.

Compare to this Cartesian layout.

This fork uses DS locations connections as data + link to a live jsfiddle example

"""
Parse markdown list items (such as FAQ) into a TOC
Usage:
python list_toc_generator.py <markdown_file, markdow_file...>
"""
import re
import sys
@asfaltboy
asfaltboy / lecture_slides_list.txt
Last active August 29, 2015 14:19
Mine URLs from POSA-15 slides
https://d396qusza40orc.cloudfront.net/posaconcurrency/slides/S0-P1-MOOC-organization-and-topics.pdf
https://d396qusza40orc.cloudfront.net/posaconcurrency/slides/S0-P3-MOOC-prereqs-and-learning-strategies.pdf
https://d396qusza40orc.cloudfront.net/posaconcurrency/2014-PDFs/S1-M1-P1-concurrency-motivations.pdf
https://d396qusza40orc.cloudfront.net/posaconcurrency/2014-PDFs/S1-M1-P2-concurrency-challenges.pdf
https://d396qusza40orc.cloudfront.net/posaconcurrency/2014-PDFs/S0-P4-overview-of-patterns-and-frameworks.pdf
https://d396qusza40orc.cloudfront.net/posaconcurrency/2014-PDFs/S0-P5-overview-of-patterns-and-frameworks-pt2.pdf
https://d396qusza40orc.cloudfront.net/posaconcurrency/lecture_slides/android-layers-s1.pdf
https://d396qusza40orc.cloudfront.net/posaconcurrency/lecture_slides/android-layers-s2.pdf
https://d396qusza40orc.cloudfront.net/posaconcurrency/lecture_slides/android-layers-s3.pdf
https://d396qusza40orc.cloudfront.net/posaconcurrency/lecture_slides/android-layers-s4.pdf
@asfaltboy
asfaltboy / runtests.py
Created May 10, 2015 14:11
tox django env matrix
import os
import sys
from django.conf import settings
import django
os.environ['DJANGO_SETTINGS_MODULE'] = 'app.tests.test_settings'
try:
from django.test.utils import get_runner
TestRunner = get_runner(settings)
@asfaltboy
asfaltboy / gist:2965177
Created June 21, 2012 11:15
returns current requirements.txt versions
import pkg_resources, os
def requirements_versions(req_file=None):
path = req_file
if path and not os.path.exists(path) or not path:
path = 'base_requirements.txt'
elif not os.path.exists(path):
path = 'req.txt'
elif not os.path.exists(path):
return None
@asfaltboy
asfaltboy / submit_form.js
Created June 28, 2012 12:31
generic form submission over ajax with jsonp response
$('#form').submit(function() {
payload = $(this).serialize();
$.ajax({
url: 'http://',
type: 'POST',
data: payload,
dataType: 'jsonp'
success: function(data){
// present success message here
}
@asfaltboy
asfaltboy / debug_exception.py
Created September 13, 2012 14:23
Python runtime exception debugging (interactive or post-mortem)
import sys
def info(type, value, tb):
if hasattr(sys, 'ps1') or not sys.stderr.isatty():
# we are in interactive mode or we don't have a tty-like
# device, so we call the default hook
sys.__excepthook__(type, value, tb)
else:
import traceback, pdb
# we are NOT in interactive mode, print the exception...
@asfaltboy
asfaltboy / gist:4037702
Created November 8, 2012 09:16
Calculate Percentage of a Trade Day
function getTradeDayPercent() {
// calculate the percent of time passed since trade opened in sydney
gmtoffset = (new Date).getTimezoneOffset() * 60 * 1000;
now = Date.now() + gmtoffset;
today = new Date(now).set({hour: 0, minute: 0, second: 0});
midnight = today.getTime()
hour = parseInt((now - midnight) / 1000 / 60 / 60);
if (hour < 17) today.addDays(-1);
gmt5 = today.set({hour: 17});
return ((now - gmt5.getTime() + gmtoffset) / 864000);