Skip to content

Instantly share code, notes, and snippets.

View virtualstaticvoid's full-sized avatar

Chris Stefano virtualstaticvoid

View GitHub Profile
@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;
@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 / 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 / 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 / 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 / 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 / XPathHelp.cs
Created January 24, 2011 09:55
Utility for determining the XPath of a given node
using System;
using System.Text;
using System.Xml;
using System.Xml.XPath;
public static class XPathHelp
{
public static string GetXPathForNode(XmlNode node)
{
@virtualstaticvoid
virtualstaticvoid / git-checkout-branch.sh
Created February 23, 2011 20:10
Checkout single Git branch
#!/bin/bash
#
# Creates a Git repository, fetches and checks out a single branch from the remote repository
#
url=$1
branch=$2
git init
@virtualstaticvoid
virtualstaticvoid / fbr.rb
Created February 28, 2011 17:07 — forked from tmm1/fbr.rb
Poor Man's Fiber
# Poor Man's Fiber (API compatible Thread based Fiber implementation for Ruby 1.8)
# (c) 2008 Aman Gupta (tmm1)
unless defined? Fiber
require 'thread'
class FiberError < StandardError; end
class Fiber
def initialize
@virtualstaticvoid
virtualstaticvoid / testing.rb
Created March 10, 2011 15:56 — forked from anonymous/testing.rb
ruote usage example
require 'rubygems'
require 'ruote'
engine = Ruote::Engine.new(Ruote::Worker.new(Ruote::HashStorage.new))
engine.register do
catchall Ruote::StorageParticipant
end