Skip to content

Instantly share code, notes, and snippets.

View danlmarmot's full-sized avatar

Dan McKean danlmarmot

View GitHub Profile
@danlmarmot
danlmarmot / pandas_snippets.py
Last active June 3, 2023 11:21
Pandas Snippets
# Using Jupyter 4.2 and Python 3.5.1
# Firstly, Jupyter notebook stuff
#
# Make the notebook the width of the brower window
from IPython.core.display import HTML
HTML("<style>.container { width:100% !important; }</style>")
#-----
# Now pandas stuffs
@danlmarmot
danlmarmot / Chrome Gmail Bookmarklet
Last active December 22, 2015 18:09
Bookmarklet for Chrome to mail link to page
javascript:(function(){m='http://mail.google.com/mail/?view=cm&fs=1&tf=1&to=&su='+encodeURIComponent(document.title)+'&body='+encodeURIComponent(document.location);w=window.open(m,'addwindow','status=no,toolbar=no,width=575,height=545,resizable=yes');setTimeout(function(){w.focus();}, 250);})();
@danlmarmot
danlmarmot / simple_pyspark.py
Created October 10, 2014 21:13
Simple PySpark 1.1 standalone program
#!/usr/bin/env python
'''
Small demo of how to get a standalone Python script working in Spark 1.1 through the regular Python interpreter,
rather than using bin/pyspark <filename.py>.
Useful for interactive debugging and avoids messing with PYTHONPATH, I used this script to verify my PyCharm IDE
was correctly configured.
Note that Spark is installed at ~/bin/spark/current
@danlmarmot
danlmarmot / Anagram maker
Last active August 29, 2015 14:05
Anagram maker
__author__ = 'danlmarmot'
from itertools import permutations
import collections
INPUT_WORD = "deposit"
MIN_ANAGRAM_LEN = 4
WORD_DICT_FILEPATH = '/usr/share/dict/words'
@danlmarmot
danlmarmot / s3_download_changed_files.py
Created August 6, 2014 15:29
Download files from S3 if they've been updated (ie, have new timestamps on S3 compared to what's saved locally). Filenames are expected to be the same, and updated on a regular basis.
#!/usr/bin/python
import os
import sys
import logging
import time
import json
from time import mktime
from boto.s3.connection import S3Connection
from boto.exception import S3DataError, S3ResponseError
@danlmarmot
danlmarmot / file_pattern_s3_upload.sh
Last active August 29, 2015 14:04
Upload files matching pattern to S3 with Bash and curl
#!/bin/bash
#
patternMatches="foo/target/*.jar
bar/target/*.jar
baz/target/*.jar
"
bucket=my-bucketname
objectPath=bucketdir/subdir
@danlmarmot
danlmarmot / crontab-list.sh
Created June 17, 2014 19:36
crontab-list.sh -- lists all cronjobs
#!/bin/bash
#
# cm-crontab-list
#
# Taken from yukondude's answer at
# http://stackoverflow.com/questions/134906/how-do-i-list-all-cron-jobs-for-all-users
# System-wide crontab file and cron job directory. Change these for your system.
CRONTAB='/etc/crontab'
CRONDIR='/etc/cron.d'
@danlmarmot
danlmarmot / filehash.py
Created January 19, 2014 19:09
This Python script measures hash performance, and attempts to answer this question: 'Given a hash function and a block size for reading, which is the fastest hash function and block size?'
__author__ = 'danlmarmot'
"""
This Python script measures hash performance, and attempts to answer this question:
'Given a hash function and a block size for reading, which is the fastest hash function and block size?'
There's no warm up, there's no cache/memory/whatever filling, just a simple way to explore performance for
commonly used functions with the timeit library
"""
@danlmarmot
danlmarmot / N2 - Gadfly GH.ipynb
Created January 19, 2014 18:05
iPython Notebook to demonstrate Gadfly visualization in Julia
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@danlmarmot
danlmarmot / gist:8458094
Last active January 3, 2016 11:39
Python script to read data from a Proliphix network thermostat's REST interface and store it in MongoDB. Handles initialization of Mongo collection if one doesn't exist.
#!/usr/bin/python
from pymongo import Connection
from collections import defaultdict
import os, sys, time
import pprint
import requests
import urllib
import re
try: import simplejson as json