Skip to content

Instantly share code, notes, and snippets.

View yaotti's full-sized avatar

Hiroshige Umino yaotti

View GitHub Profile
#!/bin/sh
sid=`pgrep screen`
if [ `echo $sid | wc -l` = 1 ];then
cd /home/yaotti/tools/tiarra
screen -S $sid -p 0 -X exec /home/yaotti/tools/tiarra/tiarra --config=/home/yaotti/tools/tiarra/tiarra.conf
fi
#!/usr/bin/env perl
use strict;
use warnings;
my $hexnum = shift || '0xdeadbeaf';
$hexnum =~ /0x([0-9a-fA-F]+)/ or die 'not hex number';
my $body = $1;
my $result = 0;
my $cnt = 0;
for (reverse split //, $body) {
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <iostream>
#include <cmath>
using namespace std;
// calculate fib(n+2)-1
int fib_total(long long int val1, long long int val2, long long int n) {
if (n < 1) return val2 - 1;
return fib_total(val2, val1+val2, n-1);
#include <iostream>
#include <cmath>
using namespace std;
long long int fib(int n)
{
double sqrt5 = sqrt(5);
return (1.0 / sqrt5) * (pow((1.0+sqrt5) / 2, n) - pow((1.0-sqrt5) / 2, n));
}
#!/usr/bin/env perl
use strict;
use warnings;
use Linux::Pid qw/getpid getppid/;
my $pid = fork;
if( $pid ){
warn "Parent: " . getpid();
warn "Parent's parent: " . getppid();
exit;
package debug;
use strict;
use warnings;
use Data::Dumper;
BEGIN {
*CORE::GLOBAL::warn = sub {
my ($package, $file, $line) = caller;
ref $_[0] ? CORE::warn(Data::Dumper::Dumper(@_), sprintf(" at %s line %d\n", $file, $line)): CORE::warn @_, sprintf(" at %s line %d\n", $file, $line);
};}
#!/usr/bin/env perl
use strict;
use warnings;
use Coro;
use Coro::Semaphore;
sub p { warn shift; }
my $sem = new Coro::Semaphore 1; # 0: locked, 1: unlocked (default)
p sprintf 'semaphores: %d', $sem->count;
;; for Mac
;; return to terminal after edit files via emacsclient
(defadvice server-edit (after server-edit-and-return)
(do-applescript
(format "
tell app \"Terminal\"
activate
end tell")))
(ad-activate-regexp "server-edit-and-return")
$ history -n 1 | awk {'print $1'} | sort | uniq -c | sort -k1 -rn | head
1275 sudo
910 ls
908 git
835 rm
808 gg
773 gc
727 cp
678 less
615 make