Skip to content

Instantly share code, notes, and snippets.

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
from scipy.optimize import fmin
from scipy.stats import *
from scipy.stats.distributions import beta, binom
from snakify import snakify
@debrouwere
debrouwere / keybase.md
Created August 31, 2016 20:02
keybase proof

Keybase proof

I hereby claim:

  • I am debrouwere on github.
  • I am debrouwere (https://keybase.io/debrouwere) on keybase.
  • I have a public key ASBkoTHjCxZfLes7DxvFDjr3qZIch9-cX1f3MWI0Ayp5fQo

To claim this, I am signing this object:

@debrouwere
debrouwere / service.service
Created February 5, 2015 19:25
Etcd snapshot
ExecStartPre=etcdctl ls /mydir \
| cut -d / -f 3 \
| xargs -I {} echo 'echo {}=$(etcdctl get /mydir/{})' \
| bash > mydir.env
EnvironmentFile=/home/core/mydir.env
@debrouwere
debrouwere / competitors.py
Created January 30, 2015 14:28
social media competitive analysis
import os
import tortilla
import tweepy
import facepy
from apiclient import discovery
import pandas as pd
twitter_credentials = tweepy.AppAuthHandler(
os.environ['TWITTER_CONSUMER_KEY'],
os.environ['TWITTER_CONSUMER_SECRET'],
@debrouwere
debrouwere / auth.py
Created August 16, 2014 08:56
Access Google Analytics data with rauth in Python
import os
import json
from flask import Flask, request, redirect, jsonify
from rauth import OAuth2Service
GOOGLE_AUTH_URI = 'https://accounts.google.com/o/oauth2/auth'
GOOGLE_REVOKE_URI = 'https://accounts.google.com/o/oauth2/revoke'
GOOGLE_TOKEN_URI = 'https://accounts.google.com/o/oauth2/token'
GOOGLE_ANALYTICS_API_ENDPOINT = 'https://www.googleapis.com/analytics/v3/'
@debrouwere
debrouwere / passport.html
Created June 13, 2014 14:58
Express 4 + PassportJS
<form action="/login" method="post">
<div>
<label>Username:</label>
<input type="text" name="username" />
</div>
<div>
<label>Password:</label>
<input type="password" name="password" />
</div>
<div>
@debrouwere
debrouwere / input.py
Created June 11, 2014 15:57
Take arguments from both stdin and as command-line flags
#!/usr/bin/env python
# encoding: utf-8
"""
This on the command line
echo '{"d": 44}' | ./input.py --a 33 --b 44 --c
turns into this argument passed to your function
@debrouwere
debrouwere / cas.coffee
Created June 8, 2014 22:45
Using content-addressable storage to efficiently and continually archive new versions of an HTML page including all related resources (images etc.)
### An interesting thing about news website homepages is that, while they
change all the time, the media on them doesn't change quite that fast: both
actual images but also stylesheets, javascript, logos and so on. Therefore,
when archiving these pages, it is possible to achieve significant space
savings by modifying the links to every image or other resource in the HTML to
instead refer to a file path that's a hash of the file's content: a type of
content-addressable storage.
The storage size can be further reduced by storing e.g. a day's worth of HTML
for one page (e.g. one fetch every hour) into a single lzip file, as LZMA can
# encoding: utf-8
"""
First, run `authenticate.py` which will launch a new browser window that
will let you give this app permission to access your Google Analytics
data. The OAuth2 token will work for one hour and will be in
`ga-oauth2-token.json`.
Then, just run this file using `python analytics.py`.
page = require('webpage').create()
page.onConsoleMessage = (msg) ->
console.log 'CONSOLE:' + msg
page.onResourceRequested = (params, request) ->
isJavaScript = params['url'].slice(-3) is '.js'
isJQuery = (params['url'].indexOf 'jquery') isnt -1
if isJavaScript and not isJQuery