Skip to content

Instantly share code, notes, and snippets.

@bruinbrown
bruinbrown / fs.txt
Created May 11, 2014 12:44
FS error
let svc = Betdaq.GetReadOnlyService()
// returns either Betdaq.ServiceTypes.SimpleDataContextTypes.ReadOnlyServiceClient or Betdaq.ServiceTypes.SimpleDataContextTypes.SecureServiceClient
A unique overload for method 'GetReadOnlyService' could not be determined based on type information prior to this program point. A type annotation may be needed. Candidates: Betdaq.GetReadOnlyService() : Betdaq.ServiceTypes.SimpleDataContextTypes.ReadOnlyServiceClient, Betdaq.GetReadOnlyService() : Betdaq.ServiceTypes.SimpleDataContextTypes.SecureServiceClient
@bruinbrown
bruinbrown / crazy.cs
Created May 9, 2014 10:18
Ridiculous C#
namespace Ref
{
public class @Ref
{
public @Ref @ref(ref @Ref @ref)
{
return @ref.@ref(ref @ref);
}
}
}
@bruinbrown
bruinbrown / brainfuck.fs
Created February 24, 2014 21:06
Brainfuck interpreter in F#. Matches most of the functionality of https://github.com/bruinbrown/Brainfuck-Interpreter but it's in F# instead of C#
let FindJump dir (program:char []) cidx =
let s = System.Collections.Generic.Stack<int>()
let rec NextChar index =
match program.[index], dir with
| '[', 1
| ']', -1 -> s.Push(index)
NextChar (index+dir)
| ']', 1
| '[', -1 -> if s.Count = 0 then (index+1)
else
@bruinbrown
bruinbrown / Geolocator.cs
Created November 18, 2013 17:03
Hack to get around broken Geolocator.GetPositionAsync on WP8
private void GetLocation()
{
var locator = new Geolocator();
Geoposition position = null;
try
{
var positionTask = locator.GetGeopositionAsync();
await Task.Delay(200);
positionTask.Cancel();
}
@bruinbrown
bruinbrown / switch.cs
Last active December 21, 2015 05:28
Using predicates to reduce code coupling
public class Switch
{
private bool _isOn;
private Predicate<bool> _onCriteria;
public Switch(Predicate<bool> onPredicate)
{
_onCriteria = onPredicate;
_isOn = _onCriteria.Invoke(true); //When you see below the x will be true as that is the value we invoked it with
//We can just as easily store a control value which we pass in
@bruinbrown
bruinbrown / app.win8.cs
Last active December 19, 2015 04:09
Azure mobile services device limit workaround. This really isn't ideal and I wouldn't recommend doing it as I don't know the consequences When mobile services went GA, there was a 100 device limit introduced on the free tier and unlimited on the paid tier. Not ideal if you're releasing a free app. It turns out it's easier than you'd think to tri…
//For Windows 8
DeviceGuid = "2DC22302-AB12-4DDD-86A0-4265843C78FC";
JObject obj = new JObject();
obj["applicationInstallationId"] = DeviceGuid;
string configText = obj.ToString();
ApplicationData.Current.LocalSettings.Values["MobileServices.Installation.config"] = configText;
Client = new MobileServiceClient("AMS URL");
@bruinbrown
bruinbrown / challenge1.cs
Last active December 19, 2015 00:59
Decided to give Mark Heath's lunchtime LINQ challenge a go. http://mark-dot-net.blogspot.co.uk/2013/06/lunchtime-linq-challenge.html
var data = "Davis, Clyne, Fonte, Hooiveld, Shaw, Davis, Schneiderlin, Cork, Lallana, Rodriguez, Lambert";
var result = data.Split(',').Select((str, index) => String.Format("{0}. {1}", index+1, str.Trim()));
@bruinbrown
bruinbrown / Program.fs
Created May 24, 2013 16:23
Decided to take the Twitter search (http://byteonmyside.wordpress.com/2013/05/17/a-twitter-search-client-in-10-lines-of-code-with-f-and-the-json-type-provider/) and roughly calculate Twitter's attitude to a topic. Very rough approximation of attitude but it gave me a chance to try some more F# stuff. Some changes which I know I can make next: ty…
open System.Linq
type T = FSharp.Data.JsonProvider<"http://search.twitter.com/search.json?q=%23fsharp&lang=en&rpp=1&page=1">
let positives = [| "good"; "awesome"; "sweet"; "nice"; "cool" |]
let negatives = [| "crap"; "terrible"; "poor"; "bad"; "awful" |]
let tweets (tag:string) (since: System.DateTime) =
let enc = System.Net.WebUtility.UrlEncode : string -> string
let rec page n =
if n < 16 then
let data = T.Load(sprintf "http://search.twitter.com/search.json?q=%s&rpp=100&page=%d&since=%4d-%02d-%02d" (enc tag) n since.Year since.Month since.Day)
@bruinbrown
bruinbrown / Blade DOM manipulation.cs
Created December 27, 2012 21:31
Manipulating the DOM with Blade
using System;
using System.Dom;
using System.Html;
namespace BladeTest
{
public class BladeExample
{
public BladeExample()
{
@bruinbrown
bruinbrown / index.html
Created December 27, 2012 18:58
Basic html for use with Blade
<!doctype html>
<html>
<head>
<script src="blade.js" type="text/javascript"></script>
<script src="BladeTest.js" type="text/javascript"></script>
<title>Blade Test</title>
</head>
<body onload="BladeTest.BladeExample()">
<p id="test">
</p>