Skip to content

Instantly share code, notes, and snippets.

View robertklep's full-sized avatar

Robert Klep robertklep

View GitHub Profile
@robertklep
robertklep / dabblet.css
Created February 23, 2013 20:06
European Energy Label in CSS
/**
* European Energy Label in CSS
*/
.energy-class {
position: relative;
width: 155px;
font-family : sans-serif;
}
.energy-class span {
@robertklep
robertklep / double-encoding-fixes.py
Created June 14, 2012 05:50
Functions to detect/fix double-encoded UTF-8 strings in Python
import re
# functions to detect/fix double-encoded UTF-8 strings
# Based on http://blogs.perl.org/users/chansen/2010/10/coping-with-double-encoded-utf-8.html
DOUBLE_ENCODED = re.compile("""
\xC3 (?: [\x82-\x9F] \xC2 [\x80-\xBF] # U+0080 - U+07FF
| \xA0 \xC2 [\xA0-\xBF] \xC2 [\x80-\xBF] # U+0800 - U+0FFF
| [\xA1-\xAC] \xC2 [\x80-\xBF] \xC2 [\x80-\xBF] # U+1000 - U+CFFF
| \xAD \xC2 [\x80-\x9F] \xC2 [\x80-\xBF] # U+D000 - U+D7FF
| [\xAE-\xAF] \xC2 [\x80-\xBF] \xC2 [\x80-\xBF] # U+E000 - U+FFFF
@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>
@robertklep
robertklep / clientserver.js
Created May 2, 2013 07:57
client -> socket.io server 1 (clientserver.js) -> socket.io server 2 (serverserver.js)
var app = require('express')()
, server = require('http').createServer(app)
, io = require('socket.io').listen(server);
server.listen(3012);
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});
@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 / app.js
Last active September 15, 2018 00:33
// First: create an index.html in the same directory, and try retrieving it
// via http://localhost:3012/ ; instead, you'll get the 'catchall' response.
// This is because the code below is equivalent to:
//
// app.use(app.router); <-- which *also* handles the catch-all
// app.use(express.static()); <-- never reached because the router caught it
//
var express = require('express');
var app = express();
var express = require('express');
var app = express();
app.use(express.static(__dirname));
app.get('/search', function(req, res){
res.send({ hello : 'world' });
});
app.listen(3012);
@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');
app.use(function(req, res, next) {
if (req.method === 'HEAD') {
res.on('finish', function() {
req.connection.end();
});
}
next();
});
public class Test {
public static void main(String[] args) {
long heapMaxSize = Runtime.getRuntime().maxMemory();
System.out.println("Max: " + heapMaxSize);
}
}