This file contains 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 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 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 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 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 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 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 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 | |
} |
This file contains 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
function Get-Network-From-CIDR([String]$CIDR) { | |
$Parsed = $CIDR -split "/" | |
$IP = [IPAddress]$Parsed[0] | |
$Length = [Int]$Parsed[1] | |
$SubnetMask = [IPAddress](([Math]::Pow(2, 32) - 1) -bxor ([Math]::Pow(2, (32 - $Length)) - 1)) | |
$IP = [IPAddress]($IP.Address -band $SubnetMask.Address) | |
return New-Object PSObject -Property @{ | |
IP = $IP; | |
SubnetMask = $SubnetMask | |
} |
This file contains 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 ( | |
"strings" | |
"github.com/gin-gonic/gin" | |
) | |
// Override HTTP method by `_method` POST body parameter. It's for HTML forms. | |
// @see [bu/gin-method-override: MethodOverride middleware for Gin web framework](https://github.com/bu/gin-method-override) |
NewerOlder