Skip to content

Instantly share code, notes, and snippets.

var random = new Random();
RandomStreamGenerator.GenerateIndefinitley(() => (Keys)(random.Next(1,150), k => /* do something with the key */);
@brooklynDev
brooklynDev / gist:3185573
Created July 27, 2012 01:12
Express routes/controller initialization
//app.js
var express = require('express')
, http = require('http')
, fs = require('fs');
var app = express();
app.configure(function(){
app.set('port', process.env.PORT || 3000);
@brooklynDev
brooklynDev / gist:3893421
Created October 15, 2012 16:29
Asynchronouse file download with WebRequest + show progress in Progress bar. APM vs async/await
#######################################
APM
#######################################
public partial class APMVersion : Form
{
private const int BUFFER_SIZE = 1024;
public Form1()
{
@brooklynDev
brooklynDev / Express JsonFlash
Last active August 29, 2015 14:01
Out of the box, express-flash only supports strings, occasionally it's useful to have some json stick around after redirects. This middleware tacks on a jsonFlash function to accomplish that. If you require this middleware you have both flash() and jsonFlash();
var flash = require('express-flash')();
module.exports = function() {
return function(req, res, next) {
flash(req, res, function() {
req.jsonFlash = function() {
if (arguments.length === 1) {
var data = req.flash(arguments[0]);
if (data.length) {
return JSON.parse(data);
@brooklynDev
brooklynDev / erb_compile
Last active August 29, 2015 14:06
ERB compile one liner
require 'erb'
require 'ostruct'
class << ERB
def compile(template, locals)
renderer = ERB.new(template)
struct = OpenStruct.new(locals)
class << struct
def get_binding
binding()