Skip to content

Instantly share code, notes, and snippets.

@googya
googya / CountBytes
Created August 20, 2011 07:25
将java的字节转换成二进制串,主要是利用了toBinaryString(int i) 这个函数
public class CountBytes {
public static void main(String[] args) throws IOException {
InputStream in;
if (args.length == 0){
in = System.in;
}else
in = new FileInputStream(args[0]);
byte[] buff = new byte[10];
int total = 0;
@googya
googya / class_module.rb
Created August 21, 2011 02:20 — forked from sergeyenin/class_module.rb
ClassModule
module ClassModule
#all successors excluding self
def successors(klass=self.name.to_s)
descendants = []
begin
ObjectSpace.each_object(class << eval(klass);self;end) do |found|
descendants << found
end
rescue Exception=>e
@googya
googya / irb3.rb
Created January 29, 2012 09:47 — forked from peterc/irb3.rb
irb3 - Run an IRB-esque prompt over multiple Ruby implementations at once using RVM
#!/usr/bin/env ruby
# encoding: utf-8
# irb3 - Runs an IRB-esque prompt (but it's NOT really IRB!) over multiple
# versions of Ruby at once (using RVM)
#
# By Peter Cooper, BSD licensed
#
# Main dependency is term-ansicolor for each impl:
# rvm exec gem install term-ansicolor
@googya
googya / gist:1722335
Created February 2, 2012 08:19
ascii_codes_ruby_way.rb
(1..255).each_with_index do |x,i|
print x, " "*(5-x.to_s.size), x.chr.inspect, "\t"
print "\n" if (i+1)%10 == 0
end
1 "\x01" 2 "\x02" 3 "\x03" 4 "\x04" 5 "\x05" 6 "\x06" 7 "\a" 8 "\b" 9 "\t" 10 "\n"
11 "\v" 12 "\f" 13 "\r" 14 "\x0E" 15 "\x0F" 16 "\x10" 17 "\x11" 18 "\x12" 19 "\x13" 20 "\x14"
21 "\x15" 22 "\x16" 23 "\x17" 24 "\x18" 25 "\x19" 26 "\x1A" 27 "\e" 28 "\x1C" 29 "\x1D" 30 "\x1E"
31 "\x1F" 32 " " 33 "!" 34 "\"" 35 "#" 36 "$" 37 "%" 38 "&" 39 "'" 40 "("
@googya
googya / error.txt
Created August 10, 2012 06:05
error when installing boost
$ brew install boost
==> Downloading http://downloads.sourceforge.net/project/boost/boost/1.49.0/boost_1_49_0.tar.bz2
Already downloaded: /Library/Caches/Homebrew/boost-1.49.0.tar.bz2
==> ./bootstrap.sh --prefix=/usr/local/Cellar/boost/1.49.0 --libdir=/usr/local/Cellar/boost/1.49.0/lib
-n Building Boost.Build engine with toolset darwin...
Failed to build Boost.Build build engine
Consult 'bootstrap.log' for more details
==> Build Environment
HOMEBREW_VERSION: 0.9.2
@googya
googya / home_brew_config.txt
Created August 10, 2012 06:12
homebrew config
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by gc configure 7.2, which was
generated by GNU Autoconf 2.68. Invocation command line was
$ ./configure --disable-debug --disable-dependency-tracking --prefix=/usr/local/Cellar/bdw-gc/7.2 --enable-cplusplus
## --------- ##
## Platform. ##
@googya
googya / bootstrap.log
Created August 10, 2012 06:23
编译bootstrap出现的问题
$ cat bootstrap.log
###
### Using 'darwin' toolset.
###
rm -rf bootstrap
mkdir bootstrap
cc -o bootstrap/jam0 command.c compile.c debug.c expand.c glob.c hash.c hdrmacro.c headers.c jam.c jambase.c jamgram.c lists.c make.c make1.c newstr.c option.c output.c parse.c pathunix.c pathvms.c regexp.c rules.c scan.c search.c subst.c timestamp.c variable.c modules.c strings.c filesys.c builtins.c pwd.c class.c native.c md5.c w32_getreg.c modules/set.c modules/path.c modules/regex.c modules/property-set.c modules/sequence.c modules/order.c execunix.c fileunix.c
expand.c:85:28: warning: field precision should have type 'int', but argument has type 'long' [-Wformat]
printf( "expand '%.*s'\n", end - in, in );
~~^~ ~~~~~~~~
@googya
googya / all_global_variables.rb
Created September 15, 2012 07:58
print all global variables in Ruby
global_variables.each do |x|
print x," ===> ", eval(x.to_s), "\n"
end
@googya
googya / mv_dot_files.rb
Created September 29, 2012 01:09
mv dot-files
require 'fileutils'
REJECTED = ['.', '..', '.git']
(Dir.entries('.') - REJECTED).each do |e|
e.scan /^(\.)(.*)/
FileUtils.mv e, $2 if $1 && File.file?(e)
end
@googya
googya / ord_chr.rb
Created October 18, 2012 01:21
字符与之对应的数字的转换
97.chr => 'a'
'a'.ord => 97