Skip to content

Instantly share code, notes, and snippets.

@d136o
d136o / index.html
Created February 25, 2016 17:39
Cycle through urls on an iframe
html>
<body>
<script type="text/javascript">
var urls = [
"https://duckduckgo.com",
"https://bing.com",
]
@d136o
d136o / mmap_test.py
Last active August 29, 2018 07:15
Comparing mmap performance
'''Compares the time to scan through a large tar.gz file when it is memory mapped vs when it isn't
In this example train_0.tar.gz is a 46 GB tar.gz file that decompresses to 47 GB. In other words its a file that
hasn't compressed much, in this case because it contains a bunch of already compressed files.
$ python3 ./mmap_test.py
seconds to execute w/o mmap: 134.61383328400552
seconds to execute mmpa: 43.660543900041375
'''
@d136o
d136o / README.md
Last active April 4, 2017 20:40
Getting familiar with TensorFlow

Computation Graph:

Instantiating Variable objects as well as Ops objects adds to a graph of computation that is tracked by tf.

After building your computation graph, where nodes are Variables or Ops or Constants, you can retrieve the executed and resulting value of any of the nodes in the graph.

The difference between Ops and Variables:

  • Ops take Tensor inputs and return Tensor outputs, they have no internal state.
@d136o
d136o / list_creator_shortcut.py
Created October 4, 2016 18:45
understand shortcuts before using them :)
$ python
Python 3.5.2 (default, Jun 28 2016, 08:46:01)
[GCC 6.1.1 20160602] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a = [[0,0],[0,0]]
>>> c = (1,1)
>>> a[c[0]][c[1]] = 100
>>> a
[[0, 0], [0, 100]]
>>> a = [[None]*2]*2
@d136o
d136o / index.html
Created February 25, 2016 17:39
Cycle through urls on an iframe
html>
<body>
<script type="text/javascript">
var urls = [
"https://duckduckgo.com",
"https://bing.com",
]
@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 = ''
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 / 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)
@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 / 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.