Skip to content

Instantly share code, notes, and snippets.

View micahasmith's full-sized avatar

Micah Smith micahasmith

View GitHub Profile
@micahasmith
micahasmith / objlit-sig.js
Created July 12, 2012 20:01
objlit functional signature style, take one
/**
* Here's the idea:
* Lets see what we can do if we don't do function(err,cb) all the time
* and instead we do function(objlit)
*
* Any advantages to instead wrapping it in one variable?
*/
// an example of what this may look like
@micahasmith
micahasmith / nodejs-livescript-webserver.ls
Created July 1, 2012 18:05
nodejs livescript webserver example
# the main example from nodejs.org
http = require 'http'
http.createServer (req,res)->
res.writeHead 200, \Content-Type : \text/plain
res.end 'Hello World\n'
.listen 1337 \127.0.0.1
console.log 'server running'
@micahasmith
micahasmith / site.conf
Created June 10, 2012 19:42
nginx rewrite configuration
# here i'm telling the server to rewrite all requests
# for that contain a html extension-- remove the html
rewrite (.*)\.html $1 permanent;
# here i'm telling the server to try finding the file by appending
# the .html on to it
# important since the files all have extensions
try_files $uri.html $uri/ /index.html;
@micahasmith
micahasmith / nonasync-webrequest-httphandler.ashx.cs
Created May 8, 2012 20:56
nonasync web request httphandler
public class nonasync_webrequest_test : IHttpHandler {
public void ProcessRequest (HttpContext context) {
var r = new RequestState()
{
Wr = WebRequest.Create("http://www.google.com"),
Cxt = context
};
r.Wr.Method = "GET";
var s= r.Wr.GetResponse();
@micahasmith
micahasmith / asyncronous-web-request.ashx.cs
Created May 8, 2012 20:51
asyncronous httphandler web request
public class RequestState
{
public WebRequest Wr { get; set; }
public HttpContext Cxt { get; set; }
public static string ReadStream(Stream i)
{
using (StreamReader sr = new StreamReader(i))
{
return sr.ReadToEnd();
}
public class nonasync_httphandler_test : IHttpHandler
{
public void ProcessRequest(HttpContext c)
{
TestMethods.Handle(c);
}
public bool IsReusable
{
public class TestMethods
{
public static void Handle(HttpContext c)
{
c.Response.ContentType = "text/plain";
c.Response.Write(string.Format("Hello World async {0}", Fib(10)));
}
static int Fib(int x)
{
if (x <= 1)
@micahasmith
micahasmith / RxWebServer.cs
Created May 7, 2012 21:40
Quick Rx Based Web Server
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Data;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using System.Reactive.Linq;
@micahasmith
micahasmith / SimpleTcpServer.cs
Created May 7, 2012 00:08
simple c# tcp server
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Data;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
@micahasmith
micahasmith / server.js
Created March 20, 2012 03:08
node.js google reverse geocode proxy
var http = require('http'),
q = require('querystring')
http.createServer(function (req, res) {
//create the geo long/lat path
var url=["/maps/geo?q="
,q.parse(req.url)["long"]
,","
,q.parse(req.url)["lat"]