Skip to content

Instantly share code, notes, and snippets.

@JoeRobich
JoeRobich / HipChatAppendFix.js
Created July 24, 2014 16:29
This is a GreaseMonkey script that fixes HipChat's annoying behavior of breaking up multiple consecutive chats into different chat blocks.
// ==UserScript==
// @name       HipChat append fix
// @namespace  http://joeyrobichaud.com/
// @version    0.1
// @description  Sending multiple messages in a row will create multiple chat blocks even though you are the sender of each of them. this fixes that.
// @match      https://*.hipchat.com/chat
// @copyright  2014+, Joey Robichaud
// ==/UserScript==
window.addEventListener("load", function(e) {
@JoeRobich
JoeRobich / Func.cs
Created June 20, 2014 19:35
Methods that allow partial application of arguments to a function.
public class Func
{
//Two Params
public static Func<T2, TR> Apply<T1, T2, TR>(Func<T1, T2, TR> func, T1 arg1)
{
return (arg2) => func(arg1, arg2);
}
//Three Params
public static Func<T2, T3, TR> Apply<T1, T2, T3, TR>(Func<T1, T2, T3, TR> func, T1 arg1)
@JoeRobich
JoeRobich / UITask.cs
Last active August 29, 2015 14:01
Class to simplify running tasks on the UI thread.
using System;
using System.Threading.Tasks;
using Windows.ApplicationModel.Core;
using Windows.UI.Core;
namespace TheDevStop.Mobile.Framework
{
public class UITask
{
static readonly CoreDispatcher _dispatcher;
@JoeRobich
JoeRobich / CsGuard.cs
Created March 13, 2014 14:03
Port of AsGuard to C#.
using System;
using System.Collections.Generic;
namespace TheDevStop.CsGuard
{
public class Contracts
{
public enum Kind
{
PreCondition,
@JoeRobich
JoeRobich / isNullOrEmpty.as
Created November 12, 2013 19:28
An API I was calling into was returning empty objects in addition to null. I made this helper function to simplify the handling logic.
public static function isNullOrEmpty(object:Object):Boolean
{
if (!object)
return true;
if (object is Array ||
object is IList)
return !object.length;
for (var key:String in object)
@JoeRobich
JoeRobich / CSVReader.as
Last active December 25, 2015 03:29
Asynchronous CSV Reader. Reads CSV file into an array of record objects. If header row exists then objects will have properties named after the headers, otherwise it will generate header names (ex. "A", "B",...,"AA","BB",...). Conforms to RFC4180 (http://tools.ietf.org/html/rfc4180) except that the separator character is now configurable.
package com.thedevstop
{
import flash.events.ErrorEvent;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.utils.setTimeout;
[Event(name="complete", type="flash.events.Event")]
[Event(name="error", type="flash.events.ErrorEvent")]
public class CSVReader extends EventDispatcher
@JoeRobich
JoeRobich / Program.cs
Created July 11, 2013 20:32
Use Linq expressions to test for `null`s in chained member access. For instance `ValidateNotNull(() => person.Address.State);` would return false if `person`, `person.Address`, or `person.Address.State` were `null`.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace TestNullCheckingExpressions
{
class Program
@JoeRobich
JoeRobich / ConfidenceStore.cs
Last active December 16, 2015 07:38
Helpful utility for tracking which item in a group occurs at high enough of a frequency to call the confident item.
public class ConfidenceStore<T> where T : class
{
public event EventHandler<EventArgs<T>> Changed;
private Queue<T> queue;
private int length;
private int threshold;
private T confidentItem;
public ConfidenceStore(int length, int threshold)
@JoeRobich
JoeRobich / json.pegjs
Created April 5, 2013 20:12
Simple incomplete JSON parser written in pegjs
{
function createObject(kvps) {
var object = {};
for (var index = 0; index < kvps.length; index++) {
var value = kvps[index].value;
value = value == undefined ? null : value;
object[kvps[index].key] = value;
}
return object;
}
@JoeRobich
JoeRobich / Program.cs
Created February 4, 2013 22:40
Developer interview problem
void Main()
{
var unsortedNames = GetNames();
var sortedNames = SortNames(unsortedNames);
PrintArray(sortedNames);
}
// Formats and sorts an array of name strings.
// Input: An unordered array of strings in the format '{LastName}, {FirstName}'
// Output: An ordered array of strings in the format '{FirstName} {LastName}'