Skip to content

Instantly share code, notes, and snippets.

@grantslatton
grantslatton / hngen.py
Last active September 27, 2021 11:07
A program that uses Markov chains to generate probabilistic Hacker News titles.
import urllib2
import re
import sys
from collections import defaultdict
from random import random
"""
PLEASE DO NOT RUN THIS QUOTED CODE FOR THE SAKE OF daemonology's SERVER, IT IS
NOT MY SERVER AND I FEEL BAD FOR ABUSING IT. JUST GET THE RESULTS OF THE
CRAWL HERE: http://pastebin.com/raw.php?i=nqpsnTtW AND SAVE THEM TO "archive.txt"
@jimmycuadra
jimmycuadra / foo__slash__foo.py
Created March 2, 2014 18:44
Example test structure
class Foo(object):
def bar(self):
pass
def baz(self):
pass
from mock import patch
@patch('path.to.module.S3Library')
def test_stores_data_in_s3(S3Library):
my_method(data)
assert S3Library.upload_file.called_once_with(data)
@patch('path.to.module.S3Library')
def test_data_contains_some_value(S3Library):
S3Library.get_file.return_value = _stub_data()
@jimmycuadra
jimmycuadra / cloud-config.yml
Last active April 19, 2021 03:04
CoreOS cloud-config for DigitalOcean with iptables firewall
#cloud-config
coreos:
etcd:
# generate a new token for each unique cluster from https://discovery.etcd.io/new
discovery: https://discovery.etcd.io/<token>
# multi-region deployments, multi-cloud deployments, and droplets without
# private networking need to use $public_ipv4
addr: $private_ipv4:4001
peer-addr: $private_ipv4:7001
@jimmycuadra
jimmycuadra / .travis.yml
Created February 13, 2015 05:25
Travis config for a Lita plugin
language: ruby
rvm:
- 2.0.0
script: bundle exec rspec
before_install:
- gem update --system
services:
- redis-server
@pixeltrix
pixeltrix / time_vs_datatime.md
Last active April 23, 2025 13:36
When should you use DateTime and when should you use Time?

When should you use DateTime and when should you use Time?

It's a common misconception that [William Shakespeare][1] and [Miguel de Cervantes][2] died on the same day in history - so much so that UNESCO named April 23 as [World Book Day because of this fact][3]. However because England hadn't yet adopted [Gregorian Calendar Reform][4] (and wouldn't until [1752][5]) their deaths are actually 10 days apart. Since Ruby's Time class implements a [proleptic Gregorian calendar][6] and has no concept of calendar reform then there's no way to express this. This is where DateTime steps in:

>> shakespeare = DateTime.iso8601('1616-04-23', Date::ENGLAND)
=> Tue, 23 Apr 1616 00:00:00 +0000
>> cervantes = DateTime.iso8601('1616-04-23', Date::ITALY)
=> Sat, 23 Apr 1616 00:00:00 +0000