Skip to content

Instantly share code, notes, and snippets.

@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')
@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 / position.rb
Last active November 29, 2021 05:26
ある緯度経度で指定された地点からある距離と方向に移動した後の緯度経度を計算する
here = Position.new(lat_A, lng_B)
# 90度方向に100m移動したあとの地点
there = here.move(distance: 100, heading: 90)
@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 / 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 / seeds.rb
Created October 6, 2011 10:52
seeds file which inserts csv data in a specific directory into mongodb
require 'csv'
require 'mongo'
path = "#{Rails.root}/db/seeds/"
db = Mongo::Connection.new.db('database_name')
Dir.open(path).each do |f|
if f.match(/(.*)\.csv$/)
col = db.collection($1)
col.remove
@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 / 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 / Playground.swift
Last active April 6, 2018 23:42
A playground to display a table view controller on a navigation controller
import XCPlayground
import UIKit
struct Pokemon {
let id: UInt
let name: String
}
class PokedexViewController: UITableViewController {
let pokemons: [Pokemon] = [
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