Skip to content

Instantly share code, notes, and snippets.

@tomviner
tomviner / cat-me.py
Created February 24, 2016 19:36
Who's been dojo herding a lot recently?
from __future__ import division, print_function
from collections import defaultdict
from operator import itemgetter
get_values = itemgetter(1)
last_few_herders = """
Nicholas
Gautier
@tomviner
tomviner / jquerify.js
Created January 30, 2016 20:59
Add jQuery to a page.
(function() {
var b = document.getElementsByTagName('body')[0];
otherlib = false;
if (typeof jQuery != 'undefined') {
console.log('This page already using jQuery v' + jQuery.fn.jquery);
} else if (typeof $ == 'function') {
otherlib = true;
}
function getScript(url, success) {
var script = document.createElement('script');
2-_129-_256-Ā_17-_144-_271-ď_257-ā_384-ƀ_511-ǿ_4097-ခ_4224-ႀ_4351-ჿ_65537-𐀁_65664-𐂀_65791-𐃿_1048577-􀀁_1048704-􀂀_1048831-􀃿
@tomviner
tomviner / output.txt
Last active August 29, 2015 14:24
Hypothesis test_reverse example
[206096504910900498493010377380239941762L, 27, 241, 468, 206096504910900498493010366855655511824L, -340, 206096504910900498493010370573292788646L, 6, -188, 206096504910900498493010365575630902925L]
[21895897394889366278002048857818986990125268678994617770323631L, -5, 73453863292979521160722570724395436702110210638363401802874390L, 860083230267801667615814962096447759118030419081884684367195374L, 1208756186641563556189216823181235577582763775470322786885255197L, 563574118372954898036644503963904424109207146483853094148809633L, 20, -1464475540476225476021127290449598226042060199991921137850322312L, -1554085104269531629275069816677895447025824915356256971517138516L, 658781301413442456187105669962066361153531021415203972856482081L, 1421770204015349061297731987862436233014697243702547161097469746L, 1111082349050193290192329277649104120747717126931126127983058755L, -109571337096131499455011271023310218778431969690802066031870575L, -1536409144373002107386864029818511666641780965936236899633623888L, 0, 14137316515470
"""
https://twitter.com/raymondh/status/617049150606028801
#python tip: The modulo operation x % y gives a result with the same sign as y and with abs(result) < abs(y):
>>> 11 % 7
4
>>> 11 % -7
-3
"""
import math
from hypothesis import given, assume
@tomviner
tomviner / queens.py
Last active September 20, 2016 20:26 — forked from teh/sudoku.py
8 Queens problem with a SAT solver
import pycosat
import numpy
import itertools
blank_idx = 0
queen_idx = 1
def get_cnf():
# * add one because 0 is reserved in picosat
# * object type because pycosat expects 'int's
@tomviner
tomviner / README.md
Last active August 29, 2015 14:22
How HTTPS Everywhere Chrome extension is breaking Lanyrd signin

Steps to reproduce bug

  1. Install Chrome extension HTTPS Everywhere
    • I have Version: 2015.5.28
  2. Visit http://lanyrd.com/
  3. Click Signin
  4. A JS error popup should appear saying
    • image

Confirm

@tomviner
tomviner / fixture_loading.py
Created April 17, 2015 10:22
Load a django fixture, but error if the file can't be found
import os
from django.core import management
from django.conf import settings
def load_ensured_fixture(fixture_path):
"""
Load a fixture with a path like 'my_app/fixtures/test_initial_data.json'
@tomviner
tomviner / README.md
Last active February 23, 2016 11:22
Enabling viewing of rewritten AST trees as Python

Use pytest_configure to patch pytest/_pytest/assertion/rewrite.py::rewrite_asserts

Note: I'm now in the process of converting this guide to a pytest plugin.

Install this gist:

git clone [email protected]:/c3537c2f2b2b8172f83e.git display_ast_rewrite
cd display_ast_rewrite
pip install -r requirements.txt
import pytest
import httpretty
@pytest.yield_fixture
def mock_out_devpi():
httpretty.reset()
httpretty.enable()
# prevent all other urls, except those registered
httpretty.HTTPretty.allow_net_connect = False
hosts = ('pypi.local', 'pypi-zonza.company.local')