Skip to content

Instantly share code, notes, and snippets.

View AlexCuse's full-sized avatar

Alex Ullrich AlexCuse

View GitHub Profile
@AlexCuse
AlexCuse / gist:1055202
Created June 29, 2011 22:53
looping indexer
let Run<'T when 'T: not struct and 'T:null and 'T:equality> (errorCallback, ct:CancellationToken, finished:ManualResetEvent) =
let p = QueueProvider<'T>.Create()
try
while not (ct.IsCancellationRequested) do
match p.Dequeue() with
| null -> Thread.Sleep 1000
| _ as obj ->
try
write obj
with | ex ->
@AlexCuse
AlexCuse / gist:1055416
Created June 30, 2011 01:03
rabbitmq subscription?
//I think this is more or less how it'd work
public IEnumerable<T> Stuffs () {
bool noAck = false;
using (var connection = connectionFactory.CreateConnection ())
using (var channel = SetupChannel (connection)) {
var sub = new Subscription (channel, queueName, noAck);
while (true) {
var result = sub.Next ();
if (result != null) {
@AlexCuse
AlexCuse / gist:1055462
Created June 30, 2011 01:41
F# subscription
namespace BrewTelligence.Search.IndexingService
#light
open System.Threading
open System.Configuration
open RabbitMQ.Client
open RabbitMQ.Client.MessagePatterns
//TODO: single connection / channel for lifetime?
@AlexCuse
AlexCuse / gist:1056072
Created June 30, 2011 11:46
subscriber usage
let Run<'T when 'T: not struct and 'T:null and 'T:equality> (errorCallback, ct:CancellationToken, finished:ManualResetEvent) =
let sub = new Subscriber<'T>()
sub.ReceivedMessages(ct)
|> Seq.iter (fun msg ->
try
write msg
with | ex ->
sub.Return msg
errorCallback ex)
finished.Set() |> ignore
@AlexCuse
AlexCuse / NHibernatePartialCollection.cs
Created January 15, 2012 00:59
Limiting Collection Contents w/ NHibernate
[Test]
public void Limit_Collection_Contents_Criteria() {
var pepperoni = new Topping { Name = "pepperoni", Type = "meat" };
var cheese = new Topping { Name = "mozzarella", Type = "dairy" };
var cheesePizza = new Pizza() { Crust = "deep dish", Sauce = "red" }
.WithTopping(cheese);
var pepperoniPizza = new Pizza() { Crust = "deep dish", Sauce = "red" }
.WithTopping(cheese)
@AlexCuse
AlexCuse / BuildAuthorizationKey.cs
Created April 25, 2012 18:14
Build Authorization Key for AWS Requests in C#
/// <summary>
/// generates key to include in the "Authorization" request header
/// </summary>
/// <param name="accessKey">AWS access key</param>
/// <param name="secretKey">AWS secret key</param>
/// <param name="dateString">string included in the "x-amz-date" request header</param>
/// <returns>string to be used for signing request</returns>
static string BuildSignature(string accessKey, string secretKey, string dateString) {
var hmacSha1 = new HMACSHA1(Encoding.UTF8.GetBytes(secretKey));
var hashedDate = Convert.ToBase64String(hmacSha1.ComputeHash(Encoding.UTF8.GetBytes(dateString)));
@AlexCuse
AlexCuse / DatabaseReCollatorMcJawn.sql
Created April 26, 2012 14:02
Recollate All SQL Server Columns
--desired collation for (var)char columns:
DECLARE @collationName VARCHAR(30)
SET @collationName = 'Latin1_General_CS_AI'
--build tables containing drop/create index queries
--http://www.sqlservercentral.com/scripts/Indexing/31652/
SELECT
REPLICATE(' ',4000) AS COLNAMES ,
OBJECT_NAME(I.ID) AS TABLENAME,
I.ID AS TABLEID,
@AlexCuse
AlexCuse / GithubTicketImporter.cs
Created May 22, 2012 00:05
Retrieve open tickets from assembla and create issues for them on github :)
using System;
using System.Collections.Generic;
using RestSharp;
namespace GithubTicketImporter {
class Program {
static IAuthenticator authenticator = new HttpBasicAuthenticator("uname", "pwd");
static string assemblaBaseUrl = "https://www.assembla.com/spaces/BrewTelligence/";
static string githubBaseUrl = "https://api.github.com/";
@AlexCuse
AlexCuse / kernel.placeholder.js
Created July 10, 2012 17:37 — forked from aaronmccall/placeholder.js
shim for browsers that don't support the html5 placeholder attribute
(function () {
$.support.placeholder = false;
var test = document.createElement('input');
if ('placeholder' in test) {
$.support.placeholder = true;
return function () { }
} else {
return function () {
$(function () {
var active = document.activeElement;
@AlexCuse
AlexCuse / NullableIntegerAttribute.cs
Created December 18, 2012 22:13
nullable integer validation
using System.ComponentModel.DataAnnotations;
namespace Project.MvvmFramework.ValidationAttributes
{
public class NullableIntegerAttribute : ValidationAttribute
{
private readonly int _maxDigits;
private readonly string _propertyName;
const string MessageFormat = "{0} can only contain up to {1} numeric characters.";