Skip to content

Instantly share code, notes, and snippets.

View yureative's full-sized avatar

Yu Yamanaka yureative

View GitHub Profile
@yureative
yureative / gist:6036297
Last active December 19, 2015 23:39
Problem: The input is a sequence of digits consistent of 0-9. We define "increasing subsequence", when the substring consists of consecutive numbers (NOT including equal). For instance, 0369, 3478, 58. Please write a program (using C, Java, PHP, Ruby or Python) to find the longest increasing subsequence of numbers in the given string.
object IncSeq {
def main(args: Array[String]) {
val result = substrLongestIncSeq("333201299823423234")
println(result) // 0129
}
def substrLongestIncSeq(str: String): String = {
def rec(nums: List[Char], buf: List[Char] = Nil): List[String] =
nums match {
case Nil => Nil
@yureative
yureative / gist:7350443
Created November 7, 2013 07:21
parse email from stdin
def parse_email_from_stdin():
"""標準入力からメールデータを受け取り、解析して
Message オブジェクトにして返す
"""
parser = FeedParser()
for line in sys.stdin:
parser.feed(line)
return parser.close()
@yureative
yureative / .zshrc
Last active August 29, 2015 13:56
Show current git branch and repository name on zsh prompt.
setopt prompt_subst
autoload -Uz vcs_info
zstyle ':vcs_info:*' actionformats \
'%F{5}[%F{2}%b%F{7}:%F{6}%r%F{3}|%F{1}%a%F{5}]%f'
zstyle ':vcs_info:*' formats \
'%F{5}[%F{2}%b%F{7}:%F{6}%r%F{5}]%f'
zstyle ':vcs_info:*' enable git
vcs_info_wrapper() {
sealed abstract class Gender
case object Male extends Gender
case object Female extends Gender
case class Person(name: String, age: Int, gender: Gender)
object CaseMatchExample extends App {
val people = List(
Person("yuu", 25, Male),
Person("mizuki", 27, Female),
@yureative
yureative / fabfile.py
Last active August 29, 2015 14:07
The sample code for executing a command without `sudo` but `su -c`.
import os
from fabric.api import env, puts, sudo, settings
from fabric.colors import cyan
DOMAIN_LIST = '%s/.ssh/config' % os.environ['HOME']
env.use_ssh_config = True
env.disable_known_hosts = True
env.password = 'xxxxxx'
@yureative
yureative / start_docker_containers.sh
Last active August 29, 2015 14:07
/var/lib/cloud/scripts/per-boot/start_docker_containers.sh
#!/bin/bash
# for fig's bug (https://github.com/docker/fig/issues/553#ref-pullrequest-46182758)
export HOME=/root
cd /root && /usr/local/bin/fig start 2>&1 | logger
@yureative
yureative / ec2_tags.rb
Last active August 29, 2015 14:09
A custom Ohai plugin which provides EC2 instance tags
require 'json'
Ohai.plugin(:EC2Tags) do
provides "ec2/tags"
depends "ec2"
collect_data do
region = ec2['placement_availability_zone'].chop
instance_id = ec2['instance_id']
@yureative
yureative / recipe_ec2_tags.rb
Created November 26, 2014 02:44
Distribute Custom Ohai plugin and use it immediately with lazy block.
ohai 'reload_ec2_tags' do
plugin 'ec2/tags'
action :nothing
end
cookbook_file "#{node[:ohai][:plugin_path]}/ec2_tags.rb" do
notifies :reload, 'ohai[reload_ec2_tags]', :immediately
end
log 'Ohai plugin ec2/tags' do
@yureative
yureative / c
Created March 3, 2015 06:47
SSH login to EC2 instances by Name Tag
#!/bin/bash
if [ $# -lt 1 ]
then
echo 'Usage: c INSTANCE_NAME [REMOTE_COMMANDS...]'
exit 1
fi
pdns=`aws ec2 describe-instances --filters "Name=tag:Name,Values=$1" | jq -r '.Reservations[].Instances[].PrivateDnsName'`
@yureative
yureative / gist:a9958da1b7188a5dc637
Created April 15, 2015 02:12
Starting circusd with Itamae
INFO : service[circusd] running will change from 'false' to 'true'
DEBUG : service[circusd] enabled will not change (current value is 'true')
DEBUG : Executing `service circusd start`...
DEBUG : exited with 0
DEBUG : stdout | Starting circusd daemon: /usr/lib64/python2.7/dist-packages/Crypto/Util/number.py:57: PowmInsecureWarning: Not using mpz_powm_sec. You should rebuild using libgmp >= 5 to avoid timing attack vulnerability.
DEBUG : stdout | _warn("Not using mpz_powm_sec. You should rebuild using libgmp >= 5 to avoid timing attack vulnerability.", PowmInsecureWarning)
DEBUG : stdout | [60G[[0;32m OK [0;39m]
DEBUG : This resource is updated.