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
@DHager
DHager / transcribed_html5_video.html
Last active April 30, 2019 21:28
Something I whipped up for a Seattle Startup Weekend event, provides a "transcript" of a video based on its closed-captioning data, and allows you to use the text to seek in the video.
<html>
<head>
<script type="text/javascript" src="jquery-1.11.0.js"></script>
<style>
#transcript{
background-color:#F0F0F0;
min-height:50px;
padding:5px;
}
#transcript span.active {
@tagr
tagr / server.js
Created September 28, 2014 20:22
Node.js/Express: Add Expires header to /images and /stylesheets directories
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes')
, user = require('./routes/user')
, http = require('http')
, path = require('path');
@davemo
davemo / app.coffee
Last active March 25, 2020 13:25
Got a .coffee file with JSX? Here's how you can transpile to .js with Reacts JSX parsed.
`/** @jsx React.DOM */`
converter = new Showdown.converter
Comment = React.createClass
render: ->
rawMarkup = converter.makeHtml @props.children.toString()
`<div className="comment">
<h2 className="comment">{this.props.author}</h2>
<span dangerouslySetInnerHTML={{__html: rawMarkup}} />
@branneman
branneman / better-nodejs-require-paths.md
Last active April 27, 2024 04:16
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@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):
@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
#
# ...
@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
@christianroman
christianroman / training.sh
Last active October 26, 2021 06:04
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
@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:
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]