Skip to content

Instantly share code, notes, and snippets.

View windwiny's full-sized avatar

windwiny windwiny

View GitHub Profile
@windwiny
windwiny / gist:7924120
Created December 12, 2013 06:56
search each cylinder , find hard disk lost filesystem
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!!"
@windwiny
windwiny / gist:8313464
Created January 8, 2014 08:17
ruby proc, lambda difference
# 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'
@windwiny
windwiny / showgpt.rb
Last active August 29, 2015 14:01
show hdisk gpt part info
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
@windwiny
windwiny / gist:9726e9827fcb7fc340aa
Last active August 29, 2015 14:02
osx make memory disk
#!/usr/bin/env ruby -w
# OSX 创建内存盘
puts '================================================================'
cmd="hdiutil attach -nomount ram://1048576"
puts ">>> #{cmd}"
new_disk=`#{cmd}`
new_disk.strip!
puts new_disk
@windwiny
windwiny / gist:7483a1c69e3ab683f28c
Created June 27, 2014 12:10
db2 diff db2move export load info
$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:(.*)$/
@windwiny
windwiny / gist:c85dd8c2571b4374f874
Last active October 24, 2023 05:55
Linux 基于策略的路由(Linux Policy Routing)(Linux 多个网卡使用相同网段的IP地址设置)
----
Linux 基于策略的路由(Linux Policy Routing)
Linux 有传统的基于数据包目的地址的路由算法,和新的基于策略的路由算法
新算法优点:支持多个路由表,支持按数据报属性(源地址、目的地址、协议、端口、数据包大小、内容等)选择不同路由表
# 查看规则命令,后面可跟其它参数,默认为 show(list) 显示全部
ip rule
@windwiny
windwiny / gist:f47a628781853629bffa
Last active August 29, 2015 14:10
fdisk -l output sector to CHS
=begin
fdisk -l output sector to CHS
=end
def sect2chs sec
sec = sec.to_i
return "" if sec == 0
@windwiny
windwiny / ex-ssh-pty.rb
Last active February 19, 2016 05:17 — forked from KINGSABRI/ex-ssh-pty.rb
ex. SSH with real PTY
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) }
@windwiny
windwiny / gist:b7b82db26842125e837de9f5d11fc0ec
Created August 7, 2016 08:35
apple script run command on finder in current path
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
@windwiny
windwiny / expandtabs ruby
Last active May 6, 2019 01:47
expandtabs ruby
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