This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |