Here’s a useful enhancement to arrays that allows you to process elements in a block n at a time. N is inferred by the arity of your block signature. Namaste…
Category Archives: Uncategorized
Sleek CLI wrappers around Ruby libs
When using Ruby’s splat operator for method invocation, eg. my_method(*my_array), it takes the array and blows it out into the parameters required to fill the method’s signature. This makes it super easy to call methods from classes via the command line, by simply passing the arguments (ARGV) to a Ruby command line app and thenContinue reading “Sleek CLI wrappers around Ruby libs”
Creating a “Supernatural” Self-Adapting REST Proxy in C#
.NET 4.0’s DynamicObject provides a quick and easy way to hook into and control how a call for a method is dispatched at runtime. This so called “late dispatch” capability is exactly what we need to easily create dynamic facades over out-of-process APIs, such as those of remote REST services. In this post, I’ll showContinue reading “Creating a “Supernatural” Self-Adapting REST Proxy in C#”
Giving Your Data Some Higher Order Muscle With C#
Today a colleague and I were going through some code. I have recently been trying to impart to him the power and beauty in the functional programing paradigm in C#. Today, the opportunity to demonstrate it presented itself as I was showing him how to use extension methods to extend Entities and ValueObjects with aContinue reading “Giving Your Data Some Higher Order Muscle With C#”
Ruby AOP in 12 lines of Code
First, we shim the Ruby Object class with a profiling aspect, in this case an additional method called profile that will wrap any existing method with timing code that we tell it to. Lets put this in a file called: aop_extension.rb. class Object def Object.profile symbol _symbol = (“rprof_” + symbol.to_s).to_sym alias_methodContinue reading “Ruby AOP in 12 lines of Code”
Property getter/setter extraction from C# Types
The C# Expression API allows you to scrape property and method definitions from Types and work with them as external references. See here: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using System.Dynamic; using System.Runtime.CompilerServices; public static class Extensions { public static Func<X, T> GetPropertyFunction<X, T>(this Type source, string name) { ParameterExpression param = Expression.Parameter(typeof(X), “arg”); MemberExpressionContinue reading “Property getter/setter extraction from C# Types”
My C# ObservableDictionary
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.ComponentModel;using System.Collections.Specialized; namespace DynamicSpikes{ public class ObservableDictionary<String, Object> : Dictionary<string, object>, INotifyPropertyChanged, INotifyCollectionChanged { public event PropertyChangedEventHandler PropertyChanged = delegate { }; public event NotifyCollectionChangedEventHandler CollectionChanged = delegate { }; private void OnCollectionChanged(object sender, NotifyCollectionChangedAction action, object value) { if (CollectionChanged != null) { CollectionChanged(sender, new NotifyCollectionChangedEventArgs(action, value)); } } private void OnPropertyChanged(object sender, string propertyName) Continue reading “My C# ObservableDictionary”
Runtime Stack Introspection with C#
public static string WhoCalledMe() { var st = new StackTrace(); var sf = st.GetFrame(1); var mb = sf.GetMethod(); return mb.Name; }
Webshims – HTML5 For The Masses
I’ve been researching the available shimming libaries out there that provide old browsers with modern features. The Webshims library does this in an efficient and unobtrusive way, always defering to the browser’s built in feature if it exists natively. With 2 lines of code you tell it where to find its shim scripts and then toContinue reading “Webshims – HTML5 For The Masses”
Metaprogramming in Ruby and C#
First read this and understand metaprogramming in Ruby: http://www.devsource.com/c/a/Languages/An-Exercise-in-Metaprogramming-with-Ruby/ It seems that C# dynamic supports a similar scenario, but in a different way. C# dynamic objects are in fact not new Types created at runtime, but rather individual compiler-safe bags of key/value pairs that self expose the keys as properties. Thus C# dynamic objects areContinue reading “Metaprogramming in Ruby and C#”