Skip to content

Instantly share code, notes, and snippets.

View pganssle's full-sized avatar
👨‍💼
Acclimating to new job, full bore FOSS contributions should resume soon.

Paul Ganssle pganssle

👨‍💼
Acclimating to new job, full bore FOSS contributions should resume soon.
View GitHub Profile
@pganssle
pganssle / test_compression.py
Created August 19, 2014 20:35
Compression of the same data, represented two ways, using BZ2 (similar results with LZMA)
from __future__ import division
import struct
import bz2
# Generate data - round to nearest 1e11 so that no data is lost when formatting in ASCII
xx = range(10**7)
x = [round(ii*1e11)/(1e11*len(xx)) for ii in xx]
sx = struct.pack('d'*len(x), *x)
# Write it to file as a text and binary file
@pganssle
pganssle / gist:74a7b5dfae366211956e
Created February 27, 2015 15:18
RRULE2 Profile: Daily BYMONTH
from datetime import datetime, timedelta
try:
from itertools import islice, filterfalse
except ImportError:
# Python 2.x
from itertools import islice, ifilterfalse as filterfalse
def _daily(start_date=datetime.now(), interval=1):
@pganssle
pganssle / keybase.md
Created June 3, 2015 15:20
keybase.md

Keybase proof

I hereby claim:

  • I am pganssle on github.
  • I am pganssle (https://keybase.io/pganssle) on keybase.
  • I have a public key whose fingerprint is 6B49 ACBA DCF6 BD1C A206 67AB CD54 FCE3 D964 BEFB

To claim this, I am signing this object:

@pganssle
pganssle / pandas_categorical_demo.py
Last active September 30, 2015 19:38
MWE demonstrating a problem using `apply()` to convert multiple DataFrame columns to categorical.
import pandas as pd
import sys
pdf = pd.DataFrame(dict(name= ('Earl', 'Eve', 'Alan', 'Randall', 'Danielle'),
age= ( 29, 17, 73, 31, 62),
gender= ( 'M', 'F', 'M', 'M', 'F'),
nationality=( 'US', 'UK', 'CAN', 'CAN', 'US'),
height= ( 182.9, 167.6, 175.3, 170.2, 172.8)),
columns=('name', 'age', 'gender', 'nationality', 'height'))
pdf = pdf.set_index('name')

Intro

Most of us have faced a point when trying to make things work with the Python datetime module by just trying things around. Datetime is one of those APIs that seems easy to use but requires the developer to have a deep understanding of what things actually mean, as otherwise it is really easy to introduce unexpected bugs given the actual complexity of date and time related issues.

Time Standards

The first concept we need to grasp when working with time is a standard that defines how we can measure units of time. The same way we have standards to measure weight or length that define kilograms or meters, we need a way to accurately define what

import random
import string
from timeit import timeit
def _recombine_skipped_queue(tokens, skipped_idxs):
"""
>>> tokens = ["foo", " ", "bar", " ", "19June2000", "baz"]
>>> skipped_idxs = set([0, 1, 2, 5])
>>> _recombine_skipped(tokens, skipped_idxs)
import timeit
import operator
def time_func(f, N, k=3):
"""Basic version of IPython's %timeit magic"""
t = min(timeit.timeit(f, number=N) for _ in range(k))
t_per = t / N
if t_per < 1e-6:
units = 'ns'
#!/usr/bin/env bash
# Parse CLI arguments
REGEXES=()
POSITIONAL=()
while [[ $# -gt 0 ]]; do
key=$1
case $key in
-r|--regex)
REGEXES+=("$2")
#![feature(concat_idents,duration_as_u128)]
extern crate pyo3;
use std::thread;
use std::time;
use pyo3::prelude::*;
use pyo3::ffi::*;
use std::ffi::CString;

Instructions

These are steps for attempting to reproduce this test failure.

Get the repository

If you don't have CPython cloned locally

If you don't already have a local CPython clone, go to wherever you clone repositories and execute:

git clone git@github.com:python/cpython.git
cd cpython