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 / false.swift
Created June 16, 2014 00:10
Swift ===
// Playground - noun: a place where people can play
import Cocoa
let a = [1, 2, 3]
var b = a
a === b // false
@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
@nisshiee
nisshiee / myhttp.scala
Last active February 25, 2016 13:12
Dispatchの文字化け対策
import dispatch._
import com.ning.http.client.filter.{ ResponseFilter, FilterContext }
import scala.collection.JavaConverters._
val MyHttp = Http.configure { builder =>
builder.addResponseFilter(new ResponseFilter {
override def filter(ctx: FilterContext[_]) = {
ctx.getResponseHeaders.getHeaders.get("Content-Type").asScala.toList match {
case "text/html" :: Nil =>
ctx.getResponseHeaders.getHeaders.put("Content-Type", List("text/html; charset=utf-8").asJava)
#!/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)