Skip to content

Instantly share code, notes, and snippets.

@DmitrySoshnikov
DmitrySoshnikov / python-closures.py
Created November 15, 2010 12:03
Understanding Python's closures
# "Understanding Python's closures".
#
# Tested in Python 3.1.2
#
# General points:
#
# 1. Closured lexical environments are stored
# in the property __closure__ of a function
#
# 2. If a function does not use free variables
@irfani
irfani / selenium_spider.py
Created June 24, 2011 16:10
Scrapyd with Selenium Spider
from selenium import selenium
from scrapy.spider import BaseSpider
from scrapy.http import Request
import time
import lxml.html
class SeleniumSprider(BaseSpider):
name = "selenium"
allowed_domains = ['selenium.com']
start_urls = ["http://localhost"]
@harlantwood
harlantwood / .gitignore
Last active March 19, 2018 16:08
CoffeeScript->Javascript D3 Force-Directed Layout (Multiple Foci)
.idea
Cakefile.js
tmp/
@endolith
endolith / example.txt
Last active November 3, 2023 18:20
Parseval's theorem Python NumPy example
In [1]: n = 10000000
In [2]: x = rand(n)
In [3]: X = fft(x)
In [4]: rms_flat(x)
Out[4]: 0.57731639149367697
In [5]: rms_flat(ifft(X))
@chitchcock
chitchcock / 20111011_SteveYeggeGooglePlatformRant.md
Created October 12, 2011 15:53
Stevey's Google Platforms Rant

Stevey's Google Platforms Rant

I was at Amazon for about six and a half years, and now I've been at Google for that long. One thing that struck me immediately about the two companies -- an impression that has been reinforced almost daily -- is that Amazon does everything wrong, and Google does everything right. Sure, it's a sweeping generalization, but a surprisingly accurate one. It's pretty crazy. There are probably a hundred or even two hundred different ways you can compare the two companies, and Google is superior in all but three of them, if I recall correctly. I actually did a spreadsheet at one point but Legal wouldn't let me show it to anyone, even though recruiting loved it.

I mean, just to give you a very brief taste: Amazon's recruiting process is fundamentally flawed by having teams hire for themselves, so their hiring bar is incredibly inconsistent across teams, despite various efforts they've made to level it out. And their operations are a mess; they don't real

@alexle
alexle / pythonsms.py
Last active December 1, 2023 01:01
How to send a text message with python
# sms.py
# Sends sms message to any cell phone using gmail smtp gateway
# Written by Alex Le
import smtplib
# Use sms gateway provided by mobile carrier:
# at&t: number@mms.att.net
# t-mobile: number@tmomail.net
# verizon: number@vtext.com
@wrunk
wrunk / jinja2_file_less.py
Last active September 19, 2023 15:05
python jinja2 examples
#!/usr/bin/env/python
#
# More of a reference of using jinaj2 without actual template files.
# This is great for a simple output transformation to standard out.
#
# Of course you will need to "sudo pip install jinja2" first!
#
# I like to refer to the following to remember how to use jinja2 :)
# http://jinja.pocoo.org/docs/templates/
#
@ssp
ssp / git-extract-file.markdown
Created January 23, 2012 13:21
Extract a single file from a git repository

How to extract a single file with its history from a git repository

These steps show two less common interactions with git to extract a single file which is inside a subfolder from a git repository. These steps essentially reduce the repository to just the desired files and should performed on a copy of the original repository (1.).

First the repository is reduced to just the subfolder containing the files in question using git filter-branch --subdirectory-filter (2.) which is a useful step by itself if just a subfolder needs to be extracted. This step moves the desired files to the top level of the repository.

Finally all remaining files are listed using git ls, the files to keep are removed from that using grep -v and the resulting list is passed to git rm which is invoked by git filter-branch --index-filter (3.). A bit convoluted but it does the trick.

1. copy the repository to extract the file from and go to the desired branch

@dupuy
dupuy / README.rst
Last active April 23, 2024 23:38
Common markup for Markdown and reStructuredText

Markdown and reStructuredText

GitHub supports several lightweight markup languages for documentation; the most popular ones (generally, not just at GitHub) are Markdown and reStructuredText. Markdown is sometimes considered easier to use, and is often preferred when the purpose is simply to generate HTML. On the other hand, reStructuredText is more extensible and powerful, with native support (not just embedded HTML) for tables, as well as things like automatic generation of tables of contents.

@efeminella
efeminella / gist:1937609
Created February 29, 2012 04:13
Loading external Handlebars Templates with jQuery or Zepto
/*
* Extends Handlebars with a basic get method for loading external
* Handlebars templates. Simply pass an options object which contains
* the following properties:
* - path (required) : Path to the external template file to be loaded
* - success (required) : Callback invoked with the compiled loaded template.
* - cache (optional) : true if the template is to be cached, otherwise false.
*
* In addition to the above arguments, any jQuery/Zepto.ajax options argument
* can be specified as well.