Skip to content

Instantly share code, notes, and snippets.

@tanglebones
tanglebones / gist:1401596
Created November 28, 2011 19:15
TC config updater for building project branches
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
namespace Move.Platform.TeamCityBranchUpdaterTool
{
public static class Program
{
@tanglebones
tanglebones / gist:1401628
Created November 28, 2011 19:23
Muxing C# types with DynamicObject
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.IO;
using System.Reflection;
using System.Text;
namespace test
{
public class Mux<T> : DynamicObject
@tanglebones
tanglebones / gist:2640039
Last active September 22, 2017 00:47
Type safe Cons Car Cdr in C# using only functions and allowing for different types in Cons
// cons :: a -> b -> (a -> b -> t) -> t
// cons a b = \x -> x a b
static Func<Func<TA, TB, dynamic>, dynamic> Cons<TA, TB>(TA a, TB b)
{
return f=>f(a,b);
}
// NOTE: you can not write:
// static Func<Func<TA, TB, TC>, TC> Cons<TA, TB>(TA a, TB b)
// {
$(function () {
"use strict";
// for better performance - to avoid searching in DOM
var content = $('#content');
var input = $('#input');
var status = $('#status');
// my color assigned by the server
var myColor = false;
(function() {
var mongodb = require('mongodb');
var http = require('http');
var url = require('url');
var socketio = require('socket.io');
var express = require('express');
var passport = require('passport');
var passport_google = require('passport-google').Strategy;
var host = "chammers01vd";
var port = process.env.PORT || 3000;
@tanglebones
tanglebones / HttpListenerExample.cs
Last active February 27, 2024 15:21
HttpListener Example
using System;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Server
{
public static class Program
@tanglebones
tanglebones / app-backend-sign-s3policy.cs
Last active December 17, 2015 04:19
Computing the signature for an s3 policy
static string ComputeSignature(string policyEncoded, string privateKey)
{
using (var hmac = new HMACSHA1(Encoding.UTF8.GetBytes(privateKey), true))
{
return Convert.ToBase64String(hmac.ComputeHash(Encoding.UTF8.GetBytes(policyEncoded)));
}
}
@tanglebones
tanglebones / app-backend-s3policy.cs
Last active December 17, 2015 04:19
Creating a signed S3 policy for a jpeg image.
var policy = new JObject();
policy["expiration"] = DateTime.UtcNow.AddMinutes(10).ToString("u").Replace(" ", "T");
var cond = new JArray();
policy["conditions"] = cond;
cond.Add(new JObject {{"bucket", Bucket}});
cond.Add(new JObject {{"key", filename}});
cond.Add(new JObject {{"acl", "public-read"}});
cond.Add(new JObject {{"Content-Type", "image/jpeg"}});
cond.Add(new JArray("content-length-range", 0, 1024*1024));
@tanglebones
tanglebones / app-client-send-s3.cs
Last active December 17, 2015 04:19
Sending a file to S3
private static byte[] GetMultipartFormData(
IDictionary<string, string> parameters,
string caName,
byte[] fileContents,
string boundary)
{
var formDataStream = new MemoryStream();
byte[] formData;
using(formDataStream)
@tanglebones
tanglebones / needless_if.cs
Created July 10, 2013 20:04
Bad Code: Needless if
// do not write:
if (!expr)
{
return false;
}
return true;
// instead of