Skip to content

Instantly share code, notes, and snippets.

private void OnClick(string buttonName) {
switch (buttonName) {
case "System":
case "Range":
ShowChildButtons(buttonName);
pathStack.push(buttonName);
break;
case "Back":
if (pathStack.Count <= 0 {
Hide();
@rgee
rgee / BubbleMenuItem.cs
Created May 20, 2016 21:16
Configuring bubble menu
new HashSet<BubbleMenuItem> {
BubbleMenuItem.Branch("System", 0, new HashSet<BubbleMenuItem> {
BubbleMenuItem.Leaf("Reset", 0),
BubbleMenuItem.Leaf("Suspend", 1),
BubbleMenuItem.Leaf("Options", 2),
BubbleMenuItem.Leaf("Tips", 3)
}),
BubbleMenuItem.Leaf("Tactical", 1),
BubbleMenuItem.Leaf("Units", 2),
BubbleMenuItem.Branch("Range", 3, new HashSet<BubbleMenuItem> {
@rgee
rgee / ContextAdapter.java
Last active January 2, 2016 11:58
Common pattern. You have a stateless object that has methods which all take some sort of "context". You want to reduce boilerplate and argument noise, so you can hide the stateless object and build an adapter class that delegates to the stateless one, but keeps the context as state for reuse. It's dead simple, but I'm writing it down so I don't …
public interface StatelessThing {
public void doThing(Context ctx, Argument1 arg);
}
public class ContextAdapter {
private final Context ctx;
private final StatelessThing thing;
public ContextAdapter(Context ctx, StatelessThing thing) {
this.ctx = ctx;
Y.namespace('Squarespace.Enums').RecordTypes = {
'TEXT': {
value: 1,
title: 'Text',
string: 'text'
}
};
@rgee
rgee / toCharCode.js
Created August 30, 2012 17:19
String.toCharChode For Fun and Profit
/* Converts a string {a} to the following format:
* "eval(String.fromCharCode(a_1, a_2, .... , a_n))"
*where a_n is the Unicode value of the character at index 'n' in a.
*/
var toPayload = function(code) {
var payload = Array.prototype.map.call(code, function(char) {
return char.charCodeAt(0);
});
return "eval(String.fromCharCode(" + payload.join(',') + "));";
@rgee
rgee / gist:3438260
Created August 23, 2012 16:23
Test
test
@rgee
rgee / gist:3363641
Created August 15, 2012 20:58
Lambdasaur
% Ryan Gee
% All Glory to the Hypno-Lamdasaur
% Lamda calculus type inference in prolog
/* Defining operations */
:- op(90, xfx, '->>').
:- op(100, xfx, '::').
:- op(130, xfx, &).
:- op(130, fx, \\).
:- op(120, yfx, '..').
@rgee
rgee / gist:3360315
Created August 15, 2012 13:51
Example of controlling your app without a browser. In an ideal situation, you should be able to instantiate things and update your application state in a node console, for example.
var app = new MyTodo();
app.navigateTo('library');
app.editPage(id);
@rgee
rgee / gist:1313099
Created October 25, 2011 15:20
Comment Logged Out Test
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException, TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
import time
def main():
chrome = webdriver.Chrome()
chrome.get("http://account.dev.squarespace.net/blog/first-post/");
try:
@rgee
rgee / PriQ.js
Created March 4, 2011 16:45
Binary Heap in JS. Not at all tested.
function BinHeap(scoreFunc){
this.data = [];
this.scorer = scoreFunc;
}
BinHeap.prototype = {
push: function(element) {
this.data.push(element);
this.bubbleUp(this.data.length - 1)
},