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 oo(cylinder, sector) | |
| sector *= 512 | |
| aa=<<-EOS | |
| echo "cylinder: #{cylinder}" | |
| losetup -o #{sector} /dev/loop1 /dev/sdb3 | |
| if [ $? -eq 0 ] ; then | |
| mount /dev/loop1 /tmp/11 2>/dev/null | |
| if [ $? -eq 0 ] ; then | |
| echo "offset #{sector} byte find a file system!!" |
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
| # proc, lambda difference | |
| # Proc.new/proc --> not check parameter, return outside method | |
| # lambda/-> --> check parameter, return just return lambda | |
| p '------------------' | |
| def test_1 | |
| p 'begin' | |
| p1 = Proc.new do |x,y| p [x,y]; return end | |
| p1.call | |
| p '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
| require 'zlib' | |
| def show_lba0(rawdata) | |
| puts "LBA0 ( MBR or PMBR )" | |
| mbr = rawdata[446...512] | |
| if mbr.size!=66 || mbr[-2..-1].unpack('CC') != [0x55, 0xaa] | |
| puts "Not valid MRB part data" | |
| puts | |
| return | |
| 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
| #!/usr/bin/env ruby -w | |
| # OSX 创建内存盘 | |
| puts '================================================================' | |
| cmd="hdiutil attach -nomount ram://1048576" | |
| puts ">>> #{cmd}" | |
| new_disk=`#{cmd}` | |
| new_disk.strip! | |
| puts new_disk |
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
| $load = [] | |
| File.foreach 'LOAD.out' do |line| | |
| if line =~/^\* LOAD:\s*table(.*)$/ | |
| $load << $cc if $cc | |
| tbs = $1.gsub /\s/,'' | |
| $cc=[tbs, -1, -1, -1, -1, -1] | |
| elsif line =~ /Rows read:(.*)$/ | |
| $cc[1] = $1.to_i | |
| elsif line =~ /Loaded:(.*)$/ |
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
| ---- | |
| Linux 基于策略的路由(Linux Policy Routing) | |
| Linux 有传统的基于数据包目的地址的路由算法,和新的基于策略的路由算法 | |
| 新算法优点:支持多个路由表,支持按数据报属性(源地址、目的地址、协议、端口、数据包大小、内容等)选择不同路由表 | |
| # 查看规则命令,后面可跟其它参数,默认为 show(list) 显示全部 | |
| ip rule |
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
| =begin | |
| fdisk -l output sector to CHS | |
| =end | |
| def sect2chs sec | |
| sec = sec.to_i | |
| return "" if sec == 0 |
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 'net/ssh' | |
| host = "the.host" | |
| user = "joe" | |
| su_user = "bob" | |
| password = "password" | |
| su_password = "password" | |
| commands = ['export PS1="\n[$?] [\t] $PS1----\n"', "cd /", "pwd", "ls -l", "exit"] | |
| finished = ("%08x" * 8) % Array.new(8) { rand(0xFFFFFFFF) } |
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
| with timeout of 3600 seconds | |
| tell application "Finder" | |
| set sel to (get selection) | |
| if not sel = {} then --selected file/dir | |
| repeat with f in sel | |
| set _cwd to POSIX path of (folder of f as alias) | |
| exit repeat --first item path | |
| end repeat | |
| else --not select |
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
| class String | |
| # like python expandtabs | |
| def expandtabs tabsize=8 | |
| self.gsub(/[^\r\n]*/) do |line| | |
| next line if line == '' | |
| ss = line.split("\t", -1) | |
| next line if ss.size == 1 | |
| sa = [] | |
| lasts = ss.pop |