Skip to content

Instantly share code, notes, and snippets.

View lobrien's full-sized avatar
💭
About 7,000 miles away from lounge access.

Larry O'Brien lobrien

💭
About 7,000 miles away from lounge access.
View GitHub Profile
public abstract class Hole
{
public static readonly float LineWidth = 2f;
protected Hole(int radius)
{
Radius = radius;
}
public PointF Point { get; set; }
@lobrien
lobrien / gist:03976449701dca45dbae
Last active August 29, 2015 14:13
Extension method on Enum
using System;
enum Direction { N, S, E, W}
static class X {
public static double NominalDirectionInRadians(this Direction d)
{
var idx = (int)d;
var directionCount = Enum.GetNames (typeof(Direction)).Length;
var pct = (double) idx / directionCount;
### Keybase proof
I hereby claim:
* I am lobrien on github.
* I am lobrien (https://keybase.io/lobrien) on keybase.
* I have a public key whose fingerprint is E928 7FF1 AD56 4639 010F 50D2 A95D 15EA EBBE D5BD
To claim this, I am signing this object:
string output = "";
bool reset = false;
int input = 15;
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Perform any additional setup after loading the view, typically from a nib.
/*
@lobrien
lobrien / gist:5250556
Created March 27, 2013 00:24
Video Capture in MonoTouch
using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System.Drawing;
using MonoTouch.CoreGraphics;
using MonoTouch.CoreAnimation;
using MonoTouch.AVFoundation;
@lobrien
lobrien / gist:5971032
Last active December 19, 2015 14:39
Simple convolution filter: First convert byte[,] to double[,] using .ToRangePlusOrMinusOne() and then use Convolve3x3(). Then convert back to byte[,] using ToBytes()
public static double[,] ToRangePlusOrMinusOne(this byte[,] self)
{
var ySize = self.GetLength(1);
var xSize = self.GetLength(0);
var dArr = new double[ySize, xSize];
for(var y = 0; y < ySize; y++)
{
for(var x = 0; x < xSize; x++)
{
@lobrien
lobrien / gist:6147243
Last active December 20, 2015 14:29
Shows a race condition in MapKit. You cannot rely on the map.CenterCoordinate in synchronous code, and it's not clear to me what event (if any) is associated with the `UIMapView.CenterCoordinate` becoming set.
var map = new MKMapView();
var ctr = new CLLocationCoordinate2D(37.8, -122.4);
map.SetCenterCoordinate(ctr, false);
map.SetRegion(new MKCoordinateRegion(ctr, new MKCoordinateSpan(0.025, 0.025)), false);
Console.WriteLine("Center coordinate is still NaN: " + map.CenterCoordinate.Latitude.ToString());
/*
Error: NaN Lat & Long var
circle = MKCircle.Circle(map.CenterCoordinate, 100);
@lobrien
lobrien / gist:7048562
Created October 18, 2013 21:30
There are a lot of voices available for iOS 7...
var ss = new AVSpeechSynthesizer();
foreach(var voice in AVSpeechSynthesisVoice.GetSpeechVoices())
{
var su = new AVSpeechUtterance("Microphone check. One, two, one two.") {
Rate = AVSpeechUtterance.DefaultSpeechRate,
Voice = voice
};
ss.SpeakUtterance(su);
}
@lobrien
lobrien / gist:7273287
Last active December 27, 2015 05:19
let GetAsync(url : string, i : int) =
async {
let req = WebRequest.Create(url)
let! rsp = req.AsyncGetResponse()
use stream = (rsp :?> HttpWebResponse).GetResponseStream()
use zip = new GZipStream(stream, CompressionMode.Decompress)
use reader = new StreamReader(zip)
Console.WriteLine("Received page " + i.ToString())
return reader.ReadToEnd()
}
@lobrien
lobrien / gist:7883900
Last active December 30, 2015 20:59
Completion-Handler version
public override void TouchesBegan(NSSet touches, UIEvent evt)
{
var addressString = "2 Park Plaza, Boston, MA, USA 02116";
var geocoder = new CLGeocoder();
geocoder.GeocodeAddress(addressString, (addresses, error) => {
foreach(var address in addresses)
{
Console.WriteLine(address);
}