Skip to content

Instantly share code, notes, and snippets.

View lrq3000's full-sized avatar
🎵

Stephen Karl Larroque lrq3000

🎵
View GitHub Profile
@bellbind
bellbind / relimporter.py
Created July 26, 2010 14:33
[python] __import__ by relative module style
def import_as(module_name, globals_):
"""__import__ for relative module style.
usage:
mod = import_as("..templates.jinja2", globals())
# it is same as: import ..templates.jinja2 as mod
"""
level = 0
for ch in module_name:
if ch != ".": break
level += 1
@jtriley
jtriley / terminalsize.py
Created July 26, 2011 21:58
Get current terminal size on Linux, Mac, and Windows
#!/usr/bin/env python
import os
import shlex
import struct
import platform
import subprocess
def get_terminal_size():
""" getTerminalSize()
@GaelVaroquaux
GaelVaroquaux / 00README.rst
Last active September 15, 2023 03:58
Copy-less bindings of C-generated arrays with Cython

Cython example of exposing C-computed arrays in Python without data copies

The goal of this example is to show how an existing C codebase for numerical computing (here c_code.c) can be wrapped in Cython to be exposed in Python.

The meat of the example is that the data is allocated in C, but exposed in Python without a copy using the PyArray_SimpleNewFromData numpy

@jiahao
jiahao / Optimizer.py
Created January 4, 2012 17:44
Pure Python implementation of some numerical optimizers
#!/usr/bin/env python
'''
Pure Python implementation of some numerical optimizers
Created on Jan 21, 2011
@author Jiahao Chen
'''
@robnyman
robnyman / IndexedDB-storing-and-retrieving-files.js
Created February 23, 2012 17:55
IndexedDB storing and retrieving files
(function () {
// IndexedDB
var indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.OIndexedDB || window.msIndexedDB,
IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.OIDBTransaction || window.msIDBTransaction,
dbVersion = 1.0;
// Create/open database
var request = indexedDB.open("elephantFiles", dbVersion),
db,
createObjectStore = function (dataBase) {
@josiahcarlson
josiahcarlson / goto.py
Created April 1, 2012 17:04
Decorators for adding goto/switch semantics to Python
'''
This code is derived from: http://code.activestate.com/recipes/576944/
It was released under the MIT license.
I (Josiah Carlson) have modified it to be correct in more cases, and to report
errors in some error cases.
@tommeier
tommeier / avatar.perl
Created September 14, 2012 05:37
Run Gource over your git repo
#!/usr/bin/perl
#fetch Gravatars
use strict;
use warnings;
use LWP::Simple;
use Digest::MD5 qw(md5_hex);
my $size = 90;
@irachex
irachex / Treap.py
Created October 20, 2012 08:43
Treap (tree + heap) in Python
import random
class TreapNode(object):
def __init__(self, key, data):
self.key = key
self.ran = random.random()
self.size = 1
self.cnt = 1
self.data = data
self.left = None
@rduplain
rduplain / slides.md
Last active February 7, 2019 15:40
Use Werkzeug's web-based interactive debugger with Tornado.

Interactive Debugging in any Python Web Project

Ron DuPlain - PyOhio 2013

Turn this:

@mwaterfall
mwaterfall / validate.py
Last active December 27, 2015 00:44
Recursively validates all python files with pyflakes that were modified since the last validation, and provides basic stats. Ignores hidden directories.
#
# Recursively validates all python files with pyflakes that were modified
# since the last validation, and provides basic stats. Ignores hidden
# directories.
#
# NOTE:
# You should set your favourite version control system to ignore
# the validate.db file that is used to track when which files
# have changed since last validation.
#