Skip to content

Instantly share code, notes, and snippets.

@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'
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 / .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() {
@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 / 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