Skip to content

Instantly share code, notes, and snippets.

@weissi
weissi / here.sh
Created March 6, 2013 15:42
bash: Find Out Script's Containing Directory
# $HERE will contain script's containing directory
HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null && pwd -P)
#optional
cd "$HERE"
pwd
@weissi
weissi / HOWTO.md
Last active December 15, 2015 20:29
Meaning of const

Run them:

ln -s test.X test.c
ln -s test.X test.cpp

$ gcc -std=c99 test.c && ./a.out
C
$ clang -std=c99 test.c && ./a.out
C

$ g++ test.cpp && ./a.out

@weissi
weissi / file-size.c
Last active December 30, 2015 21:49
#include <assert.h>
#include <dispatch/dispatch.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/event.h>
#include <sys/event.h>
#include <sys/select.h>
### Keybase proof
I hereby claim:
* I am weissi on github.
* I am jw (https://keybase.io/jw) on keybase.
* I have a public key whose fingerprint is 925E BDA8 D5F9 B6B6 11CD E61A CD4F 0E6B B144 B067
To claim this, I am signing this object:
int invoke_fun(int (*f)(void));
{-# OPTIONS_GHC -w #-}
module Language.Swift.HappyParser where
import Data.Char
import Control.Applicative(Applicative(..))
-- parser produced by Happy Version 1.19.4
data HappyAbsSyn t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 t28 t29 t30 t31 t32 t33 t34 t35 t36 t37 t38 t39 t40 t41 t42 t43 t44 t45 t46 t47 t48 t49 t50 t51 t52 t53 t54 t55 t56 t57 t58 t59 t60 t61 t62 t63 t64 t65 t66 t67 t68 t69 t70 t71 t72 t73 t74 t75 t76 t77 t78 t79 t80 t81 t82 t83 t84 t85 t86 t87 t88 t89 t90 t91 t92 t93 t94 t95 t96 t97 t98 t99 t100 t101 t102 t103 t104 t105 t106 t107 t108 t109 t110 t111 t112 t113 t114 t115 t116 t117 t118 t119 t120 t121 t122 t123 t124 t125 t126 t127 t128 t129 t130 t131 t132 t133 t134 t135 t136 t137 t138 t139 t140 t141 t142 t143 t144 t145 t146 t147 t148 t149 t150 t151 t152 t153 t154 t155 t156 t157 t158 t159 t160 t161 t162 t163 t164 t165 t166 t167 t168 t169 t170 t171 t172 t173 t174 t175 t176 t177 t178 t179 t180 t181 t182 t183 t184 t185 t186 t187 t188 t189 t190 t191
@weissi
weissi / mem-leaker.c
Created November 11, 2014 16:46
Program to leak shared memory on OS X
#include <stdio.h>
#include <sys/mman.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
int main()
{
int err = 0;
Verifying that +johannesweiss is my openname (Bitcoin username). https://onename.io/johannesweiss
@weissi
weissi / short-circuit.swift
Created February 23, 2015 20:34
demoes short circuiting
let acts : [() -> Bool] = [ { () in println("foo"); return true; }, { () in println("bar"); return true; }]
acts.reduce(false, combine:{ $0 || $1() })
println("DONE")
@weissi
weissi / pydns.py
Created March 13, 2015 17:06
Python DNS server using recursive DNS name compression pointers and always resolving to 127.0.0.1
import SocketServer
class MyPyDNSWithLoops(SocketServer.BaseRequestHandler):
def handle(self):
data = self.request[0].strip()
socket = self.request[1]
print "<-- [%s] %r" % (self.client_address[0], data)
res = data[0] + data[1] + '\x81\x80\x00\x01\x00\x02\x00\x00\x00\x00' + \
'\x04mail\x03aYa\x03com\x00\x00\x01\x00\x01\xc0\x0c\x00\x05' + \
'\x00\x01\x00\x00\x0e\x0e\x00\x02\xc0\x11\xc0*\x00\x01\x00' + \