Skip to content

Instantly share code, notes, and snippets.

git diff --word-diff=color --word-diff-regex=[^,$]+ <file1> <file2>
import gc
from io import StringIO
import xml.etree.ElementTree as etree
import objgraph
def parse_xml():
xml = """
<LEVEL1>
### Keybase proof
I hereby claim:
* I am grokcode on github.
* I am grokcode (https://keybase.io/grokcode) on keybase.
* I have a public key ASA01gbqLmX41b8VaBMJmHKo800oujS9A6ZHgBpovfVTtAo
To claim this, I am signing this object:
@grokcode
grokcode / test_flatten.py
Created January 29, 2018 22:35
Flatten a nested array
import pytest
# Solution in Python 3.6
def flatten(a):
"""
Flatten a list by removing nested lists while preserving their elements.
(Python doesn't have native arrays, we can use lists instead.)
"""
# This Gist covers how to use Django's signing functions for one-click unsubscribes
# The following code can go in the UserProfile
from django.core.signing import TimestampSigner, BadSignature, SignatureExpired
def create_unsubscribe_link(self):
username, token = self.make_token().split(":", 1)
$ VAGRANT_LOG=debug vagrant halt web
INFO global: Vagrant version: 1.2.2
DEBUG global: Loading core plugin: /Applications/Vagrant/embedded/gems/gems/vagrant-1.2.2/plugins/commands/box/plugin.rb
INFO manager: Registered plugin: box command
DEBUG global: Loading core plugin: /Applications/Vagrant/embedded/gems/gems/vagrant-1.2.2/plugins/commands/destroy/plugin.rb
INFO manager: Registered plugin: destroy command
DEBUG global: Loading core plugin: /Applications/Vagrant/embedded/gems/gems/vagrant-1.2.2/plugins/commands/halt/plugin.rb
INFO manager: Registered plugin: halt command
DEBUG global: Loading core plugin: /Applications/Vagrant/embedded/gems/gems/vagrant-1.2.2/plugins/commands/init/plugin.rb
INFO manager: Registered plugin: init command
year_ago = date.today() - timedelta(days=365)
q_new_books = Q(orig_pub_date=None) | Q(orig_pub_date__gt=year_ago)
q_multiple_books = Q(book__count__gt=1)
qs = Works.objects.all()
len(qs.annotate(Count('book')).filter(q_new_books)) # 14
len(qs.annotate(Count('book')).filter(q_multiple_books)) # 72
len(qs.annotate(Count('book')).filter(q_new_books | q_multiple_books)) # 8 WTF?
@grokcode
grokcode / StripeTutorialPage.html
Created January 12, 2012 20:47
Stripe Tutorial Payment Form
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Stripe Getting Started Form</title>
<script type="text/javascript" src="https://js.stripe.com/v1/"></script>
<!-- jQuery is used only for this example; it isn't required to use Stripe -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
// this identifies your website in the createToken call below