Skip to content

Instantly share code, notes, and snippets.

View emiel's full-sized avatar

Emiel van de Laar emiel

View GitHub Profile
@emiel
emiel / gist:4228813
Created December 6, 2012 21:49
Simple stdin to stdout (through char buffer)
#include <iostream>
int main(int argc, char *argv[])
{
char buf[4096];
while (std::cin.good()) {
std::cin.read(buf, sizeof(buf));
std::cout.write(buf, std::cin.gcount());
}
@emiel
emiel / gist:4232312
Created December 7, 2012 10:16
Simple stdin to stdout
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << std::cin.rdbuf();
}
@emiel
emiel / gist:4353901
Created December 21, 2012 16:39
Recursively replace nested dict(s) with your own dict subclass type.
import json
from collections import defaultdict
class D(defaultdict):
def __init__(self, *args, **kwargs):
if args and len(args) == 1 and isinstance(args[0], dict):
for k, v in args[0].items():
if isinstance(v, dict):
self[k] = self.__class__(v)
@emiel
emiel / foobar.py
Created March 13, 2013 20:45
Python multi-line string (wrap with parenthesis)
def foobar():
stmt = (
"select * from foobar"
" where x > 3"
" and y < 3"
" and z = 3"
)
return stmt
print(foobar())
File system
* Preferably something without a journal
* Use ext4 or xfs
* Mount filesystems with 'noatime'
* Separate disk for xlog and data
Tools
* iotop
* iozone
* mpstat
@emiel
emiel / config.log
Created October 2, 2015 09:36
Building goaccess on Mac OS X
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by goaccess configure 0.9.4, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ ./configure
## --------- ##
## Platform. ##
@emiel
emiel / editor-demo-using-template.html
Created May 12, 2016 14:31
Demo simple editor using html5 template element
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Template Test</title>
<style>
h1 { font-family: Georgia; }
#editor { max-width: 600px; }
.editable { background-color: #eeeeee; }
</style>
@emiel
emiel / gist:a4aa857bd4080a1032edc6bb2576f850
Created February 1, 2017 16:07
kombu forced close issue
DEBUG:amqp:using channel_id: 1
DEBUG:amqp:Channel open
DEBUG:amqp:heartbeat_tick : for connection cf6b5602c69a4de5aaaac06b0cda63d8
DEBUG:amqp:heartbeat_tick : for connection cf6b5602c69a4de5aaaac06b0cda63d8
DEBUG:amqp:heartbeat_tick : for connection cf6b5602c69a4de5aaaac06b0cda63d8
DEBUG:amqp:heartbeat_tick : for connection cf6b5602c69a4de5aaaac06b0cda63d8
DEBUG:amqp:heartbeat_tick : for connection cf6b5602c69a4de5aaaac06b0cda63d8
DEBUG:amqp:heartbeat_tick : for connection cf6b5602c69a4de5aaaac06b0cda63d8
DEBUG:amqp:heartbeat_tick : for connection cf6b5602c69a4de5aaaac06b0cda63d8
DEBUG:amqp:heartbeat_tick : for connection cf6b5602c69a4de5aaaac06b0cda63d8
@emiel
emiel / django_rest_api.py
Created February 16, 2017 17:51
Simple Django REST API
from django.http import HttpResponse
class ApiResponse(HttpResponse):
def __init__(data, **kwargs):
kwargs.setdefault("content_type", "application/json")
content = json.dumps(data)
super(ApiResponse, self).__init__(content=data, **kwargs)
@emiel
emiel / flask_rest_api.py
Created February 16, 2017 17:54
Simple Flask REST API
from flask import Flask
from flask import json, Response
"""
From: https://youtu.be/1ByQhAM5c1I
"""
class ApiResult(object):
"""