Skip to content

Instantly share code, notes, and snippets.

View pconerly's full-sized avatar
💭
doing code archeology

Peter Conerly pconerly

💭
doing code archeology
View GitHub Profile
@jboner
jboner / latency.txt
Last active April 7, 2025 09:18
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@LeVM
LeVM / Default (OSX).sublime-keymap
Created September 27, 2012 22:58
Sublime Text 2 - Keybindings for typing accented characters
{ "keys": ["alt+`,a"], "command": "insert", "args": {"characters": "à"} },
{ "keys": ["alt+i,a"], "command": "insert", "args": {"characters": "â"} },
{ "keys": ["alt+e,e"], "command": "insert", "args": {"characters": "é"} },
{ "keys": ["alt+`,e"], "command": "insert", "args": {"characters": "è"} },
{ "keys": ["alt+i,e"], "command": "insert", "args": {"characters": "ê"} },
{ "keys": ["alt+`,e"], "command": "insert", "args": {"characters": "ë"} },
{ "keys": ["alt+u,i"], "command": "insert", "args": {"characters": "ï"} },
{ "keys": ["alt+i,i"], "command": "insert", "args": {"characters": "î"} },
{ "keys": ["alt+i,o"], "command": "insert", "args": {"characters": "ô"} },
{ "keys": ["alt+`,u"], "command": "insert", "args": {"characters": "ù"} },
@bzerangue
bzerangue / recursive-convert-js-to-coffeescript.sh
Created December 11, 2012 00:23
RECURSIVELY Bash convert Javascript to Coffeescript; and also Coffeescript to Javascript
find . -name "*.js" | while read i; do js2coffee "$i" > "${i%.*}.coffee"; done
@desandro
desandro / require-js-discussion.md
Created January 31, 2013 20:26
Can you help me understand the benefit of require.js?

I'm having trouble understanding the benefit of require.js. Can you help me out? I imagine other developers have a similar interest.

From Require.js - Why AMD:

The AMD format comes from wanting a module format that was better than today's "write a bunch of script tags with implicit dependencies that you have to manually order"

I don't quite understand why this methodology is so bad. The difficult part is that you have to manually order dependencies. But the benefit is that you don't have an additional layer of abstraction.


from django.contrib import admin
from .models import Author, Book
class BookInline(admin.TabularInline):
model = Book
readonly_fields = ['slug']
class AuthorAdmin(admin.ModelAdmin):
inlines = [BookInline]
@mminer
mminer / jsonhandler.py
Created April 26, 2013 02:36
A JSON request handler for Tornado.
import json
import tornado.web
class JsonHandler(BaseHandler):
"""Request handler where requests and responses speak JSON."""
def prepare(self):
# Incorporate request JSON into arguments dictionary.
if self.request.body:
try:
@christianroman
christianroman / training.sh
Last active November 22, 2024 21:52
Tesseract OCR training new font
#! /bin/bash
# build the environment
mkdir tessenv; cd tessenv
TROOT=`pwd`
mkdir $TROOT/stockfonts; mkdir $TROOT/build; mkdir $TROOT/build/eng
echo "Environment built"
# Get the stock english fonts from Google (old, but they work)
cd $TROOT/stockfonts
GET http://tesseract-ocr.googlecode.com/files/boxtiff-2.01.eng.tar.gz > boxtiff-2.01.eng.tar.gz
@pamelafox
pamelafox / desk.py
Created June 25, 2013 02:09
Desk.com API Python Wrapper
import logging
import requests
from django.utils import simplejson
from django.conf import settings
class DeskError(Exception):
def __init__(self, status):
Exception.__init__(self, status) # Exception is an old-school class
@e4c5
e4c5 / paginator
Last active January 7, 2022 14:29
The django admin change_list template causes the execution of the 'select count(*) from table_name' type query which can be very slow when the table has a few million entries. The problem is better described at https://code.djangoproject.com/ticket/8408 The following custom paginator will solve this issue by caching the row count for a short per…
import collections
from math import ceil
from django.core.paginator import Page
from django.core.cache import cache
# To use the paginator, add the following to your admin class:
# from myapp import CachingPaginator
#
# ...
@cpatulea
cpatulea / gist:7394412
Created November 10, 2013 05:59
Find Python string literals that should probably be Unicode
#!/usr/bin/python
import ast, _ast, os
for root, dirs, files in os.walk('.'):
for name in files:
if name.endswith('.py'):
full = os.path.join(root, name)
t = ast.parse(open(full).read())
for n in ast.walk(t):
if isinstance(n, _ast.Str) and not isinstance(n.s, unicode):