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
| WITH RECURSIVE foo_ids AS ( | |
| (SELECT foo_id FROM hoges ORDER BY foo_id LIMIT 1) | |
| UNION ALL | |
| SELECT (SELECT foo_id FROM hoges WHERE foo_id > f.foo_id ORDER BY foo_id LIMIT 1) | |
| FROM foo_ids f | |
| WHERE f.foo_id IS NOT NULL | |
| ) | |
| SELECT foo_id FROM foo_ids WHERE foo_id IS NOT NULL |
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 HumanReadableNumber | |
| attr_reader :b, :u_n | |
| def initialize(b:, u_n:) | |
| @b = b | |
| @u_n = u_n | |
| end | |
| def from(a) | |
| _E = [u_n.size-1, Math.log([1, a.abs].max, b).floor].min |
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 ForkSafeProxy < BasicObject | |
| class << self | |
| def unwrap(instance) | |
| instance.__send__(:__value__) | |
| end | |
| end | |
| def initialize(&initializer) | |
| @mutex = ::Thread::Mutex.new | |
| @initializer = initializer |
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 Retryer | |
| class RetryError < StandardError; end | |
| class Backoff | |
| def call(attempt) | |
| raise NotImplementedError | |
| end | |
| end | |
| class ExponentialBackoffAndEqualJitter < Backoff |
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 ThreadPool | |
| def initialize(n) | |
| @n = n | |
| @queue = Thread::SizedQueue.new(@n) | |
| @workers = [] | |
| end | |
| def shutdown | |
| @queue.close | |
| errors = [] |
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 << ENV | |
| # This method behavior is almost same as `ENV.fetch()`, but it returns default value even when the value was empty string. | |
| def fetch2(*args, &block) | |
| key, default = args | |
| value = fetch(*args, &block) | |
| return value if value != '' | |
| raise KeyError, format('key not found: "%s"', key) if args.size == 1 && !block | |
| warn('block supersedes default value argument', uplevel: 1) if args.size == 2 && block | |
| block ? yield(key) : default |
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
| # $ brew install mecab | |
| # $ brew install mecab-ipadic | |
| # $ gem install natto | |
| # $ ruby mecab_sort.rb | |
| # "シュジンコウ" | |
| # "ジョウシャ" | |
| # "ジョウシャ" | |
| # "コウムイン" | |
| # "シュジンコウ" | |
| # "コウムイン" |
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 SimpleMutex { | |
| _lock: boolean; | |
| _resolves: Array<() => void>; | |
| constructor() { | |
| this._lock = false; | |
| this._resolves = []; | |
| } | |
| async synchronize(callback: () => Promise<any>) { |
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
| package main | |
| import ( | |
| "encoding/json" | |
| "fmt" | |
| "reflect" | |
| ) | |
| // Example: | |
| // |
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
| $HostIP = [IPAddress]"0.0.0.0" | |
| function Invoke-WSL-Command([String]$Cmd) { | |
| while (1) { | |
| $Result = wsl bash -c $Cmd | |
| if (!$?) { | |
| Write-Debug "Retry...: $Cmd" | |
| Start-Sleep 1 | |
| continue | |
| } |
NewerOlder