Skip to content

Instantly share code, notes, and snippets.

View mirekfranc's full-sized avatar
🌚
Rien

Miroslav Franc mirekfranc

🌚
Rien
  • Prague, Czech Republic
View GitHub Profile
@mirekfranc
mirekfranc / cpp.vim
Last active July 28, 2016 14:13
mkdir -p ~/.vim/syntax; cp ./cpp.vim ~/.vim/syntax/cpp.vim && ln -s ~/.vim/syntax/cpp.vim ~/.vim/syntax/c.vim
syntax match BeforeSpace /^ */ containedin=ALL
syntax match AfterSpace / *$/ containedin=ALL
syntax match InsideSpace "\t *\t"hs=s+1,he=e-1 containedin=ALL
highlight BeforeSpace ctermbg=DarkBlue
highlight AfterSpace ctermbg=DarkBlue
highlight InsideSpace ctermbg=DarkBlue
def main_setup (option_parsing, pager=True):
def decorator (real_main):
def main_wrapper ():
options, argv = option_parsing ()
if pager and options.use_pager:
o, pager_is_less = get_pager ()
else:
o, pager_is_less = sys.stdout, False
Colors.setup(enabled = not (options.no_colors or (not os.isatty (o.fileno ()) and not options.keep_colors and not pager_is_less)))
if options.debug is True:
@mirekfranc
mirekfranc / handling_of_global_exceptions.py
Last active November 16, 2015 18:18
nice trick to offload exception handling with a context manager
import sys
class handling_of_global_exceptions (object):
def __enter__ (self):
pass
def __exit__ (self, e_type, e_val, e_tb):
if isinstance (e_val, KeyboardInterrupt):
sys.stderr.write ("\nControl-C. Let's call it quits.\n")
elif isinstance (e_val, IOError) and e_val[1] == 'Broken pipe':
@mirekfranc
mirekfranc / plt_resolution.aarch64.cfg
Created November 12, 2015 04:35
PLT resolution (cfg suffix is for syntax highlight :))
# let's have a code that calls glibc's puts twice
somewhere in the code:
0x00000000004004c4 <+36>: bl 0x400490 <puts@plt>
# calling plt stub; return address is in link register (x30)
(gdb) p/x $x30
$2 = 0x4004c8
# bl stands for branch and link; like call on intel, but we use link register instead of top of stack for return adress
@mirekfranc
mirekfranc / divisible_by_all_numbers.c
Last active November 6, 2015 16:25
just something to make CPU busy
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[])
{
long from, i, j = 20L;
if (argc > 1)
from = atol (argv[1]);
@mirekfranc
mirekfranc / decimal.cpp
Created November 2, 2015 15:09
small decimal sanity testcase
#include <iostream>
#include <decimal/decimal>
using namespace std;
using namespace decimal;
int main ()
{
decimal32 a (1.5);
decimal64 b (2.2);
@mirekfranc
mirekfranc / parse_bug_numbers.py
Last active October 23, 2015 16:50
prefix the line with bugzilla url
import re, sys
r = re.compile ('\d\d\d\d+')
with open ("b.list", "r") as f, open ("b.list.new", "w") as o:
n = 1
for l in f:
m = r.search (l)
if m:
o.write ('{0:4}: https://gcc.gnu.org/bugzilla/show_bug.cgi?id={1} # {2}'.format (n, m.group (0), l))
@mirekfranc
mirekfranc / pre-commit.sh
Created October 21, 2015 22:53
remove trailing whitespace before commit
#!/bin/bash
# pre-commit hook for removing whitespace
git diff-index --cached --name-only HEAD | { while read -r f
do
[[ -d .git ]] || cd $(git rev-parse --show-cdup)
sed -i 's/\s*$//' "$f"
git add "$f"
done; }
@mirekfranc
mirekfranc / disassembly.txt
Last active October 12, 2015 13:28
./protected.sh GOPLT
# protected -O3
0000000000000710 <bar>:
710: 48 8d 3d 0e 00 00 00 lea 0xe(%rip),%rdi # 725 <_fini+0x9>
717: e9 b4 fe ff ff jmpq 5d0 <puts@plt>
# default -O3
0000000000000730 <bar>:
730: e9 cb fe ff ff jmpq 600 <foo@plt>
735: 0f 1f 00 nopl (%rax)
@mirekfranc
mirekfranc / red_shirt_process.sh
Last active September 30, 2015 14:45
for a testcase to be more likely selected by oom killer...
echo 1000 > /proc/self/oom_score_adj
exec $@