Skip to content

Instantly share code, notes, and snippets.

@miensol
miensol / RazorHtmlFormatter.cs
Created February 27, 2012 19:18
Razor MediaTypeFormatter
using System;
using System.Collections.Concurrent;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http.Formatting;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using RazorEngine;
@miensol
miensol / Observable
Last active December 16, 2015 13:08
Javascript Observable
var Observable = function(){
var that = this,
listeners = {},
callHandler = function(args){
this.handler.apply(this.scope, args);
},
on = function(eventName, handlerFun, scope){
var listenerList = [], handlerObj;
if(!eventName){
throw "cannot call 'on' with empty eventName";
@miensol
miensol / Gruntfile.js
Created July 1, 2013 19:08
Grunt watching less and coffee Compiles individual files
var path = require('path');
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
coffee: {
all: {
files: [{
@miensol
miensol / Global.asax.cs
Created August 27, 2013 15:33
Loading views from outside of asp.net mvc root directory
using System.Collections.Specialized;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Web;
using System.Web.Hosting;
using System.Web.Mvc;
using System.Web.Routing;
namespace TestSamples.VirtualPath
var net = require('net'),
http = require('http'),
Writable = require('stream').Writable,
parsers = http.parsers,
HTTPParser = process.binding('http_parser').HTTPParser,
util = require('util'),
EventEmitter = require('events').EventEmitter;
function freeParser(parser, req) {
if (parser) {
@miensol
miensol / generator_simple.harmony.js
Created June 14, 2014 06:50
a simple es6 generator
var sequence = function *() {
yield 1;
yield 2;
};
var sequenceGenerator = sequence();
var current = null;
current = sequenceGenerator.next();
console.log(current);
current = sequenceGenerator.next();
console.log(current);
@miensol
miensol / generator_simple.harmony.js
Created June 14, 2014 07:17
es6 fibonaci generator
var fibo = function *(){
var a = 0,
b = 1;
yield a;
yield b;
while(true){
var next = a + b;
yield next;
a = b;
@miensol
miensol / generator_simple.harmony.js
Last active August 29, 2015 14:02
oracle generator es6
var oracle = function *(){
var question = yield "Hello";
while(question != "Bye!"){
var answer = Math.random();
console.log(question, "oracle says: ", Math.random());
question = yield answer;
}
console.log("Thank you!")
};
@miensol
miensol / generator_simple.harmony.js
Created June 14, 2014 09:01
generator throwing excaptions
var throwing = function *(){
console.log('Generator entered, yielding first value');
yield 1;
console.log('Generator asked for second value - will go bum');
throw new Error("You can only call this generator once, sorry!");
console.log('Will never get here');
yield 3;
};
var throwingGenerator = throwing();
@miensol
miensol / generator_simple.harmony.js
Created June 14, 2014 09:13
generator receiving exceptions
var catchingGenerator = function *(){
console.log('I will stop when you tell me about error');
var error = null;
while(error === null){
try {
var value = yield null;
console.log("Got value from you: %s", value);
}catch(e){
error = e;
}