Skip to content

Instantly share code, notes, and snippets.

View windwiny's full-sized avatar

windwiny windwiny

View GitHub Profile
#!/usr/bin/env ruby
=begin
ruby win32ole common functions
OLE excel object: Application, Workbook, Worksheet, Range, Cells , ...
Demo howto find them, get/set value/style
used other ruby script import it:
require 'rbexcelbase' # copy this to C:\ruby2\lib\ruby\2.3.0\rbexcelbase.rb or
@windwiny
windwiny / rbexcel.rb
Created November 1, 2021 16:45
ruby win32old on excel, replace VBA
#!/usr/bin/env ruby
=begin
Use ruby/win32ole on excel application, replace VBA
=end
require 'pry'
require 'tk'
if Gem.win_platform?
require 'win32ole'
#!/usr/bin/env ruby
require 'pp'
require 'optparse'
options = {:can_skip_newerbundle=>true}
OptionParser.new do |opts|
opts.banner = "Usage: gem-ext-compile-v2.rb [options]"
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
options[:verbose] = v
@windwiny
windwiny / mutex.sh
Last active May 16, 2017 14:24
shell create pid file , avoid script running multiple times
#!/bin/sh
## create pid file , avoid script running multiple times
### every script gen a unique UUID
UUID=ACD35429D76148978480EA945653D112
pid_file=/tmp/${UUID}.pid
if [[ -f $pid_file ]]; then
lpid=$(head -1 $pid_file)
if [[ ! -z $lpid ]]; then
@windwiny
windwiny / fork.c
Created March 28, 2017 13:00 — forked from Cr4sh/fork.c
fork() for Windows
/*
* fork.c
* Experimental fork() on Windows. Requires NT 6 subsystem or
* newer.
*
* Copyright (c) 2012 William Pitcock <nenolod@dereferenced.org>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
@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
@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 / 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: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 / gist:c85dd8c2571b4374f874
Last active October 24, 2023 05:55
Linux 基于策略的路由(Linux Policy Routing)(Linux 多个网卡使用相同网段的IP地址设置)
----
Linux 基于策略的路由(Linux Policy Routing)
Linux 有传统的基于数据包目的地址的路由算法,和新的基于策略的路由算法
新算法优点:支持多个路由表,支持按数据报属性(源地址、目的地址、协议、端口、数据包大小、内容等)选择不同路由表
# 查看规则命令,后面可跟其它参数,默认为 show(list) 显示全部
ip rule