Skip to content

Instantly share code, notes, and snippets.

@ainoya
ainoya / lock.rb
Created December 5, 2014 11:38
lock while building image
# Build Docker image and run it as a container.
def up
begin
lock = File.open('/var/lock/subsys/pool.lock', 'w')
if lock.flock(File::LOCK_EX | File::LOCK_NB )
image_id = build
container_id = run image_id
confirm_running container_id
else
@ainoya
ainoya / gist:3b57826c80c7dba12902
Created January 26, 2015 08:42
stash_slack.sh
#!/bin/bash
echo "Notify commits to slack"
channel=$2
icon=$4
payload="payload={\"channel\":\"$channel\",\"username\":\"webhookbot\",\"text\":\"Push on ${STASH_REPO_NAME} by ${STASH_USER_NAME} <$STASH_USER_EMAIL>\",\"icon_emoji\":\"$icon\",\"attachments\":["
while read from_ref to_ref ref_name; do
message=`git log --format=%B -n 1 ${to_ref}`
title="[$STASH_REPO_NAME:$ref_name] <$3/commits/$to_ref|$to_ref>: $message"
@ainoya
ainoya / epv.py
Last active August 14, 2023 09:04
extract phrasal verbs
#!/usr/bin/env python
import pprint
import json
import corenlp
corenlp_dir = "/tmp/stanford-corenlp-full-2013-06-20"
parser = corenlp.StanfordCoreNLP(corenlp_path=corenlp_dir)
result_json = json.loads(parser.parse("hey shut down the station"))
pprint.pprint(result_json)
@ainoya
ainoya / application.conf
Created May 29, 2015 02:06
play2.4/slick3/mysql database configuration
slick {
default="infra.dao.*"
dbs {
default {
driver="slick.driver.MySQLDriver$"
db {
driver=com.mysql.jdbc.Driver
url="jdbc:mysql://127.0.0.1:3306/dev?useUnicode=true&characterEncoding=UTF-8"
@ainoya
ainoya / SKAction+Extensions.swift
Created July 12, 2015 18:46
Swift Extensions for SKAction.playSoundFileNamed() with custom volume
// reference: https://github.com/pepelkod/iOS-Examples/blob/master/PlaySoundWithVolume/PlaySoundWithVolumeAction.m
import SpriteKit
public extension SKAction {
public class func playSoundFileNamed(fileName: String, atVolume: Float, waitForCompletion: Bool) -> SKAction {
let nameOnly = fileName.stringByDeletingPathExtension
let fileExt = fileName.pathExtension
@ainoya
ainoya / extensions.swift
Created July 13, 2015 06:14
Iterate the values of Enum type with Swift1.2
enum SoundEffectType:Int {
case Whitsle = 0,
Finish,
CDThree,
CDTwo,
CDOne,
CDGo,
Good,
Great,
Excellent,
@ainoya
ainoya / wait.rb
Created July 19, 2015 17:30
wait
def wait? &block
i = 1
while i < 5 do
block.call(i)
sleep 0.2
i = i+1
end
end
@ainoya
ainoya / select.go
Created August 12, 2015 11:28
golang select receives close signal anyway
package main
import "fmt"
func main() {
var a chan struct{}
fmt.Println("Hello, playground")
a = make(chan struct{})
@ainoya
ainoya / parallel_appium.rb
Created July 28, 2016 06:46
start appium server in parallel
require 'selenium-webdriver'
require 'logger'
class AppiumServer
def initialize(opts = {})
@port = Selenium::WebDriver::PortProber.above(3000)
@log = ::Logger.new(STDOUT)
end
def start
@ainoya
ainoya / simple_daemon_restarts_regularly.rb
Created July 28, 2016 06:49
damonize process and restart regularly
#!/usr/bin/env ruby
require 'rufus-scheduler'
$stdout.sync = true
scheduler = Rufus::Scheduler.new
def exec_command(cmd)
IO.popen(cmd) do |io|
while (line = io.gets) do