Skip to content

Instantly share code, notes, and snippets.

Avatar

Christopher Arndt SpotlightKid

View GitHub Profile
View initcmsproject.sh
#!/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 Apr 13, 2016
Demonstrates how to use meta-classes to build a registry of sub-classes.
View registrable.py
# -*- coding: utf-8 -*-
#
# registrable.py
#
"""Demonstrates how to use meta-classes to build a registry of sub-classes."""
__all__ = [
'Registrable',
'RegistrableMeta',
'BlueColor',
View duration.py
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')
View benchmark.py
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 Aug 29, 2015
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.
View pyxrun.sh
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"
View fibonacci.py
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 Jul 15, 2018
Lua script to select folding block in Geany editor
View Select-folding-block.lua
--[[
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 Aug 29, 2015
Generate .AURINFO file, create Arch source package and add .AURINFO to it
View aurinfohelper.sh
#!/bin/bash
#
# aurinfohelper.sh
#
process() {
if [ ! -f PKGBUILD ]; then
echo "PKGBUILD not found!"
else
source PKGBUILD
@SpotlightKid
SpotlightKid / jinjarender.py
Last active Apr 13, 2016
Jinja2 Quick Load Function
View jinjarender.py
# 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 Jun 20, 2018
Download Zip bundle of Python package requirements for MarkdownPDF.py and extract them to 'site-packages' sub-directory.
View download_md2pdf.py
#!/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:
You can’t perform that action at this time.