Skip to content

Instantly share code, notes, and snippets.

View potato2003's full-sized avatar
🏠
Working from home

potato2003

🏠
Working from home
View GitHub Profile
@potato2003
potato2003 / add_hostname.sh
Last active November 8, 2019 04:59
Adding server hostname to each line of output
$ echo HOST1 HOST2 | xargs -d ' ' -P2 -I{} ssh {} 'tail -F LOG_PATH | xargs -L 1 echo $(hostname): $1'
@potato2003
potato2003 / 0_output.txt
Last active June 19, 2019 14:10
benchmark: split a string every n characters in Ruby
user system total real
String#scan 1.774321 0.007220 1.781541 ( 1.799350)
String.unpack 0.665138 0.003861 0.668999 ( 0.678201)
String#chars.each_slice.map(join) 10.444911 0.023717 10.468628 ( 10.521092)
String#[] slice with times iteration 2.244066 0.006614 2.250680 ( 2.264310)
String#slice with times iteration 2.271120 0.005431 2.276551 ( 2.290473)
@potato2003
potato2003 / systemd-note.md
Last active May 17, 2019 14:41
systemd のメモ

systemd

特徴

cgroups による管理

従来の Upstart/daemontools 等の init系プロセスでは、

  • double forking による自身を デーモン化するプロセス
  • Puma/Unicorn 等の Hot restart
@potato2003
potato2003 / setusergroups
Last active March 27, 2019 08:36
ruby 環境で必要だったので、kazuho さんの https://gist.github.com/kazuho/6181648 を参考に書いた。(参考リンク - 2) http://d.hatena.ne.jp/hirose31/20130808/1375965331
#!/usr/bin/env ruby
# usage: setusergroups [-h|--help] username child
#
# setuidgid w. support for supplementary groups
# ruby porting of https://gist.github.com/kazuho/6181648
#
# see: http://d.hatena.ne.jp/hirose31/20130808/1375965331
# see: https://gist.github.com/kazuho/6181648
@potato2003
potato2003 / dayOfWeek.java
Created May 22, 2014 08:44
Show day of the week for different locale.
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class Main {
public static void main(String[] args) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日 E曜日", Locale.JAPAN);
Date now = new Date();
@potato2003
potato2003 / watcher.sh
Created March 9, 2014 04:30
Google Playにアプリが公開されたら通知してくれるスクリプト。 requirements: Mac OS X 10.8+, terminal-notifier
#!/bin/bash
if [[ -z "${PACKAGE}" ]]; then
echo "error: PACKAGE is not assagined."
echo " usage) export PACKAGE=com.example; $(basename ${0})"
exit 1
fi
while :
do
@potato2003
potato2003 / 1.scala
Last active December 24, 2015 12:39
implicit def xxx(implicit yyy) が 暗黙的パラメータと理解するために試した。 参考: http://d.hatena.ne.jp/gakuzo/20111204/1323007376
class ClassA(val label: String)
implicit val arg1:ClassA = new ClassA("ぼくは暗黙的パラメータ") // implicit def foo のための暗黙的パラメータ定義
implicit def foo(implicit a: ClassA):String = { // 引数の implicit 消すと 暗黙的パラメータ見つからないってエラーになる
println("fooだよ")
a.label
}
def bar()(implicit argStr:String):String = {
@potato2003
potato2003 / gist:6790082
Created October 2, 2013 07:16
Play2のコードみてて気になったメモ。なにをやっているのかわからない。 def session(implicit request: RequestHeader) = request.session と何が違うのだろうか
implicit def session(implicit request: RequestHeader) = request.session
@potato2003
potato2003 / gist:6760691
Last active December 24, 2015 06:59
Scaladoc で OutOfMemory が出た時の対処 ref: http://qiita.com/potato2003@github/items/f7bed8ef8197fdf2f4c0
$ scaladoc -d doc/ -s src/main/scala/**/*.scala
@potato2003
potato2003 / gist:6697131
Created September 25, 2013 09:20
StackableController + Slick + PlayFramework で暗黙的にDBSession使いまわすのやつメモ
trait SlickDBSessionElement extends StackableController {
self: Controller =>
import play.api.db.slick
type Session = slick.Session
case object DBSessionKey extends RequestAttributeKey[Session]
override def proceed[A](req: RequestWithAttributes[A])(f: RequestWithAttributes[A] => Result): Result = {
val session:Session = play.api.db.slick.DB.createSession()