Skip to content

Instantly share code, notes, and snippets.

View spiculator's full-sized avatar

Sergey Redin spiculator

View GitHub Profile
@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;
}
@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 / 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 / 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 / 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 = ();
#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 / 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>) {
@spiculator
spiculator / rsync-3.0.6-sleepflag.patch
Created June 12, 2013 08:25
make rsync sleep every 10 seconds
diff -Naur rsync-3.0.6/Makefile.in rsync-3.0.6-sleepflag/Makefile.in
--- rsync-3.0.6/Makefile.in 2009-04-11 03:24:49.000000000 +0400
+++ rsync-3.0.6-sleepflag/Makefile.in 2010-08-05 22:05:32.000000000 +0400
@@ -35,7 +35,7 @@
OBJS1=flist.o rsync.o generator.o receiver.o cleanup.o sender.o exclude.o \
util.o main.o checksum.o match.o syscall.o log.o backup.o
OBJS2=options.o io.o compat.o hlink.o token.o uidlist.o socket.o hashtable.o \
- fileio.o batch.o clientname.o chmod.o acls.o xattrs.o
+ fileio.o batch.o clientname.o chmod.o acls.o xattrs.o sleeper.o
OBJS3=progress.o pipe.o
#!/usr/bin/perl -w
use warnings;
my $i = 1;
my @in = <>;
while(@in) {
local $_;
$_ = shift @in or die;
s/^(\d+)(\r?)$/$i$2/ or die "number of line expected: $_";
package main
import "fmt"
import "code.google.com/p/go-tour/tree"
// Walk walks the tree t sending all values
// from the tree to the channel ch.
func Walk(t *tree.Tree, ch chan int) {
if t.Left != nil {
Walk( t.Left, ch )