Skip to content

Instantly share code, notes, and snippets.

@danallison
danallison / datetime_cycles.py
Created Jun 4, 2018
Get the cyclic properties of a datetime, represented as points on the unit circle.
View datetime_cycles.py
from datetime import datetime
from math import sin, cos, pi
days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
def sin_cos(n):
theta = 2 * pi * n
return (sin(theta), cos(theta))
def get_cycles(d):
@danallison
danallison / cc2ld.py
Created May 16, 2018
A Python dictionary of second-level domains, keyed by country code. Useful when parsing URLs.
View cc2ld.py
# https://en.wikipedia.org/wiki/Second-level_domain
# https://www.quackit.com/domain-names/country_domain_extensions.cfm
from collections import defaultdict
second_level_domains_by_country_code = defaultdict(set)
d = second_level_domains_by_country_code
# Afghanistan
d['af'] = set((
'com',
'edu',
@danallison
danallison / with_sql_session.py
Last active Sep 16, 2021
Connect to Postgresql locally or through SSH tunnel
View with_sql_session.py
from sshtunnel import SSHTunnelForwarder
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from functools import wraps
# secrets.py contains credentials, etc.
import secrets
def get_engine_for_port(port):
return create_engine('postgresql://{user}:{password}@{host}:{port}/{db}'.format(
View 10kft_api_time_fees_reconstruction.py
import requests
import datetime
auth_token = '** replace this with your auth token **'
def get_time_entries_for_project(project_id, date_range=None):
'''
Fetches time entries from the API, including suggestions and phases
'''
base_url = 'https://api.10000ft.com'
@danallison
danallison / 10kft_api_example.get_users_currently_assigned_to_a_project.ipynb
Last active Jul 21, 2017
10kft API Example. Get users currently assigned to a project
View 10kft_api_example.get_users_currently_assigned_to_a_project.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View keybase.md

Keybase proof

I hereby claim:

  • I am danallison on github.
  • I am danallison (https://keybase.io/danallison) on keybase.
  • I have a public key ASDUznCpicoQz-TtNd0WOBIMNXMAYktgZzXbIRT3TjIJlAo

To claim this, I am signing this object:

@danallison
danallison / flowMap.js
Created Jan 7, 2016
Like _.flow, but also accepts arrays of functions.
View flowMap.js
function flowMap () {
var functions = [].slice.call(arguments); // convert arguments to array
return function () {
var _this = this; // maintain context
return functions.reduce(function (args, fn) {
// for each function or array of functions,
// pass in the previous return value.
if (_.isArray(fn)) {
return [fn.map(function (_fn) { return _fn.apply(_this, args); })];
} else {
@danallison
danallison / downloadString.js
Created Sep 29, 2014
download string as text file
View downloadString.js
function downloadString(text, fileType, fileName) {
var blob = new Blob([text], { type: fileType });
var a = document.createElement('a');
a.download = fileName;
a.href = URL.createObjectURL(blob);
a.dataset.downloadurl = [fileType, a.download, a.href].join(':');
a.style.display = "none";
document.body.appendChild(a);
a.click();
@danallison
danallison / dispatcher.coffee
Last active Aug 29, 2015
Bare bones event system
View dispatcher.coffee
dispatcher = {}
dispatcher._subscribers = {}
dispatcher.on = (eventName, callback, context) ->
(dispatcher._subscribers[eventName] or = [])
.push {
callback: callback
context: context
}
@danallison
danallison / useWorkerToDo.coffee
Last active Aug 29, 2015
Create a Web Worker on the fly
View useWorkerToDo.coffee
useWorkerToDo = (fn, data) ->
window.URL or = window.webkitURL
workerSupported = window.Worker and window.URL and window.Blob
callbacks = []
done = false
returnVal = undefined
resolve = ->
while callbacks.length
returnVal = callbacks.shift()(returnVal)
return