Skip to content

Instantly share code, notes, and snippets.

luikore luikore

Block or report user

Report or block luikore

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@luikore
luikore / poker_hands.rb
Last active Sep 1, 2016
Ruby Solution to Poker Hands Dealer Problem: https://ruby-china.org/topics/30918
View poker_hands.rb
PokerHand = Struct.new :player, :cards
class PokerHand
Card = Struct.new :name, :value, :suit
class Card
def initialize name
super name, '23456789TJQKA'.index(name[0]), name[1]
end
def <=> other
value <=> other.value
View design.md

Literals

integer numbers

underlines in between digits will be dropped.

1_234_567

oct numbers have a 0o prefix, so that number parsing won't make mistakes on numbers that start with 0

@luikore
luikore / a.js
Last active Sep 21, 2015
collect cols
View a.js
// run: cscript a.js
inFile = "C:\\Users\\z\\Desktop\\1.xlsx"
inSheet = 1
outFile = "C:\\Users\\z\\Desktop\\2.xlsx"
outSheet = 1
brandCol = 10 // J 列品牌
tradeCol = 12 // L 列行业
subCatCol = 13 // M 列子类
@luikore
luikore / chinese_num.rb
Last active Nov 19, 2018
To Chinese Number
View chinese_num.rb
# http://zh.wikipedia.org/wiki/中文数字
# http://china.younosuke.com/03_013.html
module ChineseNum
extend self
UPPER_ZERO = ''
LOWER_ZERO = ''
UPPER_DIGITS = %w[壹 贰 叁 肆 伍 陆 柒 捌 玖].unshift nil
LOWER_DIGITS = %w[一 二 三 四 五 六 七 八 九].unshift nil
@luikore
luikore / gen_regexp_fullwidth.rb
Last active Aug 29, 2015
Regexp to Match Fullwidth Characters
View gen_regexp_fullwidth.rb
# generate a regexp for match full-width characters
# data from
#
# A ; Ambiguous 不确定
# F ; Fullwidth 全宽
# H ; Halfwidth 半宽
# N ; Neutral 中性
# Na ; Narrow 窄
# W ; Wide 宽
#
@luikore
luikore / test.md
Last active Aug 29, 2015
markdown on v2ex
View test.md

gist is...

the way to markdown

  • and so you can edit/delete post
@luikore
luikore / china_id_verify.rb
Last active Aug 29, 2015
Verify Chinese ID card number
View china_id_verify.rb
def cn_id_verify id, gender=nil
return false if id !~ /\A\d{17}[\dX]\z/i
r = 0
x = 1
id.chars.take(17).reverse_each {|a|
x = (x * 2) % 11
r += a.to_i * x
}
last = (12 - r % 11)
last = 'X' if last == 10
@luikore
luikore / profile.sh
Created Oct 31, 2014
shrink pdf size
View profile.sh
# need to install ghostscript first
pdf-shrink() {
if [[ -e $1 ]]; then
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=$2 $1
else
echo 'usage: pdf-shrink in.pdf out.pdf'
fi
}
@luikore
luikore / 0_reuse_code.js
Last active Aug 29, 2015
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@luikore
luikore / compare.c
Created Jul 13, 2014
pool alloc is about 2.5 times faster and smaller
View compare.c
/*
benchmark with gtime -f "%M"
pool alloc:
time: 0.028571
22331392
malloc:
You can’t perform that action at this time.