Skip to content

Instantly share code, notes, and snippets.

@simonwo
simonwo / docxtables2json.py
Created Jul 20, 2020
Pulling all of the tables from a Word document into JSON files
View docxtables2json.py
#!/usr/bin/env python3
from sys import stdout, stderr, argv
import os.path
import json
try:
from docx import Document
except ImportError:
print("Maybe you should $ pip install python-docx", file=stderr)
View registers.md
@simonwo
simonwo / compact-trello.css
Last active Jul 26, 2017
Compact Trello userstyle. If you have the Stylus extension, you can download the JSON and use "Import styles".
View compact-trello.css
@-moz-document domain("trello.com") {
.card-label.mod-card-front {
width: 8px;
height: 32px;
}
.list-card-labels {
margin-right: 6px;
margin-top: 2px;
float: left;
}
@simonwo
simonwo / wireless_check.sh
Created Mar 9, 2015
Script to be called from cron to check Raspberry Pi's wireless connection
View wireless_check.sh
#!/bin/bash
# The address of the wireless access point itself
GATEWAY=`netstat -nr | grep wlan0 | grep G | awk '{ print $2 }'`
# Let's try and contact the wireless access point
ping -c 1 $GATEWAY
# Did we succeed? (ping will make $? equal to 1 if it failed, or 0 if it succeeded)
if [[ $? == 1 ]]; then
@simonwo
simonwo / cleartypes.h
Created Feb 25, 2015
These aliases make pointers and references look more like real types. See https://simonwo.net/code/clearer-cpp-types for more.
View cleartypes.h
#pragma once
/* These type alias templates (introduced in C++11) allow
* us to template typedefs (via a different syntax).
*
* Here we are templating generic pointer and reference types
* so we could write ptr<T> instead of T*.
*
* See simonwo.net/code/clearer-cpp-types for more.
*/
@simonwo
simonwo / pending.rb
Created Feb 2, 2015
Pending scenarios in Cucumber
View pending.rb
# Place me in your support/ directory and then use the @pending tag
Unless Cucumber::VERSION =~ /^2\./
Around '@pending' do |scenario, block|
scenario.steps.each &:skip_invoke!
block.call
scenario.steps.each {|step| step.status! :pending}
end
else
raise "Well done on upgrading to Cucumber 2. It's time to delete #{__FILE__}!"
end
@simonwo
simonwo / fib-cache.rb
Last active Aug 29, 2015
Cached Fibonacci in Ruby
View fib-cache.rb
Fibonacci = Hash.new {|h, i| h[i] = h[i-1] + h[i-2]}
Fibonacci[1] = 1
Fibonacci[2] = 1
# And now it's ready to use!
puts Fibonacci[6] # => 8
p Fibonacci # => {1=>1, 2=>1, 3=>2, 4=>3, 5=>5, 6=>8}
@simonwo
simonwo / install-plugins.sh
Created May 10, 2014
Scripts for auto installing Wordpress plugins. Warning: they're shitty
View install-plugins.sh
#!/bin/sh
# Usage:
# $ cd themes/your-theme/
# $ sh ./install-plugins.sh plugins.list
wget -i $1
mv *.zip ../../plugins
cd ../../plugins
ls | xargs -n 1 unzip
@simonwo
simonwo / gist:6868309
Created Oct 7, 2013
Partial classes in Ruby. Generates a new, specialised class by defining some of it's initializer arguments ahead of time.
View gist:6868309
class Class
def partial(*prep)
Class.new(self) do
define_method(:initialize) do |*args|
super(*(prep + args))
end
end
end
def << (prep)
You can’t perform that action at this time.