Skip to content

Instantly share code, notes, and snippets.

View adamcharnock's full-sized avatar

Adam Charnock adamcharnock

View GitHub Profile
@adamcharnock
adamcharnock / post-checkout
Created April 22, 2014 11:28
.git/hooks/post-checkout
#!/bin/bash
echo "Cleaning up .pyc files and empty directories"
REPO_ROOT=./$(git rev-parse --show-cdup)
# Delete .pyc files and empty directories.
find $REPO_ROOT -name "*.pyc" -delete
find $REPO_ROOT -type d -empty -delete
@adamcharnock
adamcharnock / gist:3779308f4f1fb994397e
Created June 11, 2015 17:54
Experimenting with making a ShortUUID class
from uuid import UUID, uuid4
import base64
def make_uuid(type_bits, type_size):
bits = uuid4().int
id_size = 128 - type_size
# Zero out the type bits
bits &= pow(2, id_size) - 1
# Now add in the type
bits |= (type_bits << id_size)
<?xml version="1.0" encoding="UTF-8"?>
<!-- Only the settings with values not equal to defaults are in this file. If you want to see the
full list of available settings, check the amstock_settings.xml file in the amstock folder. -->
<settings>
<margins>0</margins>
<!-- <max_series>10</max_series> -->
<redraw>true</redraw>
<max_grid_count>30</max_grid_count>
<equal_spacing>false</equal_spacing>
DROP TEMPORARY TABLE IF EXISTS siteswith30days;
CREATE TEMPORARY TABLE siteswith30days SELECT r2.siteid, COUNT(*) as totalrows FROM rawdata AS r2 GROUP BY siteid HAVING totalrows > 6*24*30;
SELECT
r.*,
(r.winddirection % 1024) * (360/1024) AS winddirectiondegrees,
0.8669 * (r.windpulsecount/600) + 0.32 AS windspeed,
s.postcode,
s.anemometerheight
FROM
rawdata AS r
#!/bin/bash
if [[ ! -n "$1" || ! -n "$2" ]]
then
echo "Usage: `basename $0` environment port"
exit 1
fi
declare -i date
declare -i lastsave
@adamcharnock
adamcharnock / method_proxy.py
Last active September 11, 2015 13:10
A sqlalchemy-continuum plugin for making model methods and properties available on the versioned model
""" A sqlalchemy-continuum plugin for making model methods
and properties available on the versioned model
"""
from functools import wraps
from sqlalchemy_continuum.plugins import Plugin
def override_in_versioned(function=None):
""" Use the explicitly mark methods which should be

We have been covering some fairly complex Redis topics here so far, so I thought it would be nice to do a good ol’ getting started guide. This should get you on your feet with Python and Redis on Ubuntu Linux. So, fire up a terminal window and get going!

Getting Redis installed & running

This guide uses Redis 2.0.3, but you can see if there is a newer version at redis.io:

apt-get install build-essential

wget http://redis.googlecode.com/files/redis-2.0.3.tar.gz
tar -zxf redis-2.0.3.tar.gz
@adamcharnock
adamcharnock / gist:1073858
Created July 9, 2011 19:18
Initial work on a Ruby/Rails setup script for https://continuous.io
#!/bin/bash -e
# The following variables are available to you
# (values are examples only)
#
# TIMEZONE="UTC" # The timezone this server should be given
# CI_USER="ci" # The user to setup and run the tests as
# # (although you are free to ignore this)
#
# GIT_URI="git://github.com/andymccurdy/redis-py.git" # The Git URL for this project
#!/bin/bash -ex
# Setup node-jshint and run it
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
curl http://npmjs.org/install.sh | sudo clean=no sh
<?xml version="1.0" ?>
<!DOCTYPE coverage
SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'>
<coverage branch-rate="0" line-rate="0.8934" timestamp="1310992801111" version="3.4">
<!-- Generated by coverage.py: http://nedbatchelder.com/code/coverage -->
<packages>
<package branch-rate="0" complexity="0" line-rate="0.9635" name="ci">
<classes>
<class branch-rate="0" complexity="0" filename="ci/__init__.py" line-rate="1" name="__init__">
<methods/>