Skip to content

Instantly share code, notes, and snippets.

View tf198's full-sized avatar

Tris Forster tf198

View GitHub Profile
@tf198
tf198 / tf_organise.py
Created March 15, 2013 23:10
Rename and organise files on a Topfield TRF 7160
#!/usr/bin/env python
"""
Script to rename and organise recordings on Topfield TRF 7160
Names everything '<programme> <date> <time>'
If there are more than two recordings of a programme it creates
a folder for it and moves everything into it. If the folder was
already created all recordings will be moved"
Requires the FTP service to be running on the topfield.
Usage: python tf_organise.py <ip_address> <username>
"""
@tf198
tf198 / archive.py
Created January 24, 2013 09:49
Archiver for directories with years of accumulated files you want to clean up. I had a directory with 15 years of projects, many with lots of revisions and helpfully named 'important.old' folders totaling about 20GB and I wanted to start backing it up to offsite. This script pulls out directories, tars and compresses them in a sensible way to a …
#!/usr/bin/env python
'''
This script will archive a directory and leave a text file
in its place with info about the files that have been removed. Allows you to
be fairly ruthless in your cleanup safe in the knowledge you can get it back later
if required. For example:
python archive.py data/projects/old_project -a data/archive
will result in two files, the old_projects directory will be deleted
@tf198
tf198 / can_sleep.sh
Last active December 11, 2015 15:08
Stop the computer going to sleep automatically under XFCE (tested 4.10) Useful to toggle on/off at either end of a long backup script
#!/bin/bash
set -e
SLEEP_ENABLED=30 # change this if you want (>14)
SLEEP_DISABLED=14
POWER_CONFIG="xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/inactivity-on-ac"
case "$1" in
true)
@tf198
tf198 / BaseX.php
Created August 23, 2012 01:30
Base encoder with customisable alphabets
<?php
class BaseX {
/** RFC4648 Base62 */
const BASE_64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
/** RFC4648 "URL and Filename safe" Base64 */
const URL_64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=";
/** URL and filename safe Base64 in UCA order */
@tf198
tf198 / protobuf.js
Created June 3, 2011 02:17
Javascript protobuf experiment
/**
* Javascript protobuf implementation
* Not compatible with official implemementation as no binary data in JS
* Not very useful as only compacts around 50% depending on fields
* Might be a good basis for something else one day though...
*/
var VarInt32 = {
'_base64': "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
'encode': function(i) {
@tf198
tf198 / squirrel.js
Created June 3, 2011 02:10
Compact javascript objects before serializing
/**
* Compact objects before serializing
* Reduces serialized size by around 40% depending on field types
* Takes an object describing the fields to compact/expand
* fields can be added/removed as long as the number stays the same
*
* var person = { 'name': 1, 'age': 4, 'town': 5 };
* var bob = { 'name': 'Bob', 'age', 42, 'town': 'London' };
* var data = JSON.stringify(Squirrel.compact(bob, person));
* console.log(Squirrel.expand(JSON.parse(data), person));