Skip to content

Instantly share code, notes, and snippets.

@d136o
d136o / visit_histogram.py
Created July 29, 2013 18:59
Count up how many of your users have 1 visit, 2 visits, 3 visits... Save as 2 column csv. run and you have pretty figure.
import numpy as np
import matplotlib.pyplot as plt
'''Makes a simple histogram from a file containing the frequency counts for each number
'''
def make_histogram():
#The format of the counts is a file with two columns, separated by commas
#first col: visit number (bin)
@d136o
d136o / s3_key_info.py
Created July 31, 2013 22:20
Get some simple Amazon S3 key information, here just the name and size of the key's object. have the access key and pass set as env vars.
import sys
from boto.s3.connection import S3Connection
def main(args):
c = S3Connection()
l = c.get_bucket(args[0]).list(prefix=args[1])
print "keyname,size"
for k in l:
print "%s,%d" % (k.name, k.size)
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab
def make_bars():
d = matplotlib.mlab.csv2rec("os_visit_counts.txt",names=('os','visits'))
sorted_indeces = np.argsort(d['visits'])
x = d['os'][sorted_indeces]
y = np.log10(d['visits'][sorted_indeces])
@d136o
d136o / quicks3download.py
Last active December 31, 2015 18:59
download all keys form a bucket that have a specific prefix
import boto
import boto.s3.connection
import os.path
def main():
aws_key = ''
aws_secret = ''
bucket_name = ''
prefix = ''
@d136o
d136o / quick_ftp_fetch.py
Last active August 29, 2015 13:56
just a quick script for fetching some files over ftp
import argparse
import ftplib
import io
import os.path
import sys
def main(host,user,passw,prefix_glob,destination_directory,optional_chdir=None):
if not os.path.isdir(destination_directory):
@d136o
d136o / full_contact_fetch.py
Last active August 29, 2015 14:01
Fetched data from Full Contact API and throws it into SQLite
import argparse
import codecs
import json
import os.path
import requests
import sys
import sqlite3
import time
import traceback
@d136o
d136o / asyc_test.hml
Last active August 29, 2015 14:02
yellow hammer asynchronous workaround
<head>
<script src="http://code.jquery.com/jquery-1.7.2.js"></script>
</head>
<body>
<script type="text/javascript">
var hostProtocol = (("https:" == document.location.protocol) ? "https" : "http");
$.getScript(
hostProtocol+'://5003.xg4ken.com/media/getpx.php?cid=XXXXXX',
function(){
console.log("about to log request after initial dom rendering, not on initial dom render.");
@d136o
d136o / gist:96bb66639abfa507a03c
Created June 24, 2014 19:10
dedicated pixel test
<!DOCTYPE html>
<html>
<head>
<title>dedicated pixel test</title>
<script type="text/javascript" src="//cpadna1.com/p.ashx?o=1246&amp;f=js&amp;t=1"></script>
</head>
<body>
use developer tools to check out network activity.
</body>
</html>
@d136o
d136o / icon.py
Created October 5, 2015 20:34
Tally up code counts per day
import os
import pandas
def main():
data_directory = './replay-correction'
output_fname = './icon_code_count.csv'
dates = []
codes = []
@d136o
d136o / tensor_overflow.py
Created November 30, 2015 18:20
Getting familiar with TensorFlow
import argparse
import tensorflow as tf
import sys
def flowfib(n):
''' f_n = f_n-1 + f_n-2
Fails in a somewhat interesting way, showing that ints passed to constants are cast to 32 bit signed ints,
causing overflow pretty early in fibonacci sequence.