Skip to content

Instantly share code, notes, and snippets.

desc "Will replace i18n references in specs with actual text from default locale"
task undo_i18n_in_specs: :environment do
Dir[Rails.root.join("spec/features/**/*.rb")].collect do |file_name|
file_text = File.read(file_name)
file_text.scan(/\Wt\("([\w\.]+)"\)/).each do |match|
file_text.gsub!("t(\"#{match.first}\")", "\"#{I18n.t(match.first)}\"")
end
File.open(file_name, "w") { |file| file.puts file_text }
end
end
@james
james / flame_detector.py
Last active July 20, 2020 17:25
Zonal flame detector
# Install raspbian lite
# run `sudo raspi-config` and enable camera
# sudo apt-get update
# sudo apt-get upgrade
# sudo apt-get install python3-picamera
# sudo apt-get install python3-rpi.gpio
from picamera.array import PiYUVArray
from picamera import PiCamera
from time import sleep
@james
james / convert.rb
Created August 19, 2017 18:02
Example hacky code from the Jeremy Corbyn Labour leadership campaign 2015
require 'csv'
require 'date'
require 'chronic'
HEADERS_TO_KEEP = ['MembershipNumber', 'Title', 'LastName', 'PreferredFirstName', 'DateOfBirth', 'AddressLine1', 'AddressLine2', 'AddressLine3', 'Town', 'Country Code', 'County', 'PostCode', 'Email', 'MobilePhoneNumber', 'PhoneNumber', 'RegionName', 'ConstituencyName', 'TradeUnion', 'PrimaryStatus'] #, 'JoinedDate'
Dir.entries('to_convert')[2..999].each do |file|
members = CSV.read("to_convert/#{file}", headers: true, :encoding => 'windows-1251:utf-8')
# remove unused columns
@james
james / menu_controller.rb
Last active August 29, 2015 14:07
A Rails controller I wrote in 2006. This is bad code. Don't copy it.
class PagesController < ApplicationController
layout 'site'
def show
@page = Page.find_by_url(params[:id], :limit => 1)
@content = @page.content.gsub(/£/, "&pound;")
@cat = @page.category
if @cat == 'overview' or @cat == 'menu' or @cat == 'offers'
@subcat = @cat
@cat = 'restaurant'

Keybase proof

I hereby claim:

  • I am james on github.
  • I am abscond (https://keybase.io/abscond) on keybase.
  • I have a public key whose fingerprint is 2440 6B38 61ED 4BD1 61B2 5F6F 3866 9EBB 7B84 70DA

To claim this, I am signing this object:

@james
james / run.rb
Last active August 29, 2015 13:58
require 'twitter'
require 'csv'
@client = Twitter::REST::Client.new do |config|
config.consumer_key = ""
config.consumer_secret = ""
config.access_token = ""
config.access_token_secret = ""
end
// ==UserScript==
// @name Highlight italics
// @version 0.1
// @namespace abscond
// @include *
// ==/UserScript==
arr = document.getElementsByTagName('i');
var length = arr.length;
@james
james / rightmove_bedrooms.user.js
Created July 1, 2013 08:57
Userscript to add price per bedroom in rightmove.co.uk search results.
// ==UserScript==
// @name Right Move Price per Bedroom
// @version 0.1.4
// @namespace abscond
// @include http://*rightmove.co.uk/*/find*
// ==/UserScript==
function addJQuery(callback) {
var script = document.createElement("script");
@james
james / REAMDE.md
Last active November 16, 2016 18:30
Pingdom Dashing Widget

Description

Simple Dashing widget (and associated job) to display Pingdom checks.

##Dependencies

pingdom-client

Add it to dashing's gemfile:

@james
james / gist:5508572
Last active December 16, 2015 22:39
require 'twitter'
Twitter.configure do |config|
config.consumer_key = YOUR_CONSUMER_KEY
config.consumer_secret = YOUR_CONSUMER_SECRET
config.oauth_token = YOUR_OAUTH_TOKEN
config.oauth_token_secret = YOUR_OAUTH_TOKEN_SECRET
end
s = nil
while true
if IO.popen('pbpaste', 'r+').read != s