Skip to content

Instantly share code, notes, and snippets.

View aseemgautam's full-sized avatar
👋
Hi!

Aseem Gautam aseemgautam

👋
Hi!
View GitHub Profile
@aseemgautam
aseemgautam / node-fibers-simple.js
Last active April 21, 2016 12:28
NodeJS Fibers Example
var Fiber = require('fibers');
var decrement = function(input) {
var fiber = Fiber.current;
setTimeout(function () {
console.log('decrement');
fiber.run(--input);
}, 1000);
@aseemgautam
aseemgautam / util.js
Created November 25, 2015 16:42
Javascript Utility Class - Reusable Functions
/* USE WITH NAMESPACING */
/* javascript reusable functions */
var lib = {
/* add <option> for each item in json object */
/* json should be key value pair type */
/* var obj = {
"flammable": "inflammable",
"duh": "no duh"
};
*/
/// <summary>
/// Utilties for reflection
/// </summary>
public static class ReflectionUtils
{
/// <summary>
/// Get all the fields of a class
/// </summary>
/// <param name="type">Type object of that class</param>
/// <returns></returns>
@aseemgautam
aseemgautam / IconHelper.cs
Created January 16, 2014 06:36
Helper Class for Icon operations.
/// <summary>
/// Helpful methods to handle the <see cref="System.Drawing.Icon"/> stuff.
/// </summary>
public class IconHelper : IDisposable
{
[DllImport("user32.dll", SetLastError = true)]
static extern int DestroyIcon(IntPtr hIcon);
[DllImport("gdi32.dll")]
static extern bool DeleteObject(IntPtr hObject);
@aseemgautam
aseemgautam / XtraBarsUtils.cs
Created December 20, 2013 06:59
Reusable code related to XtraBars component of Developer Express winform suite.
/// <summary>
/// Use this method to enable/disable all items in a ribbon page.
/// </summary>
public static void ChangeRibbonPageItemsEnabledState(RibbonPage page, bool enabled)
{
foreach (RibbonPageGroup rpg in page.Collection) {
foreach (BarItemLink itemLink in rpg.ItemLinks)
{
itemLink.Item.Enabled = enabled;
}
@aseemgautam
aseemgautam / Safe Invokes
Created March 19, 2013 07:25
General Winforms
protected void SafeBeginInvoke(Delegate method)
{
if (IsDisposed || Disposing) return;
if (IsHandleCreated)
{
BeginInvoke(method);
}
}
protected void SafeInvoke(Delegate method)
@aseemgautam
aseemgautam / EventArgs.cs
Last active December 13, 2015 17:08
C# 2.0 Generic Utilities 1. EventArgs 2. NameValuePair
public class EventArgs<T> : EventArgs
{
public EventArgs(T value)
{
this.value = value;
}
private readonly T value;
public T Value
@aseemgautam
aseemgautam / Async.cs
Created February 13, 2013 10:05
C# 2.0 Asynchronous Action and Callback Library.
internal class Async
{
//Action = for void methods.
public delegate void Action();
public delegate void Action<T>(T t);
public delegate void Action<T, U>(T t, U u);
public delegate void Action<T, U, V>(T t, U u, V v);
//Func = for methods with some return type.
public delegate TResult Func<TResult>();
@aseemgautam
aseemgautam / FireEvent.cs
Last active December 13, 2015 16:49
C# Event Handling
/// <summary>
/// Fires the specified event, and passes the input as a parameter.
/// </summary>
/// <typeparam name="T">Type of the input parameter.</typeparam>
/// <param name="eventToFire">The event to fire.</param>
/// <param name="sender">Object that triggered this event </param>
/// <param name="input">Typeof EventArgsThe input.</param>
/// <param name="eventName">Name of the event. Needed for error logging. </param>
internal static void FireEvent<T>(Delegate eventToFire, object sender, T input, string eventName)
{