Skip to content

Instantly share code, notes, and snippets.

View NigelThorne's full-sized avatar

Nigel Thorne NigelThorne

View GitHub Profile
require 'parslet'
class Parslet::Atoms::FixedLength < Parslet::Atoms::Base
attr_reader :len, :parslet
def initialize(parslet, len, tag=:length)
super()
raise ArgumentError,
"Asking for zero length of a parslet. (#{parslet.inspect} length #{len})" \
if len == 0
@NigelThorne
NigelThorne / example.rb
Last active August 29, 2015 13:57
Parslet example of transforms with default values
require 'pp'
require 'parslet'
module Example # as in 'lots of insipid and stupid parenthesis'
class Parser < Parslet::Parser
rule(:ws) { match('[\s]').repeat(1) }
rule(:ws?) { ws.maybe }
rule(:number) { match('[0-9]').repeat(1) }
rule(:offset) { ws? >> str("[") >> number.as(:offset) >> str("]") }
@NigelThorne
NigelThorne / activeWindowHighlight.ahk
Created March 13, 2014 22:36
Highlight the active window
#Persistent
SetTitleMatchMode, 2
SetTitleMatchMode, Fast
SetTimer, DrawRect, 50
border_thickness = 5
Table_String = Table
DrawRect:
WinGetTitle, title, A
@NigelThorne
NigelThorne / MoqExtension.cs
Created April 29, 2014 22:17
Extension to Moq to allow you to write: Mock.Get(obj).VerifyNoMethodsAreCalled();
public static class MoqExtensions
{
/// <summary>
/// LINQ + Reflection + Moq = MAGIC!!!
/// Calls Mock.Get(obj).Verify(x => x.MethodY(It.IsAny<Z>,...), Times.Never) for all methods
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="mock">mock object you want to assert on</param>
public static void VerifyNoMethodsAreCalled<T>(this Mock<T> mock) where T : class
{
@NigelThorne
NigelThorne / np.bat
Created May 1, 2014 12:25
run notepad++ batch file
@start "Edit" /B "c:\Program Files (x86)\Notepad++\notepad++.exe" %*
@NigelThorne
NigelThorne / example
Created May 12, 2014 10:53
iptables_save output parser... not complete.. just helping someone out.
# Generated by iptables-save v1.4.7 on Sun Feb 24 00:48:11 2013
*mangle
:PREROUTING ACCEPT [756:54757]
:INPUT ACCEPT [756:54757]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [578:527896]
:POSTROUTING ACCEPT [578:527896]
-A INPUT -s 1.1.1.2/32 -j CHECKSUM --checksum-fill
-A OUTPUT -s 1.1.1.2/32 -j CLASSIFY --set-class 0004:0056
COMMIT
@NigelThorne
NigelThorne / CustomRules.js
Last active August 29, 2015 14:02
FiddlerScript Rules file to stop ads on Plus7
import System;
import System.Windows.Forms;
import Fiddler;
// INTRODUCTION
// This is the FiddlerScript Rules file, which creates some of the menu commands and
// other features of Fiddler. You can edit this file to modify or add new commands.
//
// The original version of this file is named SampleRules.js and it is in the
// \Program Files\Fiddler\ folder. When Fiddler first starts, it creates a copy named
@NigelThorne
NigelThorne / readme
Last active August 29, 2015 14:02
Git workflow using Stash
I added an alias to my git aliases in my .gitconfig
review-me = !sh -c 'cmd.exe /c \"@e:\\bin\\send_for_review.bat\"'
so I can type 'git review-me'
@NigelThorne
NigelThorne / kill_IE_WhenHung.bat
Created July 3, 2014 02:36
Powershell script to kill IE when it hangs (used in automation testing)
@powershell -NoProfile -ExecutionPolicy unrestricted .\Kill_IE_WhenHung.ps1
@NigelThorne
NigelThorne / app.rb
Created September 5, 2014 01:04
Sinatra app wrapping QC library call to reorder test in a test_set. (Using Slim and streaming)
require 'sinatra'
require 'slim'
require './reorder_tests_in_test_lab'
require 'pit'
set :bind, '0.0.0.0'
set :slim, :pretty => true
@@config = Pit.get("qc", :require => {
"username" => "qc_user",