Skip to content

Instantly share code, notes, and snippets.

View pezholio's full-sized avatar

Stuart Harrison pezholio

  • Birmingham / London
View GitHub Profile
@pezholio
pezholio / README.markdown
Created March 5, 2012 11:34 — forked from gudbergur/README.markdown
Bootstrap's Typeahead plugin extended (allowing for AJAX functionality) among other things

This is a fork of a fork of Bootstrap Typeahead that adds minimal but powerful extensions.

I've added a couple of lines to the original fork to stop the default behaviour when tabbing. For the proper source, please see the original gist.

For example, process typeahead list asynchronously and return objects

  # This example does an AJAX lookup and is in CoffeeScript
  $('.typeahead').typeahead(
    # source can be a function
@pezholio
pezholio / xml2array
Created February 25, 2012 20:26
PHP XML to Array
function xml2array($contents, $get_attributes=1) {
if(!$contents) return array();
if(!function_exists('xml_parser_create')) {
//print "'xml_parser_create()' function not found!";
return array();
}
//Get the XML parser of PHP - PHP must have this module for the parser to work
$parser = xml_parser_create();
xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 );
@pezholio
pezholio / check_prs.js
Created April 30, 2020 08:02
PR age checker
const { Octokit } = require("@octokit/rest");
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
})
const repoOwner = process.env.REPOSITORY_OWNER;
const repoName = process.env.REPOSITORY_NAME;
var getOpenPRs = function() {
@pezholio
pezholio / import.rb
Last active January 15, 2020 14:03 — forked from dnagir/import.rb
Regenerate the source of an Octopress blog (if you're an idiot and forgot to commit the source like me)
require 'rubygems'
require 'nokogiri'
require 'fileutils'
require 'date'
require 'uri'
require 'find'
@posts = {}
@drafts = {}
@pezholio
pezholio / 1.rb
Created December 9, 2019 13:59
Advent of Code 2019 - Day 2
file = File.read('input.txt')
memory = file.split(",").map(&:to_i)
finished = false
i = 0
while finished == false do
num = memory[i]
if [1,2].include?(num)
index = i+3
@pezholio
pezholio / 1.rb
Created December 9, 2019 13:57
Advent of Code 2019 - Day 1
file = File.read('input.txt')
answer = file.split("\n").map do |line|
(line.to_i / 3).floor - 2
end.inject(0, :+)
puts answer
@pezholio
pezholio / mapit.js
Last active July 7, 2019 10:53
Getting parliamentary constituencies from MapIt
// This assumes you have node-rest-client (https://www.npmjs.com/package/node-rest-client) installed and available in your NODE_PATH
var Client = require('node-rest-client').Client;
var postcode = 'SW1A1AA'; // Or whatever postcode you're looking for
var uri = 'https://mapit.mysociety.org/postcode/' + postcode;
var getConstituency = function(uri, callback) {
var client = new Client();
client.get(uri, function(data, response) {
constituencyCode = data.shortcuts.WMC;
cache_directory = "/tmp/retroarch"
core_options_path = "/opt/retropie/configs/all/retroarch-core-options.cfg"
system_directory = "~/RetroPie/BIOS"
config_save_on_exit = "false"
video_fullscreen_x = "640"
video_fullscreen_y = "480"
video_threaded = "true"
video_smooth = "false"
video_aspect_ratio_auto = "true"
video_font_size = "12.000000"
@pezholio
pezholio / twfy.js
Last active April 20, 2017 16:06
Getting MP information using TheyWorkForYou
var Client = require('node-rest-client').Client;
var constituency = 'Tamworth'; // Or the name of the constituency you want information for
var apiKey = ''; // Add your API key here
var uri = 'https://www.theyworkforyou.com/api/getMP?constituency='+ constituency +'&output=json&key='+ apiKey;
var getUri = function(uri, callback) {
var client = new Client();
client.get(uri, function(data, response) {
callback(data);
@pezholio
pezholio / say-the-swears.sh
Last active November 3, 2016 15:26 — forked from pikesley/say-the-swears.sh
Swears on a Mac
curl https://peterkwells.github.io/known-uk-swearwords/data/swearwords.csv | tr -s '\015' '\n' | grep -v UID | cut -d ',' -f 1,2 | sed "s:\(.*\),\(.*\):number \1, \2,:" | say