Skip to content

Instantly share code, notes, and snippets.

Carl Johnson carlmjohnson

Block or report user

Report or block carlmjohnson

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:6627945
>>> funcs = []
>>> for i in range(10):
... def f(): return i
... funcs.append(f)
...
>>> [func() for func in funcs]
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9]
View Stereotastic Bookmarklet.js
javascript:
if (location.href.indexOf('stereotastic.com/') > -1 ) {
var re = /\/[A-Za-z0-9]{6}$/;
var m = re.exec(location.href);
if (m[0] != null) {
var wiggle_url = 'http://stereotastic.com/img/user'+m[0]+'.gif';
var tumblr_share_url =
"http://www.tumblr.com/share/photo?source="+encodeURIComponent(wiggle_url)
+ "&caption=" + encodeURIComponent('<p><a href="'+location.href+'">Stereotastic</a></p>')
+ "&click_thru=" + encodeURIComponent(location.href)
@carlmjohnson
carlmjohnson / mustache_engine.py
Last active Sep 15, 2015
An adaptor to use Mustache as a templating engine in Django 1.8+
View mustache_engine.py
import io
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.template import TemplateDoesNotExist
from django.template.backends.base import BaseEngine
from django.template.backends.utils import csrf_input_lazy, csrf_token_lazy
from django.utils.html import conditional_escape
from pystache import parse, Renderer
View randword.py
import random
with open('/usr/share/dict/words') as f:
words = f.readlines()
print(random.choice(words).strip())
View keybase.md

Keybase proof

I hereby claim:

  • I am carlmjohnson on github.
  • I am carlmjohnson (https://keybase.io/carlmjohnson) on keybase.
  • I have a public key whose fingerprint is 30BE 0B1F 857C 534D 948C D204 EFF3 01E7 5C6D 0414

To claim this, I am signing this object:

View ham.go
package sudoku
const hammDist = [...]int{
0x000: 0,
0x002: 1,
0x004: 1,
0x006: 2,
0x008: 1,
0x00A: 2,
0x00C: 2,
View net-dsl.go
package main
import (
"fmt"
"log"
"net"
"net/http"
"time"
)
@carlmjohnson
carlmjohnson / paginator.py
Last active Mar 26, 2018
Python for making 1, 2 … 5, 6, 7 … 10, 11 pagination correctly.
View paginator.py
def pages(n, max, window=1, ellipsis=None):
s = set(range(window + 2))
s.update(range(n-window, n+window+1))
s.update(range(max-window, max+1))
seq = [i for i in sorted(s) if i > 0 and i <= max]
res = [1]
for i, nxt in zip(seq, seq[1:]):
diff = nxt - i
if diff == 2:
res.append(i+1)
@carlmjohnson
carlmjohnson / git gud.md
Last active Dec 19, 2018
Git Standards
View git gud.md

Git standards Creative Commons License

Git is the democracy of programming: it is the worst tool for version control, except all those other tools that have been tried from time to time. Among other problems, Git’s command names are obtuse (what is a “rebase”?) and non-orthogonal (how is “resetting” different than “checking out”?), and Git generally impedes the creation of an accurate mental model, but without understanding its underlying directed acyclic graph, one can’t move from beginner to intermediate user. Still, it is a necessary tool in every developer’s toolbox, and following good Git practices leads to smoother, more productive development. This guide assumes you already know how to use Git and discusses some of the higher level issues around standards for collaboration.

 

[<img s

@carlmjohnson
carlmjohnson / README.md
Created Jun 5, 2018
Go project README template
View README.md

$NAME GoDoc Go Report Card

$DESCRIPTION

Installation

First install Go.

If you just want to install the binary to your current directory and don't care about the source code, run

You can’t perform that action at this time.