Skip to content

Instantly share code, notes, and snippets.

Avatar

luikore luikore

View GitHub Profile
@luikore
luikore / slim_stimulus.rb
Created Jun 30, 2020
Enable some shortcuts for stimulus: @controller, @target, @click
View slim_stimulus.rb
# 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 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 Sep 29, 2022
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