Skip to content

Instantly share code, notes, and snippets.

@jtmueller
jtmueller / gist:1175065
Created August 27, 2011 06:26
Chrome Frame Prompt
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<!--[if lt IE 8 ]>
<script src="//ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js"></script>
<script>window.attachEvent('onload',function(){CFInstall.check({mode:'overlay'})})</script>
<![endif]-->
</head>
var cnStr = ConfigurationManager.ConnectionStrings["foo"].ConnectionString;
using (var conn = new SqlConnection(cnStr))
using (var cmd = conn.CreateCommand())
{
// if you use a stord proc, change the type, and put the proc name in CommandText
cmd.CommandType = CommandType.Text;
cmd.CommandText = "IF NOT EXISTS (SELECT fooID FROM table WHERE fooID = @fooID) BEGIN " +
"INSERT INTO table (fooID, a, b, c, d) " +
"VALUES (@fooID, @a, @b, @c, @d) END";
var id = cmd.Parameters.Add("@fooID", SqlDbType.Int);
@jtmueller
jtmueller / gist:2401291
Created April 16, 2012 20:26
Google Code Jam Problem A in C#
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
public static class Decoder
{
private const string inputFile = "A-small-practice.in.txt";
private static readonly string[] crypt = new[] { "ejp mysljylc kd kxveddknmc re jsicpdrysi",
@jtmueller
jtmueller / gist:2416115
Created April 18, 2012 19:56
Chrome Frame Prompt
<!--[if lte IE 8]>
<script src="//ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js"></script>
<script>window.attachEvent('onload',function(){CFInstall.check({mode:'overlay'});});</script>
<![endif]-->
let forMember (destMember: Expr<'dest -> 'mbr>) (memberOpts: IMemberConfigurationExpression<'source> -> unit) (map: IMappingExpression<'source, 'dest>) =
map.ForMember(Expr.ToFuncExpression <@ %destMember >> box @>, memberOpts)
test 7 "=3 + 4"
test -1.5 "=-C3"
test -8 "=-2 ^ 3"
test true "=AND(2+2=4, 2+3=5)"
test "Not OK" "=IF(C3 <= C4, \"OK\", \"Not OK\")"
test -4257.44 "=(C1 + C3 - 1) * -C5"
test -4 "=(3 - (4 + 5)) + 2"
test "Not quite." "=IF(AND(2+2=4, 3+4>6, 5*9<10), \"All true!\", \"Not quite.\")"
test "Some true" "=IF(OR(2+2=4, 3+4>6, 5*9<10), \"Some true\", \"Not quite.\")"
test 24.0 "=C3 * 4 ^ 2"
function foo()
{
return
{
a: 1,
b: 3,
c: 7
};
}
// Akka F# API
type ICanTell with
member this.Ask(msg: obj, timeout: TimeSpan): Async<'Response> =
this.Ask<'Response>(msg, Nullable(timeout)) |> Async.AwaitTask
// If we do this.Ask().ContinueWith(..) after shutting down the host for a remote actor,
// the task passed into ContinueWith has IsFaulted = false and Exception = null, but throws
// an AggregateException when the Result property is accessed.
// Knowing this, I wrote the following replacement to the Akka F# API extension method above.
namespace Akka.FSharp
open System
/// The result of an Akka Ask operation, either a value or an exception.
type AskResult<'TResult> =
| Ok of result: 'TResult
| Err of exn
with
/// Retrieves the value on success, throws an exception if there was an error.
// Allows for strongly-typed access to underlying DOM elements when working with jQuery objects containing only a single element type.
interface JQueryOf<T extends HTMLElement> extends JQuery {
get(index: number): T;
get(): T[];
[index: number]: T;
eq(index: number): JQueryOf<T>;
first(): JQueryOf<T>;
last(): JQueryOf<T>;
slice(start: number, end?: number): JQueryOf<T>;