Skip to content

Instantly share code, notes, and snippets.

@prabirshrestha
prabirshrestha / ReactBindTo.js
Created January 15, 2014 05:14
simple two way bindings for reactjs using mixins
/** @jsx React.DOM */
// http://jsfiddle.net/prabir/x2VX7/5/
var ReactBindTo = {
bindTo: function (key, defaultValue) {
var self = this;
return {
value: this.state[key] || defaultValue,
requestChange: function (value) {
@prabirshrestha
prabirshrestha / isNode.js
Created January 15, 2014 00:05
isNode.js
(function (isNode) {
var public = {};
if (isNode) {
module.exports = public;
} else {
window.public = public;
}
@prabirshrestha
prabirshrestha / node-postgres-example.js
Created January 10, 2014 04:49
sample using postgres in node js
// http://stackoverflow.com/a/19282657/157260
var pg = require('pg'),
cn = 'pg://prabirshrestha@localhost:5432/test';
pg.defaults.poolSize = 10;
pg.connect(cn, function (err, client, done) {
@prabirshrestha
prabirshrestha / AllowWriteStreamBuffering.cs
Created January 5, 2014 17:19
Patch HttpWebRequest.AllowWriteStreamBuffering using ReflectionUtils (https://github.com/facebook-csharp-sdk/reflection-utils) HttpWebRequest.AllowWriteStreamBuffering isn't present in WP7 but is present in WP8. Here is the hack to get it work on both the platforms.
PropertyInfo writeStreamBuffering = typeof(HttpWebRequest).GetProperty("AllowWriteStreamBuffering");
ReflectionUtils.GetDelegate getter = null;
ReflectionUtils.SetDelegate setter = null;
if (writeStreamBuffering != null)
{
getter = ReflectionUtils.GetGetMethod(writeStreamBuffering);
setter = ReflectionUtils.GetSetMethod(writeStreamBuffering);
}
@prabirshrestha
prabirshrestha / routes.js
Created January 4, 2014 17:54
playing around with hapi.js
var Hapi = require('hapi'),
routes,
products = [
{ id: 1, name: 'Guitar' },
{ id: 2, name: 'Banjo' }
];
routes = [
public interface IMyAppBuilder {
public IDictionary<string, object> Properties { get; }
}
public AppFunc Configuration(IDictionary<string, object> startupEnv)
{
return async env =>
{
var responseBody = (Stream) env["owin.ResponseBody"];
var bytes = Encoding.UTF8.GetBytes("hello world");
await responseBody.WriteAsync(bytes, 0, bytes.Length);
};
}
var n = Require<Nake>();
var msbuild = Require<NakeMsBuild>().init(n);
var nunit = Require<NakeNUnit>().init(n);
n.defaults(new {
configuration = "Release",
output = "output"
});
nunit.defaults(new {
public AppFunc App(IDictionary<string, object> startupEnv) {
var nginxVersion = (string)startupEnv["nginx.version"];
return async env => await env.WriteStringAsync(nginxVersion);
}
// config.csx
return new {
greeting = "hello world",
valediction = "goodbye world"
};
// config library
public class Config {
public object LoadScriptFile(string path) {
returns IDictionary<string,object> ....