Skip to content

Instantly share code, notes, and snippets.

View asfaltboy's full-sized avatar

Pavel Savchenko asfaltboy

View GitHub Profile
@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);
@asfaltboy
asfaltboy / 5.1
Created December 1, 2012 08:46 — forked from yprez/5.1
MySQL set unicode as default
[mysqld]
default-character-set=utf8
default-collation=utf8_general_ci
character-set-server=utf8
collation-server=utf8_general_ci
init-connect='SET NAMES utf8'
[client]
default-character-set=utf8
@asfaltboy
asfaltboy / log_test12.py
Last active August 24, 2019 05:50 — forked from anonymous/log_test11.py
Test harness for the logging module. Tests BufferingSMTPHandler, an alternative implementation SMTPHandler. This fork includes credential and secure support (as implemented in newer versions of logging library). Additionaly a flood check is implemented to make sure not more than capacity per minute is sent, otherwise the capacity (buffer) is rai…
#!/usr/bin/env python
#
# Copyright 2001-2002 by Vinay Sajip. All Rights Reserved.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and that
# both that copyright notice and this permission notice appear in
# supporting documentation, and that the name of Vinay Sajip
# not be used in advertising or publicity pertaining to distribution
@asfaltboy
asfaltboy / find_candidates.py
Last active December 20, 2015 16:39
Search for possible hire candidates from github profiles
"""
Welcome to github candidate finder!
Note: Current github api hardcode limit for searches is 1000 results
Valid arguments are either:
a. set the CREDS tuple in the code or,
b. pass one of the following:
* A github OAUTH_TOKEN
* A valid set of credentials (<Username>, <Password>) with which we'll
@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