Skip to content

Instantly share code, notes, and snippets.

View luikore's full-sized avatar

luikore luikore

View GitHub Profile
@luikore
luikore / slim_stimulus.rb
Created June 30, 2020 09:39
Enable some shortcuts for stimulus: @controller, @target, @click
# enable the template engine shortcuts
Slim::Engine.set_options shortcut: {'&' => {tag: 'input', attr: 'type'}, '#' => {attr: 'id'}, '.' => {attr: 'class'}}, sort_attrs: false
# enable stimulus shortcuts:
# - @controller="foo"
# - @target="bar"
# - @click...="#action"
module Slim
class Parser
@luikore
luikore / poker_hands.rb
Last active September 1, 2016 03:29
Ruby Solution to Poker Hands Dealer Problem: https://ruby-china.org/topics/30918
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
@luikore
luikore / design.md
Created November 13, 2015 08:38
Nabla syntax

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 September 21, 2015 11:26
collect cols
// 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 September 29, 2022 07:50
To Chinese Number
# 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 August 29, 2015 14:15
Regexp to Match Fullwidth Characters
# 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 August 29, 2015 14:12
markdown on v2ex

gist is...

the way to markdown

  • and so you can edit/delete post
@luikore
luikore / china_id_verify.rb
Last active August 29, 2015 14:12
Verify Chinese ID card number
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 October 31, 2014 07:04
shrink pdf size
# 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 August 29, 2015 14:07
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console