Skip to content

Instantly share code, notes, and snippets.

View machadogj's full-sized avatar

Gustavo Machado machadogj

View GitHub Profile
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Reactive.Linq;
using System.Text;
using System.Web;
using Newtonsoft.Json;
@machadogj
machadogj / gist:1023075
Created June 13, 2011 16:08
Rx Using the Repeat operator
var start = Observable.FromEvent<EventArgs>(btnStart, "Click");
var stop = Observable.FromEvent<EventArgs>(btnStop, "Click");
var keyDown = Observable.FromEvent<KeyEventArgs>(txtMainText, "KeyDown")
.Select(x => x.EventArgs)
.SkipUntil(start)
.TakeUntil(stop)
.Repeat() //this will start skiping again after stop was raised.
.Where(x =>
{
@machadogj
machadogj / gist:3539358
Created August 30, 2012 19:58
Git Cheat Sheet
#aliases
git config --global alias.tree 'log --oneline --abbrev-commit --all --graph --decorate'
#view the history of the repo
git log --oneline --abbrev-commit --all --graph --decorate
#view whitespace issues.
git diff --check
#common flow
var app = connect()
.use(function(req,res,next){
buffer = httpProxy.buffer(req);
next();
})
.use(connect["static"](process.cwd()))
.use(function(req, res){
//alter request here.
req.headers["host"] = host;
@machadogj
machadogj / server.js
Created September 26, 2012 17:27
HTTPS With SNI not working on IE9
var https = require('https');
var fs = require('fs');
var crypto = require("crypto");
var options = {
SNICallback: function (hostname) {
console.log('hostname: ' + hostname);
return crypto.createCredentials({
key: fs.readFileSync('default.key'),
cert: fs.readFileSync('default.crt')
@machadogj
machadogj / -n 100 -c 1
Created November 2, 2012 20:19
Express App Load Tests
PS D:\apache\bin> .\ab.exe -n 100 http://one.org:3000/
This is ApacheBench, Version 2.3 <$Revision: 1373084 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking one.org (be patient).....done
Server Software:
Server Hostname: one.org
@machadogj
machadogj / MyClass.js
Created April 5, 2013 20:59
Sample code for understanding error handling in node.js.
var util = require('util'),
EventEmitter = require('events').EventEmitter;
var MyClass = function () {
if (!(this instanceof MyClass)) return new MyClass();
EventEmitter.call(this);
};
@machadogj
machadogj / users.coffee
Created August 16, 2013 13:22
Example of global scope being a problem when code is converted from js.
###
Include database config.
@var [Object] db
@api private
###
###
Set users collection
@machadogj
machadogj / server.js
Created November 8, 2013 18:49
Express error handling
var express = require('express');
var app = express();
app.get('/', function (req, res, next) {
next({ status: 403, message: 'this is forbidden'});
});
app.use(function (err, req, res, next) {
res.send(err.status || 500, err.message || "something broke");
});
@machadogj
machadogj / picker.js
Created March 17, 2016 20:18
React native simple picker
"use strict";
import React from "react-native";
let {
StyleSheet,
View,
ScrollView,
PropTypes,
Component,
Text