Skip to content

Instantly share code, notes, and snippets.

func calculateHouses(in string) int {
v := map[int]int{0: 1}
z := map[rune]int{'<': -1, '>': 1, '^': 99, 'v': -99}
x := 0
for _, a := range in {
x += z[a]
v[x] = 1
}
@SneakyBrian
SneakyBrian / CAPTCHA.js
Created March 20, 2013 22:47
Implementing CAPTCHA client-side using HTML5 canvas
(function (window, document, $, undefined) {
var possibleCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var defaults = {
selector: "#captcha",
text: null,
randomText: true,
randomColours: true,
@SneakyBrian
SneakyBrian / Client.cs
Created October 9, 2012 22:13
ZeroMQ MsgPack .NET Testbed
using System;
using System.IO;
using MsgPack.Serialization;
using ZeroMQ_MessagePack_Testbed.Models;
using ZMQ;
namespace ZeroMQ_MessagePack_Testbed
{
class Program
{
@SneakyBrian
SneakyBrian / jqueryRequestIndicator.js
Created October 5, 2012 20:26
Add an ajax request indicator to a page in a fixed position for debug purposes
$(function () {
//add a requesting indicator to the page
$(document.body).append(
$('<div id="requesting" />').css({
top: '0px',
right: '0px',
height: '5px',
width: '5px',
'background-color': 'gray',
@SneakyBrian
SneakyBrian / Program.cs
Created October 5, 2012 20:09
XML2JSON command line tool, uses JSON.NET. Usage: XML2JSON.exe input.xml output.json
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;
using Newtonsoft.Json;
using Formatting = Newtonsoft.Json.Formatting;
namespace XML2JSON
{
class Program
@SneakyBrian
SneakyBrian / GetDynamicFromXml.cs
Created October 5, 2012 17:34
Get A Dynamic Object from an xml file
private static dynamic GetDynamicFromXml(string pathToXml)
{
var xdoc = XDocument.Load(pathToXml);
return GetDynamicFromNode(xdoc.Root);
}
private static dynamic GetDynamicFromNode(XElement node)
{
dynamic result = new ExpandoObject();
@SneakyBrian
SneakyBrian / window.query.js
Created October 5, 2012 17:17
Get Query String for current page as object
(function (window) {
//declare the variables here,
//as js variable hoisting will do this
//here anyway
var m, queryString, re;
//if the window query object does not exist
if (!window.query) {