Skip to content

Instantly share code, notes, and snippets.

View SpotlightKid's full-sized avatar

Christopher Arndt SpotlightKid

View GitHub Profile
#!/bin/sh
# Inits a project made with the django-cms-boilerplate
# Requires virtualenvwrapper and pip
# Create virtualenv if no active
if [ "$VIRTUAL_ENV" == "" ]; then
echo "Creating virtualenv... Name?"
read venvname
source virtualenvwrapper.sh
mkvirtualenv --no-site-packages $venvname
workon $venvname
@SpotlightKid
SpotlightKid / registrable.py
Last active April 13, 2016 15:47
Demonstrates how to use meta-classes to build a registry of sub-classes.
# -*- coding: utf-8 -*-
#
# registrable.py
#
"""Demonstrates how to use meta-classes to build a registry of sub-classes."""
__all__ = [
'Registrable',
'RegistrableMeta',
'BlueColor',
from contextlib import contextmanager
from time import time
from sys import stdout
@contextmanager
def duration(outfile=stdout):
start = time()
yield
end = time()
outfile.write(str(end - start) + '\n')
from contextlib import contextmanager
from operator import itemgetter
from sys import argv, stdout
from time import time
@contextmanager
def duration(outfile=stdout):
start = time()
yield
end = time()
@SpotlightKid
SpotlightKid / pyxrun.sh
Last active August 29, 2015 13:56
Here is a useful little shell function I came up with while experimenting with Cython (http://cython.org/). Put it in your ~/.bashrc and then use it to compile a Cython source code file (*.pyx extension) into a standalone executable and run it directly.
pyxrun() {
PYTHON="${PYTHON:-python}"
if [ "x$1" = "x-t" ]; then
local timeit="time"
shift
fi
if [ -z "$1" ]; then
echo "usage: pyxrun [-t] <file>.pyx"
cpdef int fib(int n):
if n == 2:
return 2
elif n < 0:
raise NotImplementedError
elif n <= 1:
return 1
else:
return fib(n-1) + fib(n-2)
@SpotlightKid
SpotlightKid / Select-folding-block.lua
Last active July 15, 2018 08:51
Lua script to select folding block in Geany editor
--[[
Select block corresponding to current folding level
--]]
line, col = geany.rowcol()
-- Scintilla uses 0-based line numbering internally
line = line - 1
--~print("L: " .. line .. " C: " .. col)
fstart = geany.scintilla("SCI_GETFOLDPARENT", line)
--~print("S: " .. fstart+1)
@SpotlightKid
SpotlightKid / aurinfohelper.sh
Last active August 29, 2015 14:00
Generate .AURINFO file, create Arch source package and add .AURINFO to it
#!/bin/bash
#
# aurinfohelper.sh
#
process() {
if [ ! -f PKGBUILD ]; then
echo "PKGBUILD not found!"
else
source PKGBUILD
@SpotlightKid
SpotlightKid / jinjarender.py
Last active April 13, 2016 15:52
Jinja2 Quick Load Function
# Source: http://pydanny.com/jinja2-quick-load-function.html
from jinja2 import FileSystemLoader, Environment
def render_from_template(directory, template_name, **kwargs):
"""Render named Jinja2 template in given direcctory.
Sample usage::
>>> from mymodule import render_from_template
@SpotlightKid
SpotlightKid / download_md2pdf.py
Last active June 20, 2018 11:56
Download Zip bundle of Python package requirements for MarkdownPDF.py and extract them to 'site-packages' sub-directory.
#!/usr/bin/env python
#-*- coding:utf-8 -*-
"""Download Zip bundle of Python package requirements for MarkdownPDF.py
and extract them to 'site-packages' sub-directory.
This is meant for Pythonista (an iOS app) users as an easy way to install
these packages.
Packages included in the Zip bundle: