Skip to content

Instantly share code, notes, and snippets.

@naoty
naoty / testing_mysql_with_active_record.rb
Last active July 17, 2022 13:55
Boilerplate code to test MySQL behavior with ActiveRecord
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'minitest'
gem 'activerecord', require: 'active_record'
gem 'mysql2'
end
@naoty
naoty / ghpr
Created July 29, 2021 05:57
ghとfzfでCLIからPull Requestを開くやつ
#!/bin/bash -e
id=$(gh pr list --search "involves:@me" | cut -f 1-2 | fzf --reverse | cut -f 1)
gh pr view ${id} --web
@naoty
naoty / eager_load_with_select.rb
Created December 16, 2020 09:35
eager_loadでSELECTするカラムを絞れるか検証する
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'activerecord'
gem 'sqlite3'
end
require 'active_record'
@naoty
naoty / hatena2md.rb
Last active May 2, 2021 12:28
はてなブログからエクスポートしたMT形式のファイルをMarkdownファイルに分割するやつ
require "bundler/inline"
require "pathname"
require "time"
require "uri"
abort "[USAGE]: hatena2md <exported file> <output dir>" if ARGV.length < 2
exported_file_path = ARGV[0]
output_dir = Pathname.new(ARGV[1])
output_dir.mkpath unless output_dir.exist?
@naoty
naoty / typescriptreact.json
Last active September 5, 2018 06:15
VSCode snippet for react component in TypeScript
{
"Functional Component": {
"prefix": "_functional",
"body": [
"import * as React from \"react\";",
"",
"export default () => (",
" ${1:component}",
");"
]
@naoty
naoty / ssm2env
Created April 24, 2018 05:59
Create .env file from SSM parameter store
#!/bin/bash -e
aws ssm get-parameters-by-path \
--path "/myapp/" \
--with-decryption \
--query "Parameters[*].[Name,Value]" \
--output text |
while read line
do
name=$(echo ${line} | cut -f 1 -d ' ' | sed -e 's/\/myapp\///g')
set-option -g prefix C-t
bind-key C-v split-window -h -c "#{pane_current_path}"
bind-key C-s split-window -v -c "#{pane_current_path}"
bind-key -r C-k select-pane -U
bind-key -r C-j select-pane -D
bind-key -r C-l select-pane -U
bind-key -r C-h select-pane -D
" Basic settings
set nocompatible
" Edit
set fileencodings=ucs-bom,utf-8,iso-2022-jp,sjis,cp932,euc-jp,cp20932
set tabstop=4
set softtabstop=0
set shiftwidth=4
set expandtab
import Foundation
class Observer: NSObject {
private let recipe: Recipe
init(recipe: Recipe) {
self.recipe = recipe
}
deinit {
import Foundation
let utcFormatter = DateFormatter()
utcFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
utcFormatter.locale = Locale(identifier: "en_US_POSIX")
utcFormatter.timeZone = TimeZone(abbreviation: "UTC")
let jstFormatter = DateFormatter()
jstFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
utcFormatter.locale = Locale(identifier: "en_US_POSIX")