This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'levenshtein' | |
| content = ARGF.read.split(/[^\w]/).grep(/^\w+$/) | |
| h = {} | |
| content.each do |c| | |
| h[c] ||= 0 | |
| h[c] += 1 | |
| end | |
| words = h.keys |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| " 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Fixnum | |
| def <(right) | |
| super ? right : nil | |
| end | |
| def >(right) | |
| super ? right : nil | |
| end | |
| def >=(right) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ < 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| AllCops: | |
| TargetRubyVersion: 2.3 | |
| Style/ConditionalAssignment: | |
| EnforcedStyle: assign_inside_condition | |
| Enabled: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def foo | |
| tap do | |
| $_ = 3 | |
| p $_ | |
| end | |
| p $_ | |
| end | |
| foo | |
| puts '-------------' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/ruby b/rails | |
| index bf5e5a1..79ff999 100644 | |
| --- a/ruby | |
| +++ b/rails | |
| @@ -1,3 +1,4 @@ | |
| +` | |
| ^ | |
| <=> | |
| =~ | |
| @@ -8,47 +9,77 @@ |