Skip to content

Instantly share code, notes, and snippets.

@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
@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"; }
# ディレクトリの絶対パス
@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")
@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)
@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._
@rummelonp
rummelonp / faraday.md
Last active January 19, 2026 16:33
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] というものがよく使われてた

@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"
)