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
#!/bin/bash | |
# This `code` command is for containers, and it can also execute on terminals other than vscode. | |
# If you use it, you must execute it after attaching the container in vscode. | |
# see: VSCode Remote SSHで別Shellからファイルを開く https://zenn.dev/shirou/articles/vscode-remote-open-file | |
export VSCODE_IPC_HOOK_CLI=$(ls -t /tmp/vscode-ipc-*.sock | head -1) | |
CODE=$(ls -t ~/.vscode-server/bin/*/bin/code | head -1) | |
exec ${CODE} $* |
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
#include<type_traits> | |
#include<utility> | |
#include<iostream> | |
template<typename Callable> | |
union storage | |
{ | |
storage() {} | |
std::decay_t<Callable> callable; | |
}; |
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
const cryptoJsHmacSHA256Digest = (key, data) => { | |
const hmac = CryptoJS.HmacSHA256(data, key); | |
const buffer = new ArrayBuffer(hmac.sigBytes); | |
const dv = new DataView(buffer); | |
hmac.words.forEach((v, i) => dv.setInt32(4*i, v, false)); | |
let digest = ''; | |
for (let i = 0; i < hmac.sigBytes; i++) { | |
digest += String.fromCharCode(dv.getUint8(i)); | |
} |
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
const data = [ 102222, 4000032 ]; | |
const buffer = new ArrayBuffer(4 * 2); | |
const dv = new DataView(buffer); | |
data.forEach((v, i) => dv.setInt32(4 * i, v, false)); | |
let result = ''; | |
for (let i = 0; i < 4 * 2; i++) { | |
result += String.fromCharCode(dv.getUint8(i)); | |
} | |
console.log(btoa(result)) |
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
# @see [Rubyの末尾呼び出し最適化を試す - Qiita](https://qiita.com/rsnni/items/8f818f2c2da07896fc7e) | |
RubyVM::InstructionSequence.compile_option = { | |
:tailcall_optimization => true, | |
:trace_instruction => false | |
} | |
RubyVM::InstructionSequence.new(<<-EOS).eval | |
def fact(x) | |
return 1 if x == 0 |
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 Lock | |
def initialize(redis:, key:) | |
@redis = redis | |
@key = key | |
end | |
def lock(timeout_sec: 10) | |
start = Time.now.to_i | |
loop do | |
break yield if @redis.setnx(@key, 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
class Hoge | |
def a | |
1 | |
end | |
end | |
hoge = Hoge.new | |
b = 2 | |
hoge.define_singleton_method(:b){ b } |
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
const sleep = (msec) => new Promise(resolve => setTimeout(resolve, msec)); | |
const main = async () => { | |
console.log(1); | |
await sleep(1000); | |
console.log(2); | |
await sleep(1000); | |
console.log(3); | |
await sleep(1000); | |
}; |
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
# frozen_string_literal: true | |
class HogesController < ApplicationController | |
def destroy | |
hoge = Hoge.find(params[:id]) | |
hoge.destroy! | |
redirect_to hoges_path | |
rescue ActiveRecord::RecordNotDestroyed => e | |
flash[:error] = e.record.errors.full_messages.join("\n") | |
flash[:error] = 'Destroying failed' if flash[:error].blank? |
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 'net/http' | |
# @see https://qiita.com/mechamogera/items/d9ea1cf043e976641a23#rails%E3%81%A7%E7%A2%BA%E8%AA%8D%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95 | |
class Net::HTTP | |
alias :create :initialize | |
def initialize(*args) | |
logger = ActiveSupport::Logger.new(STDOUT) | |
create(*args) | |
self.set_debug_output logger |