Skip to content

Instantly share code, notes, and snippets.

View sigmavirus24's full-sized avatar
🌴
Taking a break from F/OSS indefinitely

Ian Stapleton Cordasco sigmavirus24

🌴
Taking a break from F/OSS indefinitely
View GitHub Profile
authors:
hanzou:
name: Hanzou Hattori
display_name: Hanzou
gravatar: c66919cb194f96c696c1da0c47354a6a
email: hanzou@company.com
web: http://company.com
twitter: company
github: hhattori
jorgen:
>>> class A(object):
... def __init__(self):
... self.s = 'foo'
... def __del__(self):
... print 'deleting an instance of a'
...
>>> class B(object):
... def __init__(self):
... self.a = A()
... def __getattr__(self, name):
@sigmavirus24
sigmavirus24 / user-agent.py
Created July 20, 2014 00:03
Permanent User-Agent
import requests
s = requests.Session()
s.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36'
r = s.get('http://reidreport.com/blog/wp-content/uploads/2010/07/michelebachmann.jpg')
use std::rc::Rc;
fn main() {
let x = Rc::new(5i);
for _ in range(0, 10u) {
println!("{}", x)
}
}
h = Hash.new []
h[:first] << 1
h[:second] == [1]
h[:second] << 2
h[:first] == [1, 2]
function Person(name, location) {
this.name = name;
this.location = location;
}
var maria = new Person("Maria", "California");

A Thankyou To Google

Dear Google,

I'd just like to thank you for disabusing me of the idea that JSON is under some requirement of well-formedness. I'd been labouring under the tyrannical misapprehension that some standards body had written down how JSON was supposed to work and that if I wanted to claim I was using JSON I would have to comply with that specification.

However, I today received a bug report indicating that a project to which I contribute was unable to make HTTP requests your Google Flights website could understand. I found this perplexing, but my eyes were opened when I saw your HTTP request. In particular, I enjoyed your freeform and inclusive definition of JSON. Allow me to show you what you've called JSON by showing you my SPDY request:

:host:www.google.fr
@sigmavirus24
sigmavirus24 / pascal's output
Created August 10, 2014 13:21
Pascal's Triangle
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
@sigmavirus24
sigmavirus24 / glance_client.py
Last active August 29, 2015 14:06
HTTPS test
>>> c.http_client.session.adapters
OrderedDict([('https://', <requests.adapters.HTTPAdapter object at 0x108a30d90>), ('http://', <requests.adapters.HTTPAdapter object at 0x108a44110>)])
@sigmavirus24
sigmavirus24 / timeit_output.txt
Last active August 29, 2015 14:07
Python benefits of using a set
# Flag explanations for the lazy:
# -s: Run the given string as set-up code. Excludes set-up code from timing
# -n: Number of times to run the given statement, e.g., 'n in l'
$ python -mtimeit -n10000 -s'n = 100*100; l = set(range(n))' 'n in l'
10000 loops, best of 3: 0.0561 usec per loop
$ python -mtimeit -n10000 -s'n = 100*100; l = list(range(n))' 'n in l'
10000 loops, best of 3: 159 usec per loop
$ python3 -mtimeit -n10000 -s'n = 100*100; l = set(range(n))' 'n in l'
10000 loops, best of 3: 0.0368 usec per loop
$ python3 -mtimeit -n10000 -s'n = 100*100; l = list(range(n))' 'n in l'