Skip to content

Instantly share code, notes, and snippets.

@ferrouswheel
ferrouswheel / move_to_github.sh
Created October 16, 2012 21:45
Script to move Opencog from Launchpad to Github
#!/bin/bash
# Destination must exist as empty repo on github
GIT_REPO="git@github.com:opencog/opencog.git"
TEMP_PATH=~/src/opencog_bzr_to_git
echo "Using $TEMP_PATH as working dir"
BRANCHES=(trunk UnityEmbodiment)
mkdir -p ${TEMP_PATH}
cd ${TEMP_PATH}
@ferrouswheel
ferrouswheel / _base.html
Created March 3, 2013 23:12
Set up Django with CSRF protection when using require.js, backbone, and backbone-relational.
<script>
// Include this template in your base Django template.
// I also define my backbone API urls here, using Django's url resolver:
//var a_model_url = "{% url backbone:appname_modelname %}";
var csrf_token = "{{ csrf_token }}";
</script>
@ferrouswheel
ferrouswheel / to_local_time
Last active December 14, 2015 14:58
If you are using Django with USE_TZ=True, then Django stores times in UTC and various template utilities help to convert to the user's/current timezone as necessary. However, when serialising objects to JSON (which many API libraries do) they'll often directly convert the UTC time. This might be what you want, but you might also be using the API…
# assuming utc_datetime is the datetime to convert:
from django.utils import timezone
current_tz = timezone.get_current_timezone()
local_time = current_tz.normalize(utc_datetime).astimezone(current_tz)
@ferrouswheel
ferrouswheel / config
Last active December 14, 2015 19:39
Want to tunnel your ssh connections through host A to get to host B?
# Why would you do this?
# Well, perhaps you have a VPN to A, and A can access B but you can't access B directly.
# Assuming a and b are hosts in the domain example.com. Add the below to ~/.ssh/config on
# your local machine.
Host b.example.com
ProxyCommand ssh -q a.example.com nc -q0 b.example.com 22
# If you have another host that only b can access, you can also chain through that!
@ferrouswheel
ferrouswheel / access_horror.py
Last active December 18, 2015 23:49
Liberate data from Access databases.
"""
A script to run on a Windows 7 host after installing the Access redistributable:
http://www.microsoft.com/en-nz/download/details.aspx?id=13255
Install Python 2.7, and then pyodbc from:
http://code.google.com/p/pyodbc/
The script dumps all tables to a dictionary and pickles it. The dictionary has a key for each table name, each value is a dictionary that has the following keys.
@ferrouswheel
ferrouswheel / template.html
Last active December 19, 2015 12:19
Want to use Django pagination and bootstrap's paginator div? Want to customise and avoid installing an entirely new app? Just copy, paste and customise the below.
<!-- Assume spreadsheets is a django pagination object and pages is an iterable of page numbers to display -->
<!-- Note: this doesn't preserve GET parameters or hash fragments -->
<div class="pagination">
<ul>
{% if spreadsheets.has_previous %}
<li><a href="?page={{ spreadsheets.previous_page_number }}">&laquo;</a></li>
{% else %}
<li class="disabled"><a href="?page={{ spreadsheets.previous_page_number }}">&laquo;</a></li>
{% endif %}
@ferrouswheel
ferrouswheel / conf.py
Last active September 22, 2017 10:50
Sphinx add-on to annotate Django models based on fields and their help_text. Based on https://djangosnippets.org/snippets/2533/ - but adds ForeignKey resolution, and ensure field.rel.to is an actual model instead of a string.
import sys, os
local_path = lambda path: os.path.join(os.path.dirname(__file__), path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'PROJECTNAME.settings'
sys.path.append(local_path('..'))
... # Rest of conf.py goes here

Docker Cheat Sheet

Why

Why Should I Care (For Developers)

"Docker interests me because it allows simple environment isolation and repeatability. I can create a run-time environment once, package it up, then run it again on any other machine. Furthermore, everything that runs in that environment is isolated from the underlying host (much like a virtual machine). And best of all, everything is fast and simple."

TL;DR, I just want a dev environment

Keybase proof

I hereby claim:

  • I am ferrouswheel on github.
  • I am jpwp (https://keybase.io/jpwp) on keybase.
  • I have a public key whose fingerprint is 1183 6DAE 39D0 C262 DC7A 905C F151 CC60 5B54 C9AF

To claim this, I am signing this object:

# Copyright 2012 Erlware, LLC. All Rights Reserved.
#
# This file is provided to you under the Apache License,
# Version 2.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,