Thursday, November 6, 2008

perl work with growl

Excerpt from
http://oreilly.com/catalog/9780596526740/toc.html
and
http://search.cpan.org/~cnandor/Mac-Growl-0.67/lib/Mac/Growl.pm

A quick method to post notification to Growl.


#!/usr/bin/env perl

use warnings;
use strict;

use Mac::Growl qw(:all);

Mac::Growl::RegisterNotifications(
# register your application in Growl before posting.
# just one time enough.
'growlalert', # app name
['alert'], # all notification
['alert'], # default notification
);

Mac::Growl::PostNotification(
# post notification to Growl
"growlalert", # app name
"alert", # notification type
"this is a title", # alert title
"this is a description", # alert content
);


 

Monday, October 13, 2008

push in scheme


01 (define push
02 (lambda (element stack)
03 (append stack (cons element '()))))
04
05 (push 'd '(a b c)) ; => (a b c d)


Though putting element before stack is a little weird XD.

 

Wednesday, September 17, 2008

tip in mpb

Defect mode always appears around the number of super lattice cells, so set num-bands automatically is a better way if we do not confirm how big the supper lattice.

e.g.
(define-param supercell-x 5)
(define-param supercell-y 11)
(set! num-bands (+ 2 (* supercell-x supercell-y)))


 

Saturday, September 6, 2008

emacs.app

the default color scheme looks more beautiful in emacs.app. :D

From temp

Wednesday, September 3, 2008

expand tab

emacs: (setq-default indent-tabs-mode nil)
vim: set expandtab

but I could not find the setting in textmate :~

 

Sunday, August 31, 2008

Array.split


01 class Array
02 def split(part)
03 num = self.length/part.to_i
04 result = Array.new
05 for row in 0..(part-1)
06 result[row] = self[num*row...num*(row+1)]
07 end
08 result
09 end
10 end

a = [1,2,3,4,5,6,7,8,9]
a.split(3).inspect # => [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

 

Monday, August 11, 2008

build source package in debian

just for memo
need build-essential fakeroot

$ apt-get build-dep package
$ fakeroot apt-get source -b package

then wait for compilation.

$ dpkg -i package

so happy not messing with tarball

 

Sunday, August 10, 2008

safari history search

Using the shortcut Command-? for searching help to search history is a very good hacking.

 

Wednesday, August 6, 2008

ls_color in bsd style

for xterm-color, set in .profile

alias ls="ls -G"
export LSCOLORS="ExFxCxDxBxEGEDABAGACAD"

make it more beautiful.

 

Sunday, August 3, 2008

set volume in max os x terminal

Costing my much time to search, It seems no command for setting volume in Leopard. When I used AppleScript to do this, I didn't know why the executable file cause some problem in screen. But Ruby's applescript gem do this good. I saved below content as /usr/bin/volume, and then I could use $ volume [1-7 as volume] to set Leopard's Volume from remote.

01 #!/usr/bin/env ruby
02
03 require 'rubygems'
04 require 'applescript'
05
06 AppleScript.execute("set volume #{ARGV[0]}")


update 2008/8/3

the way using applescript interpreter is $ osascript -e "set volume [1-7]"
or call in script by shebang.

01 #!/usr/bin/osascript
02
03 set volume [1-7]