Skip to content

Instantly share code, notes, and snippets.

@kmizu
kmizu / build.sbt
Created May 19, 2012 00:38
Code snippet of build.sbt for Finagle 4.0.2 in Scala 2.9.1
resolvers += "twitter-repo" at "http://maven.twttr.com"
libraryDependencies ++= Seq(
"com.twitter" % "finagle-core_2.9.1" % "4.0.2",
"com.twitter" % "finagle-http_2.9.1" % "4.0.2",
"com.twitter" % "finagle-stream_2.9.1" % "4.0.2"
)
@rummelonp
rummelonp / faraday.md
Last active May 20, 2022 12:23
Ruby の HTTP クライアントライブラリ Faraday が便利そう

Ruby の HTTP クライアントライブラリ Faraday が便利そう

Ruby の HTTP クライアントライブラリ Faraday が便利そう

API ラッパの開発には [RestClient gem][rest_client_gem] だとか
OAuth の必要なものは [Net/HTTP][net_http] + [OAuth gem][oauth_gem] を使ってた

[Twitter gem][twitter_gem] や [Instagram gem][instagram_gem] など API ライブラリのソースを読んでみると
[Faraday gem][faraday_gem] というものがよく使われてた

@drexin
drexin / Macros.scala
Last active October 27, 2016 09:41
macros to get current file and line, inspired by ruby's __FILE__ and __LINE__
import java.io.File
import language.experimental.macros
import scala.reflect.macros.Context
object Macros {
def LINE: Int = macro lineImpl
def lineImpl(c: Context): c.Expr[Int] = {
import c.universe._
@ryoco
ryoco / slide
Last active December 17, 2015 14:49
rpscala 104回で質問させていただいた スライド 題名と質問したい事がズレているがそのまま
/**
* rpscala 104回 で tototoshi さんが書いてくださった sample code の記憶を頼りにして書いたもの。
* unapply は Boolean でもり値にできるよというのと、
* paramTOStatus のようなものを書きたいのであれば list に object 書けば、という話
* (であってます。。。?)
*/
sealed abstract class Status(val id: Int) {
def unapply(i: Int): Boolean = i == id
}
case object OK extends Status(1)
@takezoux2
takezoux2 / SealedClassEnum
Last active December 17, 2015 14:49
scala勉強会で出た話題のコード。 sealed classを使ってEnumerationと同じようなことを行う。
object App
{
def main(args : Array[String]){
doMatch(args[0].toInt)
}
def doMatch( id : Int) = {
id match{
// scala2.10では()つけないとコンパイルエラーなのであまりいけてない?
case Status.OK() => println("OK")
@nekoruri
nekoruri / commonfunc.sh
Last active January 5, 2017 02:41
よく使いそうなbash関数
# DEBUG付いてるときだけデバッグ出力
function debug() { ((DEBUG)) && echo "$*"; }
# タイムスタンプ付き出力
function ts() { echo $(date +'%Y/%m/%d %H:%M:%S')" $1"; }
# タイムスタンプ付きデバッグ出力
function debugts() { debug $(date +'%Y/%m/%d %H:%M:%S')" $1"; }
# ディレクトリの絶対パス
@okisanjp
okisanjp / gist:7465900
Last active December 28, 2015 07:39
CentOSにzabbix-agent2.0を入れるときの作業用ひな形。実際には&&で全部つなげてワンライナーにして使います。 confは新しく作り直してるので入れておきたいオプションがあれば適宜追加で。 RHEL5/6系ならi386でもx86_64でも使えるはず。
OS_VER="5"
OS_TYPE="x86_64"
ZAB_VER="2.0.9"
ZAB_SERVER="ZABBIX_SERVER_IP_OR_FQDN"
rpm -ivh http://repo.zabbix.com/zabbix/2.0/rhel/$OS_VER/$OS_TYPE/zabbix-$ZAB_VER-1.el$OS_VER.$OS_TYPE.rpm http://repo.zabbix.com/zabbix/2.0/rhel/$OS_VER/$OS_TYPE/zabbix-agent-$ZAB_VER-1.el$OS_VER.$OS_TYPE.rpm
mv /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf.org
echo -e "Server=$ZAB_SERVER\nServerActive=$ZAB_SERVER\nHostnameItem=system.hostname\nInclude=/etc/zabbix/zabbix_agentd.d/\nEnableRemoteCommands=1\nLogRemoteCommands=1\nAllowRoot=1\nLogFile=/var/log/zabbix/zabbix_agentd.log
\nLogFileSize=0\n" > /etc/zabbix/zabbix_agentd.conf
/etc/init.d/zabbix-agent start
/sbin/chkconfig zabbix-agent on
@icyleaf
icyleaf / ar_migrate.rb
Last active June 6, 2024 20:06
ActiveRecord type of integer (tinyint, smallint, mediumint, int, bigint)
# activerecord-3.0.0/lib/active_record/connection_adapters/mysql_adapter.rb
# Maps logical Rails types to MySQL-specific data types.
def type_to_sql(type, limit = nil, precision = nil, scale = nil)
return super unless type.to_s == 'integer'
case limit
when 1; 'tinyint'
when 2; 'smallint'
when 3; 'mediumint'
when nil, 4, 11; 'int(11)' # compatibility with MySQL default