Skip to content

Instantly share code, notes, and snippets.

View virtualstaticvoid's full-sized avatar

Chris Stefano virtualstaticvoid

View GitHub Profile
@virtualstaticvoid
virtualstaticvoid / example_usage.rb
Last active September 24, 2015 14:28
Emulates a C# 'using' statement in Ruby
require 'kernel_using'
class ResourceConsumer
def open()
puts 'Opening up...'
end
def close()
puts 'Closing up...'
@virtualstaticvoid
virtualstaticvoid / dirinbash
Created December 30, 2010 22:09
How to list all subdirectories of a directory in bash
# taken from http://www.daybarr.com/blog/how-to-list-all-subdirectories-of-a-directory-in-bash
To (non-recursively) list all children of a directory in bash
find . -type d -maxdepth 1 -mindepth 1
and to do the same but omitting the .svn directory (subversion's working copy info)
find . -type d -maxdepth 1 -mindepth 1 -not -name .svn
Useful in constructs such as
view sourceprint?
@virtualstaticvoid
virtualstaticvoid / EventFiring.cs
Created May 12, 2009 18:03
Generic event firing in C#
using System;
namespace MyNamespace
{
public static class MyExtensions
{
public static void Fire<TSender, TEventArgs>(this EventHandler<TSender, TEventArgs> myEvent, TSender sender, TEventArgs e)
where T EventArgs: EventArgs
{
if(myEvent != null)
@virtualstaticvoid
virtualstaticvoid / gist:110625
Created May 12, 2009 17:58
AOP via extension method
public static class DelegateExtensions
{
public static Func<T> Before<T>(this Func<T> func, Action before)
{
return () =>
{
before();
return func();
};
}
@virtualstaticvoid
virtualstaticvoid / AttributeSupport.cs
Last active May 31, 2018 10:49
Attribute reflection support
//
// MIT License
// Copyright (c) 2009 Chris Stefano <virtualstaticvoid@gmail.com>
// https://gist.github.com/virtualstaticvoid/105255
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
@virtualstaticvoid
virtualstaticvoid / ControlInvokeSupport.cs
Last active August 17, 2018 11:57
Control Invoke Support
/*
* MIT License
* Copyright (c) 2013 Chris Stefano
* virtualstaticvoid@gmail.com
*/
public static class ControlInvokeSupport
{
public delegate void SafeControlInvokeHandler<TControl>(TControl control)
where TControl : Control;