This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(){ | |
char s[255]; | |
int n; | |
FILE *fp; | |
fp=fopen(__FILE__,"r"); | |
n=0; | |
while( fgets(s,255,fp) ) { | |
n++; | |
printf("%d %s",n,s); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#http://hi.baidu.com/051156/blog/item/6e6936133ea25a29dc5401be.html | |
ls|while read line | |
do | |
len=`echo $line|awk '{print length($0)}'` | |
name=($line:$len) | |
echo ${name[*]} | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'graphviz_r' | |
g=GraphvizR.new "G" | |
g.start>>g.stop | |
g.output "gvr.png" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'graphviz' | |
class GraphViz | |
class Edge | |
def [](xAttrName) | |
if Hash===xAttrName | |
for name,value in xAttrName | |
self[name]=value | |
end | |
else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d=DATA.read | |
`echo "#{d}"|dot -Tjpg -o a.jpg` | |
exec "firefox a.jpg" | |
__END__ | |
digraph G{ | |
1; | |
2; | |
3; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'erb' | |
d=DATA.read | |
d=ERB.new(d).result | |
`echo "#{d}"|dot -Tjpg -o a.jpg` | |
exec "firefox a.jpg" | |
__END__ | |
digraph G{ | |
a->{<%=(1..10).to_a.join(';')%>} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#mkfifo mm | |
#ruby p.rb & | |
#echo 1 > mm | |
total=0 | |
while(true) | |
d=IO.read('mm') | |
total+=d.to_i | |
p [total] | |
exit if d=~/exit/ | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def run_solr | |
defs = { | |
'jetty.home' => @path, | |
'solr.data.dir' => @path/'solr'/'data' | |
}.map { |k, v| "-D#{k}=#{v}" }.join(' ') | |
cmd = "java -jar #{@path}/start.jar #{@path/'etc'/'jetty.xml'} -classpath #{@path/'lib'} #{defs}" | |
# IO.popen is more portable than fork/exec (i.e. to JRuby) | |
pid = IO.popen(cmd, 'r').pid |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Prints if the input or output is regular or piped | |
puts "INPUT: #{STDIN.tty? ? "regular" : "pipe"}" | |
puts "OUTPUT: #{STDOUT.tty? ? "regular" : "pipe"}" | |
#http://blog.bogojoker.com/2009/04/check-if-your-ruby-script-is-in-a-pipe/ | |
== | |
ruby -e 'puts $stdin.tty?' < rakefile.rb | |
false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
var_dump(posix_isatty(STDIN)); | |
var_dump(posix_isatty(STDOUT)); | |
?> |