Skip to content

Instantly share code, notes, and snippets.

Avatar

Felix Geisendörfer felixge

View GitHub Profile
View scrollable.js
gc.widget("gc.cl.widgets.scrollable", {}, function (m, document, $, gc) {
$ = jQuery; // Sorry Malte
var ANIMATION_SPEED = 800;
// A little helper function to sniff common CSS properties that we need
// to animate form an event.
function getCss($element) {
var css = {
opacity: $element.css('opacity'),
View example.json
{
"flameExplain": "Go to flame-explain.com and paste this JSON in the Input tab.",
"input": {
"plan": "[\n {\n \"Plan\": {\n \"Node Type\": \"Function Scan\",\n \"Parallel Aware\": false,\n \"Function Name\": \"generate_series\",\n \"Schema\": \"pg_catalog\",\n \"Alias\": \"generate_series\",\n \"Startup Cost\": 0.00,\n \"Total Cost\": 10.00,\n \"Plan Rows\": 1000,\n \"Plan Width\": 4,\n \"Actual Startup Time\": 194.503,\n \"Actual Total Time\": 331.185,\n \"Actual Rows\": 1500000,\n \"Actual Loops\": 1,\n \"Output\": [\"generate_series\"],\n \"Function Call\": \"generate_series(1, 1500000)\",\n \"Shared Hit Blocks\": 0,\n \"Shared Read Blocks\": 0,\n \"Shared Dirtied Blocks\": 0,\n \"Shared Written Blocks\": 0,\n \"Local Hit Blocks\": 0,\n \"Local Read Blocks\": 0,\n \"Local Dirtied Blocks\": 0,\n \"Local Written Blocks\": 0,\n \"Temp Read Blocks\": 0,\n \"Temp Written Bloc
View example.json
{
"flameExplain": "Go to flame-explain.com and paste this JSON in the Input tab.",
"input": {
"plan": "[\n {\n \"Plan\": {\n \"Node Type\": \"Function Scan\",\n \"Parallel Aware\": false,\n \"Function Name\": \"generate_series\",\n \"Schema\": \"pg_catalog\",\n \"Alias\": \"generate_series\",\n \"Startup Cost\": 0.00,\n \"Total Cost\": 10.00,\n \"Plan Rows\": 1000,\n \"Plan Width\": 4,\n \"Actual Startup Time\": 194.503,\n \"Actual Total Time\": 331.185,\n \"Actual Rows\": 1500000,\n \"Actual Loops\": 1,\n \"Output\": [\"generate_series\"],\n \"Function Call\": \"generate_series(1, 1500000)\",\n \"Shared Hit Blocks\": 0,\n \"Shared Read Blocks\": 0,\n \"Shared Dirtied Blocks\": 0,\n \"Shared Written Blocks\": 0,\n \"Local Hit Blocks\": 0,\n \"Local Read Blocks\": 0,\n \"Local Dirtied Blocks\": 0,\n \"Local Written Blocks\": 0,\n \"Temp Read Blocks\": 0,\n \"Temp Written Bloc
View main-linux.c
// Example program showing that signal delivery from setitimer ends up in
// "random" threads of the executing program.
#include <sys/time.h>
#include <unistd.h>
#include <signal.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
View multiwrap.go
// Package multiwrap implements support for wrapping multiple errors into a
// single error value that supports the Go 1.13 Unwrap(), Is() and As()
// interface. It's similar to go-multierror [1].
//
// This is a proof of concept and I'm looking for feedback! Maybe somebody has
// already done a nicer version of this idea?
//
// [1] https://godoc.org/github.com/hashicorp/go-multierror
package multiwrap
@felixge
felixge / command.sh
Created Oct 29, 2011
Bash stuff for fighting a weak DOS attack
View command.sh
# Here a few bash one-liners that helped me analyze / fight a weak DOS attack against debuggable.com. Mostly for future reference.
# The attacker was opening lots of tcp connections without sending data, I believe it's called a SYN flood, see: http://tools.ietf.org/html/rfc4987#section-3.2
# Step 0: Check what is going on at port 80
$ netstat -tan | grep ':80 ' | awk '{print $6}' | sort | uniq -c
# Step 1: Increase the number of available fds
$ ulimit -n 32000
# Step 2: Restart your webserver, for me:
View wc.asm
global main
extern printf
section .text
main:
sub rdi, 1 ; argc includes program name, so substract 1 to get arg count
cmp rdi, 1 ; check if we got exactly 1 arg
jne bad_arg_count ; if not, jump to bad_arg_count
mov r15, [rsi+8] ; main's argv[1]
mov r14, 0 ; index (also byte count)
View blocked-by-loop.js
let last = new Date();
setInterval(function () {
delta = new Date() - last;
if (delta > 2) {
console.log(delta);
}
last = new Date();
}, 1);
setInterval(function () {
View run-wc.txt
$ time wc test.txt
16500000 49252094 2059004431 test.txt
real 0m5.930s
user 0m5.491s
sys 0m0.374s
$ go build wc.go && time ./wc test.txt
16500000 49252094 2059004431
View plan.json
[
{
"Plan": {
"Node Type": "Nested Loop",
"Parallel Aware": false,
"Join Type": "Inner",
"Startup Cost": 0.01,
"Total Cost": 17402710335540.01,
"Plan Rows": 1000000000000000,
"Plan Width": 20,