Skip to content

Instantly share code, notes, and snippets.

View hdemers's full-sized avatar

Hugues Demers hdemers

  • Orford, Quebec, Canada
View GitHub Profile
@hdemers
hdemers / d3sandbox.html
Created May 6, 2012 14:23
D3.js bar chart tutorial, part 1
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>D3.js sandbox</title>
<script src="http://d3js.org/d3.v2.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
@hdemers
hdemers / bigqueries.sql
Created May 9, 2012 18:50
Sample queries to GitHub BigQueries data. For the first GitHub Data Challenge.
-- La première requète pour les projets ayant le plus de fork
SELECT repository_name, MIN(repository_forks) as mini, MAX(repository_forks) as maxi, MAX(repository_forks) - MIN(repository_forks) as diff
FROM githubarchive:github.timeline WHERE type = "ForkEvent" AND LENGTH(actor_attributes_location) > 3 AND repository_forks > 200
GROUP BY repository_name
ORDER BY maxi DESC;
-- La deuxième requète pour la localisation et le nombre de fork en fonction du temps
SELECT created_at, actor_attributes_location, repository_forks
FROM githubarchive:github.timeline WHERE type = "ForkEvent" AND LENGTH(actor_attributes_location) > 3 AND repository_name = "bootstrap" AND repository_owner = "twitter" AND repository_fork = "false"
ORDER BY repository_forks
@hdemers
hdemers / index.html
Created May 15, 2012 15:27 — forked from johan/index.html
Animated Draggable Spinny Globe with clipped circles
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>d3.js Spinny Globe from Mike Bostock's SVG Open 2011 keynote</title>
<script src="http://mbostock.github.com/d3/d3.js"></script>
<script src="http://mbostock.github.com/d3/d3.geo.js"></script>
<link type="text/css" rel="stylesheet" href="http://mbostock.github.com/d3/talk/20111018/style.css"/>
<link type="text/css" rel="stylesheet" href="http://mbostock.github.com/d3/talk/20111018/colorbrewer/colorbrewer.css"/>
<style type="text/css">
@hdemers
hdemers / pydata-science.sh
Last active June 1, 2020 07:17
Installation instructions for doing data science in a Python environment on Ubuntu. We'll install base packages like numpy, scipy, scikit-learn and pandas. We also install the IPython Notebook interactive environment. This is a best practice recommendation for doing research-type work. We make use of virtualenvwrapper, but don't show how to inst…
mkvirtualenv datascience
sudo apt-get install python-scipy libblas-dev liblapack-dev gfortran
sudo apt-get install libffi-dev # for cryptography from scrapy
sudo apt-get install libxslt-dev # for libxml from scrapy
export BLAS=/usr/lib/libblas.so
export LAPACK=/usr/lib/liblapack.so
pip install numpy
pip install scipy
pip install scikit-learn
pip install pandas
@hdemers
hdemers / listchunker.py
Created April 8, 2013 19:11
A Python generator yielding a list in chunks. Cf. http://stackoverflow.com/a/312464
def chunks(l, n):
""" Yield successive n-sized chunks from l.
Cf. http://stackoverflow.com/a/312464
"""
for i in xrange(0, len(l), n):
yield l[i:i+n]
@hdemers
hdemers / decorators.py
Created April 10, 2013 19:17
Python decorator cheat sheet.
from functools import wraps
def decorator(fn):
"""A function that *is* a decorator.
Use it like so:
@decorator
def foobar(arg):
return arg
@hdemers
hdemers / utctime.py
Created April 14, 2013 17:34
I never remember how to convert to/from UTC datetime and epoch. Now I don't have to.
"""UTC time conversion functions.
"""
from calendar import timegm
from datetime import datetime
def utcdt2epoch(utcdatetime):
"""Convert a datetime object expressed in UTC to a Unix timestamp expressed
in seconds since the epoch (Jan 1st 1970).
"""
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
{
"metadata": {
"name": "",
"signature": "sha256:b558204f751fde84d16bf429dd76b6bd17dc0901bd51c746c7dbfc3e3a09f71e"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
# Connect to database
import os
import pandas as pd
from sqlalchemy import create_engine
hostname = "127.0.0.1"
username = os.environ['DB_USERNAME']
db_name = os.environ['DB_NAME']
password = os.environ['MYSQL_PWD']