Skip to content

Instantly share code, notes, and snippets.

View pocke's full-sized avatar
⌨️
Pocke is typing...

Masataka Pocke Kuwabara pocke

⌨️
Pocke is typing...
View GitHub Profile
require 'levenshtein'
content = ARGF.read.split(/[^\w]/).grep(/^\w+$/)
h = {}
content.each do |c|
h[c] ||= 0
h[c] += 1
end
words = h.keys
@pocke
pocke / diff_for_each.rb
Last active October 19, 2016 12:58
Diff between for and each method in Ruby (2.3.1)
p defined? x # => nil
p defined? y # => nil
[1,2,3].each do |x|
x
y = 1
end
p defined? x # => nil
p defined? y # => nil
require 'benchmark'
Benchmark.bm 10 do |x|
x.report('=~'){ 10000000.times{/a/ =~ 'a'; /b/ =~ 'a' }}
x.report('==='){ 10000000.times{/a/ === 'a'; /b/ === 'a' }}
x.report('match'){ 10000000.times{/a/.match('a'); /b/.match('a') }}
x.report('match?'){10000000.times{/a/.match?('a'); /b/.match?('a') }}
end
@pocke
pocke / denite-op.vim
Last active November 11, 2016 01:17
Denite && Operator がこんな形だとどうだろう、という妄想
" OpFuncName が定義される
" Denite によって提供される
call denite#get_opfunc('file_rec -some-arg', 'OpFuncName')
" Operator を定義する
" ユーザーが vim-operator-user などの任意のプラグイン or プラグインに依存しない形で扱える
call operator#user#define('denite-file_rec', 'OpFuncName')
map <Space>uo <Plug>(operator-denite-file_rec)
class Fixnum
def <(right)
super ? right : nil
end
def >(right)
super ? right : nil
end
def >=(right)
@pocke
pocke / tweets.zsh
Created November 21, 2016 11:51
沢山ツイートしている単語を知る
$ < p_ck_161121.csv |
ruby -rcgi -rcsv -e '
CSV.parse($<){|row|
puts CGI.unescapeHTML(row[2].gsub(/\@[a-zA-Z0-9_]+/, "").gsub(%r!https?://\S+!, ""))
}' | head -12000 |
docker run --rm -i docker-mecab-neologd:latest |
grep '\s名詞,' | grep -v '語幹' | grep -v '非自立' | grep -v -E '^ー+\s' | cut -f 1 | ruby -pe '$_.downcase!' | sort | grep -v '^.$' |
ruby -e '
c = 1; p = nil;
while gets
require 'benchmark'
Benchmark.bm(20) do |x|
array = (1..100000).map { rand(100000) }
x.report('10000 max_by'){100.times{array.max_by{|x| x.to_s}}}
x.report('10000 max'){ 100.times{array.max{|a, b| a.to_s <=> b.to_s }}}
x.report('10000 min_by'){100.times{array.min_by{|x| x.to_s}}}
x.report('10000 min'){ 100.times{array.min{|a, b| a.to_s <=> b.to_s }}}
end
AllCops:
TargetRubyVersion: 2.3
Style/ConditionalAssignment:
EnforcedStyle: assign_inside_condition
Enabled: true
def foo
tap do
$_ = 3
p $_
end
p $_
end
foo
puts '-------------'
diff --git a/ruby b/rails
index bf5e5a1..79ff999 100644
--- a/ruby
+++ b/rails
@@ -1,3 +1,4 @@
+`
^
<=>
=~
@@ -8,47 +9,77 @@