Skip to content

Instantly share code, notes, and snippets.

View yaotti's full-sized avatar

Hiroshige Umino yaotti

View GitHub Profile
;; 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))))
)
(defun copy-current-file-name ()
(interactive)
(let ((name (buffer-file-name)))
(shell-command (format "echo %s | pbcopy" name))
(message (format "copied: %s" name))))
@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 c++-debug-print()
(interactive)
(let* ((var-str (read-from-minibuffer "variables (space separated): "))
(vars (split-string var-str))
(dp "cout"))
(dolist (v vars)
(setq dp (concat dp " << " v " << \", \"")))
(insert (concat dp " << endl;"))))
#!/usr/bin/env perl
use strict;
use warnings;
use WWW::Mechanize;
use Config::Pit;
my $mech = WWW::Mechanize->new();
my $login_url = "http://lang-8.com/login";
my $response = $mech->get($login_url);
my ( $mail, $password ) = do { @{ pit_get("lang-8.com") }{qw/mail password/} };
@yaotti
yaotti / GET.pm
Created December 28, 2009 04:41
design pattern: Chain Of Responsibility
package HTTP::RequestHandler::GET;
use base qw/HTTP::RequestHandler/;
use strict;
use warnings;
sub handle_request {
my ($self, $request) = @_;
return if $request->method ne 'GET';
warn 'Requested method is GET: ' . $request->uri;
}
#!/usr/bin/env perl
use strict;
use warnings;
use Hash::MultiValue;
use XXX;
my $h = [a => 1, a => 2, b => 3];
my $hm = Hash::MultiValue->new(@$h);
YYY $hm;
#!/usr/bin/env python
# coding: utf-8
# http://ameblo.jp/programming/entry-10001721422.html
class Cards:
@classmethod
def deal(cls, num, string):
cds = [""]*num
for i in xrange(len(string) / num):
for j in xrange(num):
cds[j] += string[i*num+j]
#!/usr/bin/env python
# coding: utf-8
def fact(x):
def factrec(f, n):
if n < 1:
return 1
else:
return n * (f (f, (n - 1)))
return factrec(factrec, x)
#!/usr/bin/env ruby
commit = ARGV.empty? ? 'HEAD' : ARGV.shift
puts `git log --pretty=oneline #{commit}`.split(/\s+/)[0]