Skip to content

Instantly share code, notes, and snippets.

View nisshiee's full-sized avatar

Hirokazu Nishioka nisshiee

View GitHub Profile
import Apollo
public struct KCal: JSONDecodable, JSONEncodable {
let value: Double
public init(jsonValue value: Apollo.JSONValue) throws {
guard let value = value as? Double else { throw JSONDecodingError.wrongType }
guard (value.isZero || value.isNormal) && value >= 0.0 else { throw JSONDecodingError.couldNotConvert(value: value, to: KCal.self) }
self.value = value
}
@nisshiee
nisshiee / cluster.tf
Created April 14, 2017 13:44
TerraformでAuroraを立てる
resource "aws_rds_cluster" "default" {
cluster_identifier = "${var.service}-${var.name}-${var.env}"
master_username = "${var.username}"
master_password = "${var.password}"
backup_retention_period = 5
preferred_backup_window = "19:30-20:00"
preferred_maintenance_window = "wed:20:15-wed:20:45"
port = 3306
vpc_security_group_ids = ["${var.security_group_ids}"]
db_subnet_group_name = "${var.subnet_group_name}"
@nisshiee
nisshiee / nightly-build.js
Created October 3, 2016 09:24
AWS Lambda Script for CircleCI nightly build
var projects = [
['githubuser/repo1', 'circleci_api_token_for_repo1'],
['githubuser/repo2', 'circleci_api_token_for_repo2'],
];
var https = require('https')
var callApi = function(method, path, body, callback) {
var options = {
hostname: 'circleci.com',
@nisshiee
nisshiee / subl
Created August 4, 2016 08:27
ちょっと賢いsublコマンド
#!/usr/bin/env ruby
SUBL_COMMAND = '/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl'
require 'pathname'
def base_dir
return @base_dir if @base_dir
return @base_dir = Pathname.new('.') if ARGV.empty?
input = Pathname.new(ARGV[0])
@nisshiee
nisshiee / open_iterm2
Created June 20, 2016 01:52
Alfredから新しいiterm2ウィンドウを開くApple Script
on alfred_script(q)
tell application "iTerm" to (create window with default profile)
end alfred_script
@nisshiee
nisshiee / index.js
Created June 14, 2016 07:49
AWS LambdaからCircleCI Buildをキックするスニペット
var https = require('https')
exports.handler = function(event, context) {
var options = {
hostname: 'circleci.com',
path: '/api/v1/project/${user|org}/${project}/tree/master?circle-token=${token}',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
a=readlines.map(&:strip).map(&:each_char).map(&:to_a)
a[0]+=([nil]*100)
puts a[0].zip(*a[1..-1]).flatten.join
#!/bin/sh
remove_dangling() {
echo "Removing dangling images ..."
docker rmi $(docker images -f dangling=true -q)
}
remove_stopped_containers() {
echo "Removing stopped containers ..."
docker rm $(docker ps -qa)
@nisshiee
nisshiee / Prob.scala
Created May 16, 2015 06:31
1時間以内に解けなければプログラマ失格となってしまう5つの問題が話題に(for, while省略)
// http://www.softantenna.com/wp/software/5-programming-problems/
object Prob {
def p1(list: List[Int]) = {
def addRec(list: List[Int], acc: Int): Int = list match {
case Nil => acc
case x :: xs => addRec(xs, acc + x)
}
addRec(list, 0)
}
@nisshiee
nisshiee / Regex.swift
Created November 24, 2014 15:34
とりあえず書き殴ってみたSwiftでの正規表現ユーティリティ。正しさとかパフォーマンスは保証しないよ。
import Foundation
class Regex {
let internalExpression: NSRegularExpression
let pattern: String
init(_ pattern: String) {
self.pattern = pattern
var error: NSError?
self.internalExpression = NSRegularExpression(pattern: pattern, options: nil, error: &error)!