Skip to content

Instantly share code, notes, and snippets.

View gabehesse's full-sized avatar

Gabe Hesse gabehesse

View GitHub Profile
@gabehesse
gabehesse / useScroll.js
Last active July 1, 2019 15:11 — forked from joshuacerbito/useScroll.js
Custom React hook for listening to scroll events
/**
* useScroll React custom hook
* Usage:
* const { x, y, direction } = useScroll();
*/
import { useState, useEffect } from "react";
export default function useScroll() {
if(!process.browser) return {x: null, y: null, direction: null}
@gabehesse
gabehesse / EnumLabel.cs
Created June 1, 2011 16:53
C# attribute that allows string representation of enum members & an extension method to get that string representation from an enum member.
public class EnumLabelAttribute : Attribute
{
public string Label { get; private set; }
public EnumLabelAttribute(string label) { Label = label; }
}
public static class EnumLabelExtension
{
public static string GetLabel(this Enum @enum)
{
@gabehesse
gabehesse / StatusBar.cs
Created May 16, 2011 21:59
Status bar in C# console application
/// <summary>
/// Draw a progress bar at the current cursor position.
/// Be careful not to Console.WriteLine or anything whilst using this to show progress!
/// </summary>
/// <param name="progress">The position of the bar</param>
/// <param name="total">The amount it counts</param>
private static void drawTextProgressBar(int progress, int total)
{
//draw empty progress bar
Console.CursorLeft = 0;
@gabehesse
gabehesse / powerset.cs
Created May 2, 2011 22:46
Power set P(S) in C#
var list = new List<char> { 'A', 'B', 'C' };
var result = new List<List<char>> ();
for (int i = 0; i < (1 << list.Count); i++) { // 1 << n == the n-th power of 2
var sublist = new List<char> ();
for (int j = 0; j < list.Count; j++) { // analyze each bit in "i"
if ((i & (1 << j)) != 0) { // if the j-th bit of i is set...
sublist.Add (list [j]); // add the item to the current sublist
}
}
@gabehesse
gabehesse / gist:870932
Created March 15, 2011 16:00
Get the MSMQ messageid of the current operation when using WCF netmsmqbinding
MsmqMessageProperty msmqMessageProperty = (MsmqMessageProperty)OperationContext.Current.IncomingMessageProperties[MsmqMessageProperty.Name];
Type myType = typeof(MsmqMessageProperty);
PropertyInfo myPropInfo2 = myType.GetProperty("MessageId", BindingFlags.NonPublic | BindingFlags.Instance);
Console.WriteLine("Received message with MessageId: {0}", (string)myPropInfo2.GetValue(msmqMessageProperty, null));