Skip to content

Instantly share code, notes, and snippets.

View cstrahan's full-sized avatar

Charles Strahan cstrahan

  • Fullstory
  • Dallas, TX
View GitHub Profile
This is a test gist...
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
public class ResourceInspector
{
object stringUtil = new ExpandoObject();
// The CallSite that will handle setting the ToUpper member on stringUtil
var set_ToUpper_callSite = CallSite<Func<CallSite, object, Func<string, string>, object>>.Create(
Binder.SetMember(CSharpBinderFlags.None, "ToUpper", typeof(Program),
new[]
{
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null)
}));
// Languages\Ruby\Ruby\Builtins\RubyEncoding.cs
public static RubyEncoding/*!*/ GetRubyEncoding(Encoding/*!*/ encoding) {
ContractUtils.RequiresNotNull(encoding, "encoding");
if (encoding == BinaryEncoding.Instance) {
return Binary;
} else if (encoding.ToString() == Encoding.UTF8.ToString()) {
return UTF8;
} else {
throw new ArgumentException(String.Format("Unknown encoding: '{0}'", encoding));
}
/*
Here's an example of how to get info for a given COM type library.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
@cstrahan
cstrahan / FirewallHelper.cs
Created August 8, 2010 09:09
C# Firewall helper
///
/// Allows basic access to the windows firewall API.
/// This can be used to add an exception to the windows firewall
/// exceptions list, so that our programs can continue to run merrily
/// even when nasty windows firewall is running.
///
/// Please note: It is not enforced here, but it might be a good idea
/// to actually prompt the user before messing with their firewall settings,
/// just as a matter of politeness.
///
@cstrahan
cstrahan / Example.cs
Created August 18, 2010 22:16
Unindent for C#
class Foo {
static void Bar() {
// The following strings are identical, but the first is prettier.
string baz = @"
Here's some text that will
be unindented here
in a little while".Unindent();
string sameAsBaz =
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class DateTimeElapsedEventArgs : EventArgs
{
public DateTime DateTime { get; private set; }
public DateTimeElapsedEventArgs(DateTime dateTime)
{
@cstrahan
cstrahan / Showdown.as
Created October 27, 2010 10:04
Showdown.as: An AS3 port of John Fraser's showdown.js
// UPDATE: For latest code, see https://github.com/cstrahan/Showdown.as
//
// Showdown.as -- An ActionScript port of showdown.js
//
// Copyright (c) 2010 Charles Strahan.
//
// Original Showdown Copyright (c) 2007 John Fraser.
// <http://attacklab.net/showdown/>
//
// Original Markdown Copyright (c) 2004-2005 John Gruber
@cstrahan
cstrahan / gist:648799
Created October 27, 2010 10:36
AS3 alert function.
// Just for future reference,
// here's a quick way to interface with the browser's Javascript `alert' function.
import flash.external.ExternalInterface;
private function alert(text:String):void
{
text = text.replace(/\\/g, "\\\\");
ExternalInterface.call("alert", text);
}