Skip to content

Instantly share code, notes, and snippets.

View yaotti's full-sized avatar

Hiroshige Umino yaotti

View GitHub Profile
@yaotti
yaotti / git-pushh
Created February 25, 2010 12:45
notify git-push had succeed or failure with growl
#!/bin/zsh
git push $@
if [ $? = 0 ]; then
growlnotify Succeed -a GitX -m 'successfully pushed'
else
growlnotify Fail -a CyberDuck -m 'git push failed'
fi
(defun copy-current-file-name ()
(interactive)
(let ((name (buffer-file-name)))
(shell-command (format "echo %s | pbcopy" name))
(message (format "copied: %s" name))))
;; open the current (file's) directory in Terminal.app
(defun mac-open-terminal ()
(interactive)
(let ((dir ""))
(cond
((and (local-variable-p 'dired-directory) dired-directory)
(setq dir dired-directory))
((stringp (buffer-file-name))
(setq dir (file-name-directory (buffer-file-name))))
)
$ 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
;; 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")
#!/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;
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 Linux::Pid qw/getpid getppid/;
my $pid = fork;
if( $pid ){
warn "Parent: " . getpid();
warn "Parent's parent: " . getppid();
exit;
#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));
}
#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);