Skip to content

Instantly share code, notes, and snippets.

View spiculator's full-sized avatar

Sergey Redin spiculator

View GitHub Profile
@spiculator
spiculator / resolve-kernel-trace-with-system-map.pl
Created March 4, 2013 11:52
resolve kernel trace with system map
#!/usr/bin/perl -w
use strict;
use FindBin;
1 == @ARGV or die "Usage: cat kernel-call-trace.txt |$FindBin::Script <system-map-file>\n";
my $map = shift @ARGV;
my (@address, @type, @name);
open MAP, "<", $map or die $!;
while(<MAP>) {
#include <stdio.h>
#include <sys/time.h>
main() {
struct timeval tv;
gettimeofday(&tv, NULL);
printf("Content-Type: text/plain\n\n%d.%06d\n", tv.tv_sec, tv.tv_usec);
}
@spiculator
spiculator / convert-livelib-to-zim-wiki.pl
Created August 19, 2012 15:14
convert livelib.ru page like http://www.livelib.ru/reader/teak/print into zim-wiki format
#!/usr/bin/perl -w
use strict;
use utf8;
use encoding "utf8";
binmode( STDIN, ':utf8' );
binmode( STDOUT, ':utf8' );
use Encode qw(decode_utf8);
my @month_names = qw/Январь Февраль Март Апрель Май Июнь Июль Август Сентябрь Октябрь Ноябрь Декабрь/;
my %months = ();
@spiculator
spiculator / bashteegrep.txt
Created March 18, 2012 20:30
tee grep with pure bash
sergey@eeeteak:/tmp$ while read; do if [[ "$REPLY" =~ isok ]]; then echo "$REPLY" >>/dev/fd/4; else echo "$REPLY" >>/dev/fd/5 ; fi; done 4>/tmp/passed 5>/tmp/failed
sadjhb
dsfgvjhbasdf
kjvhdffvzsed
jhszdfisokasf
sdfjhvasdfg
kjhgvgsedfgvaweesisok
zdsjhb
sergey@eeeteak:/tmp$ cat /tmp/passed
jhszdfisokasf
@spiculator
spiculator / teegrep.txt
Created March 18, 2012 20:07
tee grep with awk
sergey@eeeteak:/tmp$ awk '{ if( /isok/ ) {print $0 >> "/dev/fd/4"} else {print $0 >> "/dev/fd/5"} }' 4>/tmp/passed 5>/tmp/failed
dgshbkl,hb
sdfbjh,,jhbdfv
cfzxmgvzxfisoksxfgvjhvb
dxfmgvmhv
dsxvjhbisok
sergey@eeeteak:/tmp$ cat /tmp/failed
dgshbkl,hb
sdfbjh,,jhbdfv
dxfmgvmhv
@spiculator
spiculator / getmul.pl
Created February 11, 2012 06:34
getmul
#!/usr/bin/perl
use warnings;
use strict;
sub getmul($$$$) {
my $num = shift;
my $num2 = $num % 100;
my $last = $num2 % 10;
my $case = $num2 > 4 && $num2 < 21 ? 2 :
1 == $last ? 0 :
$last > 1 && $last < 5 ? 1
@spiculator
spiculator / mypow10.c
Created October 25, 2011 13:43
power 10
int mypow10(int a)
{
int a2 = a * a;
int a4 = a2 * a2;
int a5 = a4 * a;
return a5 * a5;
}