Skip to content

Instantly share code, notes, and snippets.

@jackmaney
jackmaney / pypi_homepage.sh
Last active August 27, 2015 06:02
A simple function to open the homepage of any project on PyPI (with a listed homepage)
# Retrieves the home page of a project in PyPI, and opens that homepage in your default browser.
# This makes use of the PyPI JSON API: https://wiki.python.org/moin/PyPIJSON
function pypi_homepage() { curl -sL http://pypi.python.org/pypi/$1/json | \
python -c "from __future__ import print_function;import json;import fileinput;\
blob=json.loads(' '.join([x for x in fileinput.input()]));print(blob['info']['home_page'])"| xargs open ;}
@jackmaney
jackmaney / user_agent.js
Created April 2, 2014 18:16
Server-side UA Sniffing to Detect Browser
var express = require('express');
var uaParser = require('ua-parser')
var app = express();
app.get('/', function(req,res){
var r = uaParser.parse(req.headers['user-agent']);
res.status(200).send(r.ua.family);
})
@jackmaney
jackmaney / gist:5f6cd4d24688954e7a93
Created December 8, 2014 23:56
Averaging variables by ID
# create dummy data
df = data.frame(id=c(1,1,1,2,2,3,3,3,4,4,4), var1=c(-2.1, 1.1, 3.14, 2.17828, 9, 10, 8,2,1,0,-1), var2=c(1,2,3,4,5,6,7,8,9,10,11))
# This is what you'd see if you called this data set from the interactive prompt (or REPL, as it's called (Read-Evaluate-Print-Loop)):
#> df
# id var1 var2
#1 1 -2.10000 1
#2 1 1.10000 2
#3 1 3.14000 3
#4 2 2.17828 4
@jackmaney
jackmaney / gist:841ca7af0027c02a6deb
Created December 30, 2014 04:36
Diophantus.java
package com.jackmaney.Diophantus;
import com.jackmaney.Diophantus.element.Element;
public class Diophantus {
public static void main(String[] args) {
Element e = new Element(6,0,-5);
2014-12-30 18:36:20 -0600
./configure
--disable-dependency-tracking
--prefix=/usr/local/Cellar/harfbuzz/0.9.37
--with-icu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ./install-sh -c -d
@jackmaney
jackmaney / gist:4a98cfdfef61e1d5a097
Last active August 29, 2015 14:13
A queue for geocoding addresses with geopy that respects a per-second rate limit
from time import time
class RateLimitedGeocodingQueue(object):
def __init__(self, geocoder, addresses, per_sec_rate_limit=5):
self.geocoder = geocoder
self.addresses = [x for x in addresses] # Cloning list of addresses so we can pop with impunity
self.per_sec_rate_limit = per_sec_rate_limit
@jackmaney
jackmaney / parse_manifest.py
Last active August 29, 2015 14:15
Using distutils to parse MANIFEST.in and grab files against the manifest
# Adapted from https://github.com/python/cpython/blob/2.7/Lib/distutils/command/sdist.py#L386
from distutils.text_file import TextFile
from distutils.filelist import FileList
template = TextFile("MANIFEST.in", strip_comments=1, skip_blanks=1, join_lines=1, lstrip_ws=1, rstrip_ws=1, collapse_join=1)
filelist = FileList()
try:
while True:
@jackmaney
jackmaney / macbeth.py
Created March 9, 2015 13:24
r/dailyprogrammer challenge #204 [Easy]
# Daily Programming Challenge:
# http://www.reddit.com/r/dailyprogrammer/comments/2xoxum/20150302_challenge_204_easy_remembering_your_lines/
import requests
import re
import sys
macbeth = requests.get(
"https://gist.githubusercontent.com/Quackmatic/f8deb2b64dd07ea0985d/raw/macbeth.txt").text
# act_number: {scene: {description: (desc_of_scene), dialogues: [{speaker:
# S, text: T}]}}
pyenv_python_version(){
result=""
pyenv_version="$(pyenv version-name)";
if [ -n "$pyenv_version" ]; then
result="$pyenv_version";
fi
[[ -n "$result" ]] && echo "($result) "
}
export PS1="\$(pyenv_python_version)\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h\[\033[33;1m\]\w\[\033[m\]$ "
@jackmaney
jackmaney / gist:4c5360255d5f43391567
Created August 6, 2015 20:22
MacDown crash log
Process: MacDown [17345]
Path: /Applications/MacDown.app/Contents/MacOS/MacDown
Identifier: com.uranusjr.macdown
Version: 0.4.5.1 (647)
Code Type: X86-64 (Native)
Parent Process: launchd [445]
Responsible: MacDown [17345]
User ID: 502
Date/Time: 2015-08-06 15:22:12.317 -0500