Skip to content

Instantly share code, notes, and snippets.

View kennethreitz's full-sized avatar
🌙

Kenneth Reitz kennethreitz

🌙
View GitHub Profile
// Here is a proposal for minimalist JavaScript classes, humbly offered.
// There are (at least) two different directions in which classes can be steered.
// If we go for a wholly new semantics and implementation, then fancier classical
// inheritance can be supported with parallel prototype chains for true inheritance
// of properties at both the class and instance level.
// If however, we keep current JavaScript prototype semantics, and add a form that
// can desugar to ES3, things must necessarily stay simpler. This is the direction
// I'm assuming here.
@david-torres
david-torres / ClickyApi.py
Created October 29, 2011 22:22
Simple Python interface for Clicky web analytics API
import requests
import json
class ClickyApi(object):
"""
A simple Python interface for the Clicky web analytics api.
Relies on the Requests library - python-requests.org
Usage:
@chrisguitarguy
chrisguitarguy / xml.py
Created October 21, 2011 21:18
Parse an XML sitemap with Python, requests and BeautifulSoup
from __future__ import with_statement # we'll use this later, has to be here
from argparse import ArgumentParser
import requests
from BeautifulSoup import BeautifulStoneSoup as Soup
def parse_sitemap(url):
resp = requests.get(url)
# we didn't get a valid response, bail
@schacon
schacon / slide_w_notes.txt
Created September 13, 2011 23:00
ShowOff slide with notes
!SLIDE bullets incremental transition=fade
.notes something something something something something something something something something something something something something something something dark side
# Second Slide #
* something
* something else
* a third thing
* a fourth thing
@sjl
sjl / email.py
Created September 8, 2011 15:15
Useful Django send_mail wrapper that will automatically add a plain text alternative to outgoing HTML emails.
from django.conf import settings
from django.core.mail import EmailMultiAlternatives
from django.template.defaultfilters import striptags
def send_mail(subject, html_message, from_email, recipient_list, fail_silently=False, connection=None):
text_message = striptags(html_message)
recipient_list = getattr(settings, 'EMAIL_RECIPIENTS_OVERRIDE', recipient_list)
msg = EmailMultiAlternatives(subject, text_message, from_email, recipient_list, connection=connection)
msg.attach_alternative(html_message, "text/html")
@schacon
schacon / plumbing.md
Created August 18, 2011 04:51
plumbing cheat sheet

the plumbing commands

  • rev-parse [something]

    • show the SHA of any weird git phrase
  • hash-object -w [file]

    • take any file or stdin and return a blob sha
  • ls-tree (-r) [sha]

  • show the entries of a git tree in the db

@kevinsawicki
kevinsawicki / UploadFile.java
Created August 2, 2011 23:39
Add downloads to a GitHub repository
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import org.eclipse.egit.github.core.Download;
import org.eclipse.egit.github.core.RepositoryId;
import org.eclipse.egit.github.core.client.GitHubClient;
import org.eclipse.egit.github.core.service.DownloadService;
/**
@technoweenie
technoweenie / gist:975010
Created May 16, 2011 18:25
Response from a support request to the DoD DPS system regarding the inability the login.
Subject: RE: DPS Site Access
No idea what you mean by script information, are you using a Mac? No Mac support for DPS. DPS
requires Windows based systems with Internet Explorer 7 or 8. If you are using IE 8, you will
have to change the zoom level to 150% (bottom right of IE8) from 100% for compatibility reasons.
Remember only IE7 and 8 supported by DPS, No Firefox, Chrome, Safari, and pop up blocker must be
turned off to access DPS and this is listed under TOOLS.
@kennethreitz
kennethreitz / 0_urllib2.py
Created May 16, 2011 00:17
urllib2 vs requests
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
gh_url = 'https://api.github.com'
req = urllib2.Request(gh_url)
password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
@jcsalterego
jcsalterego / gist:969186
Created May 12, 2011 18:49
Grab all parameters for `defaults write` for Twitter for Mac
$ find /Applications/Twitter.app \
-type f \
-exec strings {} \; \
| awk '/^values.[^ ]+$/ { sub("values.", ""); print }'
FontSize
ShowDevelopMenu
QuoteTweetSyntax
ShowFullNames
TypeAnywhereToTweet
TMLinkColor