Skip to content

Instantly share code, notes, and snippets.

View NigelThorne's full-sized avatar

Nigel Thorne NigelThorne

View GitHub Profile
Sub InsertLotsOfFiles()
'
' InsertLotsOfFiles Macro
' Macro written 21/09/2009 by Nigel Thorne
'
Dim No_Of_Files As Integer
Dim kk25 As Integer
Dim File_Path As String
File_Path = "..." 'change this to the path you want to use.
#Taken from http://coderrr.wordpress.com/2008/04/22/building-the-right-class-with-sti-in-rails/
class GenericClass < ActiveRecord::Base
class << self
def new_with_cast(*a, &b)
if (h = a.first).is_a? Hash and (type = h[:type] || h['type']) and (klass = type.constantize) != self
raise "wtF hax!!" unless klass < self # klass should be a descendant of us
return klass.new(*a, &b)
end
class Game(rolls: List[Int]) {
def score:Int = score(rolls, 10)
private def score(rolls:List[Int], index:Int):Int = {
if (index == 0) return 0
rolls match {
case 10 :: second :: third :: rest
=> 10 + second + third + score(second :: third :: rest, index-1)
case first :: second :: third :: rest if first + second == 10
=> 10 + third + score(third :: rest, index-1)
@NigelThorne
NigelThorne / fromRoman.js
Created January 7, 2011 13:19
Novel solution to the 'Convert Roman Numerals to Integers' kata...
String.prototype.fromRoman = function() {
maps = new Object();
maps["I"] = 1;
maps["V"] = 5;
maps["X"] = 10;
maps["L"] = 50;
maps["C"] = 100;
maps["D"] = 500;
maps["M"] = 1000;
@NigelThorne
NigelThorne / beautify.rb
Created July 3, 2011 23:24
A simple script to beautify a PGSQL file. (Also an AutoHotKey script to beautify the currently selected text)
# Please fork this and make it better :)
#
# A valid solution follows these rules:
# 1 - The output should be the same sql as the input with different whitespace.
# 2 - Running the script on a file that is already beautified should do nothing.
sql = File.read(ARGV[0])
clean = sql.
gsub(/\t/, " ").
@NigelThorne
NigelThorne / resize.js
Created July 15, 2011 07:01
Resize fonts on a webpage to make things visible from a distance.
// Mark things you want to resize with class="resizeable"
// The ratio between their sizes will be maintained.
// works with jquery-1.4.2.min.js
//
// <script src=".../jquery-1.4.2.min.js"></script>
// <script src=".../resize.js"></script>
//
function resizeNodes(nodes, startsizes, multiplier){
@NigelThorne
NigelThorne / CSVParser.cs
Created October 3, 2011 00:54
I can't find a CSVParser that escapes strings correctly... so here is something that does what I need. Feel free to fork and improve.
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
namespace NigelThorne
{
public class CSVParser
{
@NigelThorne
NigelThorne / json_parser.rb
Last active September 28, 2015 05:37
JSON Parser
require 'rubygems'
require 'parslet'
#This needs a few more 'as' calls to annotate the output
class JSONParser < Parslet::Parser
rule(:space) { match('[\s\n]').repeat(1)}
rule(:space?) { space.maybe }
rule(:digit) { match('[0-9]') }
rule(:hexdigit) { match('[0-9a-fA-F]') }
rule(:comma) { space? >> str(',') >> space? }
@NigelThorne
NigelThorne / svn_log_to_csv.rb
Created November 29, 2011 02:31
SVN log to CSV ["Revision","Author","Date","Message","Jira Issues Mentioned..."]
# Report SVN logs for a revision span as a csv for analysis in excel.
# By Nigel Thorne (nwt) www.nigelthorne.com
require 'nokogiri'
repo = ARGV[0] || "http://.../trunk" # repository location
from = ARGV[1] || "1111" # from revision
to = ARGV[2] || "2222" # to revision
xml_changes = Nokogiri::XML(`svn.exe log #{repo} -r#{from}:#{to} --xml`)
@NigelThorne
NigelThorne / worst_code.rb
Created November 29, 2011 02:48
Report On the Worst code in your codebase (for some definition of worst) as reported by Team City and NCover
# Report On the Worst code in your codebase (for some definition of worst) as reported by Team City and NCover
# *******This works for us.. may need editing to work for you!********
# By Nigel Thorne (nwt) www.nigelthorne.com
# https://gist.github.com/gists/1403141
#install :
# once ruby is installed...
# and in your path
# gem install nokogiri
# gem install mechanize