Skip to content

Instantly share code, notes, and snippets.

@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-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)));
}
}
(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;
$(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;
@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: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
{
# this can be put in [repo]/.git/config for local settings
# or ~/.gitconfig for global settings
# create a difftool "nodiff" that just returns true
# this path is for Mac. On linux it's /bin/true i guess
[diff "nodiff"]
command = /usr/bin/true
# make git ignore white space differences, many different possibilites here