Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am alexyork on github.
  • I am alexyork (https://keybase.io/alexyork) on keybase.
  • I have a public key whose fingerprint is E0D3 B6F8 49EE 8165 F008 7387 1C81 1BDA 57DA 2B48

To claim this, I am signing this object:

@alexyork
alexyork / gist:1941487
Created February 29, 2012 15:17
The beauty of LINQ lambda's
var names = new[] { "Bill", "Bill", "Bob", "Mary", "Bartholomew", "Shane", "Elisabeth", "Dave", "Bartholomew" };
var query = names.Distinct()
.Where(n => n.Length > 6)
.OrderByDescending(n => n)
.ToArray();
// result: { "Elisabeth", "Bartholomew" }
@alexyork
alexyork / gist:1940750
Created February 29, 2012 13:12
Using LINQ to flatten a data structure v Old-Skool C# code
private static void FlattenData()
{
var dictionary = new Dictionary<string, string[]> {
{ "Foo", new [] { "foo-1", "foo-2" }},
{ "Bar", new [] { "bar-1", "bar-2" }}
};
IEnumerable<string> flattenedData;
// Using LINQ
@alexyork
alexyork / gist:1405081
Created November 29, 2011 14:58
Running code in Parallel in C#
// Running code in Parallel in C#
// Sequential
DoSomething();
DoSomethingElse();
DoAnotherThing();
// Parallel
Parallel.Invoke(
DoSomething,
@alexyork
alexyork / gist:1333011
Created November 2, 2011 06:07
MonoTouch Twitter Bug
// Error:
// Wrapper type 'MonoTouch.Twitter.TWTweetComposeViewController' is missing its native ObjectiveC class 'TWTweetComposeViewController'. Please check if it's been linked.
// Other Info:
// - I am targetting v 5.0
// - I have tried switching linking on and off, to no avail
// - I have the latest MonoTouch installed
// My code:
@alexyork
alexyork / gist:1237529
Created September 23, 2011 14:43
A HTML nesting problem.
// Before:
<script>
$("td .foo input").whatever(); // worked fine
</script>
<html>
<table><!-- "legacy" HTML where <table> is used for layout/columns -->
<tr>
<td>
@alexyork
alexyork / gist:1098344
Created July 21, 2011 22:02
Compiler directives v IoC
// With compiler directives
public class SpaceInvadersGame
{
private Vector2 screenRes;
public SpaceInvadersGame()
{
#if WINDOWS_PHONE
screenRes = new Vector2(800,480);
@alexyork
alexyork / TableCellFactory.cs
Created July 19, 2011 06:12
Custom UITableViewCell's with a TableCellFactory in MonoTouch
using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.ObjCRuntime;
namespace CustomTableCellApp
{
public class TableCellFactory<T> where T : UITableViewCell
@alexyork
alexyork / HTTP handler
Created May 19, 2011 19:34
A very simple HTTP handler in .NET that returns JSON
using System;
using System.Web;
public class MyJsonHttpHandler : IHttpHandler
{
public bool IsReusable
{
get { return false; }
}
prepareSnacks({
'biscuits': "Hobnobs",
'crisps': "Quavers",
'peanuts': "Lots and lots!",
'olives': "The ones with feta cheese inside",
// etc etc
});