Skip to content

Instantly share code, notes, and snippets.

View NigelThorne's full-sized avatar

Nigel Thorne NigelThorne

View GitHub Profile
@NigelThorne
NigelThorne / ebnf_parser.rb
Created July 16, 2015 14:17
EBNF parser written in parslet: Note I added ':' as an end of definition character. I could have used (eol >> eol)
require 'parslet'
require 'ostruct'
require 'pp'
class BaseParser < Parslet::Parser
def no(p);(p.absent? >> any);end
def join(p,q);(p >> (q >> p).repeat(0));end
def self.tokens(toks)
toks.map do |t,r|
key=t.to_s
@NigelThorne
NigelThorne / base_parser.rb
Created July 15, 2015 13:14
Base class for Parslet Parsers
require 'parslet'
class BaseParser < Parslet::Parser
def no(p);(p.absent? >> any);end
def join(p,q);(p >> (q >> p).repeat(0));end
def self.tokens(toks)
toks.map do |t,r|
key=t.to_s
rule((key).to_sym){r.is_a?(String) ? str(r) : match(r)}
rule((key+"!").to_sym){no(r.is_a?(String) ? str(r) : match(r))}
@NigelThorne
NigelThorne / nsubl.bat
Created June 24, 2015 03:10
Use sublime text with 7zip
"%~dp0subl.exe" -n -w %1
@NigelThorne
NigelThorne / Contexts.cs
Created June 24, 2015 00:29
An alternative mechanism for passing context to SpecFor
public static class ABus
{
// can be a simple method
public static void that_works(ISpecs<Config.Backend.Iguana.Services.IguanaResourceService> state)
{
state.SUT.Bus = state.GetMockFor<IBus>().Object;
}
}
public static class AMapper
choco install sublimetext3 -y
choco install putty -y
#choco install kitty.portable -y
choco install console2 -y
choco install autohotkey -y
choco install negativescreen -y
# These need running as admin
choco install gajim -y
choco install winsplitrevolution -y
@NigelThorne
NigelThorne / invertbackground.rb
Last active August 29, 2015 14:21
Invert background image in Windows
#ruby
wallpaper = `reg QUERY "HKCU\\Control Panel\\Desktop" /v Wallpaper`.split(/REG_SZ\s*/)[1].chomp.strip
dot_index = wallpaper.rindex(".")
if /_inv\./ =~ wallpaper
inv_filename = wallpaper.gsub("_inv","")
else
inv_filename = "#{wallpaper[0...dot_index]}_inv.jpg"
end
@NigelThorne
NigelThorne / webservices.vba
Last active January 3, 2016 17:31
Download json from web service and push onto excel sheet
' Add references in Excel
' * Microsoft XML, v6.0
' * Microsoft Script Control 1.0
Option Explicit
Private ScriptEngine As ScriptControl
Public Function GetWebSource(ByRef URL As String) As String
Dim xml As IXMLHTTPRequest

Sample service script for debianoids

Look at LSB init scripts for more information.

Usage

Copy to /etc/init.d:

# replace "$YOUR_SERVICE_NAME" with your service's name (whenever it's not enough obvious)
@NigelThorne
NigelThorne / gist:9261ccacaebcfc645123
Last active August 29, 2015 14:10
How ruby should work
#class URLSource( url )
# def read
# open(@url).read
# end
#end
# or maybe we could implement
def klass(*args, &block)
Class.new(Object).tap{ |c|
@NigelThorne
NigelThorne / transformer.rb
Created November 14, 2014 06:02
Transformer for post processing Nokogiri Node trees. Following the style of Parslet::Transformer class.
class Transformer
def initialize()
@rules = []
end
def rule(*conditions, &block)
@rules.push( Rule.new( Filter.new(conditions), block ) )
end
def simple(sym_name) # matches any object not array not hash