Skip to content

Instantly share code, notes, and snippets.

@reimai
reimai / .hgrc
Created February 15, 2017 12:11
Make mercurial usable
[extensions]
strip =
rebase =
graphlog =
[alias]
pc = push -b .
pp = pull --update
ab = update --clean .
package rei
import scala.language.experimental.macros
import scala.reflect.macros.blackbox
object Macros {
def ?[T](s: T): Option[T] = macro opt_impl[T]
def opt[T](s: T): Option[T] = macro opt_impl[T]
@reimai
reimai / Fences.hs
Last active October 30, 2016 00:19
comparing haskell with scala on a hackerrank quiz (not only haskell is better looking, it's much faster, yes, I've used List in scala to make it haskell-like); quiz: https://www.hackerrank.com/challenges/john-and-fences
module Main where
main :: IO()
main = getContents >>= putStrLn. show. maxFence 0. map (read:: String -> Int). words. last. lines
type Fence = [Int]
maxFence :: Int -> Fence -> Int
maxFence base [] = base
maxFence base [spike] = base + spike
@reimai
reimai / sshwarn.sh
Created August 18, 2016 18:49
a warning for people who ssh and switch instead of connection as a dev user right away
#!/bin/bash
#warns a user to log in as dev by a key instead of sudo su-ing every time
function get_ps {
pid=$1
what=$2
echo $(ps -o $what -p $pid h | tr -d ' ')
}
function get_parent {
@reimai
reimai / pyzip
Created July 29, 2016 13:16
pack several python scripts to an executable archive
#!/bin/bash
# packs python scripts to an executable, the first script must be the main script
# example: pyzip quotes find_quotes.py dx.py
name=$(basename "$0")
usage="$name name_of_executable main_script.py [other python scripts]"
executable=${1?usage}
main_script=${2?usage}
scripts=${@:3}
@reimai
reimai / tcp_to_fix.sh
Created April 13, 2016 08:16
parse fix quote events messages out of tcp dump to compare receiving and sending time
#!/bin/bash
#turn tcp dump into a text file:
# receiving_time -> fix_msg_sending_time
tcpdump -A -r - | strings | sed 's/\.\([[:digit:]]\+=\)/|\1/g' | sed 's/\.*$//g' | sed 's/^[^|]*|/|/g' | grep 'length\|8=FIX' | grep -B 1 '35=X' | grep -v '^--$' | cut -d ' ' -f 1 | sed 's/.*52=\([^|]*\).*/-> \1/g' | paste - -
# usage:
# $ sudo apt-get install python-numpy
# $ python percentile.py 95 97 99 99.9 < my_file_with_floats
import numpy as np
import fileinput
import sys
lines = []
for line in sys.stdin:
@reimai
reimai / count_N_plot
Last active April 13, 2016 08:18
count smth from logs (not the most effective way, but good enough for the task in hand) and plot it on time axis
$ for m in {32..33}; do for s in {00..59}; do echo "$m$s " `grep -c "$m$s" ~/input`; done; done > ~/out
$ gnuplot -p -e "set xdata time; set timefmt '%M%S'; set format x '%M:%S'; plot '~/out' using 1:2 with points"
@reimai
reimai / clean_target.sh
Created January 26, 2016 13:39
If you're desperate for disk space
for d in `find . -name target`; do find $d -type f; done | xargs rm
@reimai
reimai / nkill
Last active December 21, 2015 18:56
kills whoever is listening on 5005, maven debug sometimes fails to free the damn port
#!/bin/bash
#automated killing of maven debug plugin
#or anyone else if the port was specified
port=${1:-5005}
pid=`lsof -t -i :$port | tr -s ' ' | cut -d ' ' -f 2`
if [[ -z $pid ]]; then
echo "no one to kill 8'("
else
echo "killing process listening on port $port \n`ps hp $pid`"