Skip to content

Instantly share code, notes, and snippets.

@arosh
arosh / gist:3497882
Created August 28, 2012 13:17
sinatra session
#!/usr/bin/env ruby
require 'sinatra'
require 'erb'
require 'rack'
# secretの値はデフォルトで乱数を与えてくれるらしい
# 細かい設定をしたいときは Rack::Session::Cookie を使え
# http://www.sinatrarb.com/faq.html#sessions
set :sessions, true
@arosh
arosh / Gemfile
Created August 29, 2012 09:54
activerecord with sqlite3, another primary key
source :rubygems
# activerecordにはパッケージ名に罠がある
# http://stackoverflow.com/questions/4016929/bunder-require-does-not-work-for-activerecord-in-my-gem
gem 'activerecord', require: 'active_record'
gem 'sqlite3'
@arosh
arosh / .bashrc
Last active February 13, 2018 03:58
Ubuntu Serverで最低限追記しておきたい設定
alias ls='ls -p --color=auto'
alias l='ls'
alias ll='ls -lFh'
alias la='ls -A'
alias lla='ll -A'
alias mv='mv -i'
alias cp='cp -i'
alias rmdir='rm -rf'
alias grep='grep --color=auto'
alias egrep='grep -E'
@arosh
arosh / nginx.conf
Last active December 17, 2023 15:23
redmine on nginx + unicorn
# This is example contains the bare mininum to get nginx going with
# Unicorn or Rainbows! servers. Generally these configuration settings
# are applicable to other HTTP application servers (and not just Ruby
# ones), so if you have one working well for proxying another app
# server, feel free to continue using it.
#
# The only setting we feel strongly about is the fail_timeout=0
# directive in the "upstream" block. max_fails=0 also has the same
# effect as fail_timeout=0 for current versions of nginx and may be
# used in its place.
@arosh
arosh / gist:3618705
Created September 4, 2012 08:53
proCONTROLL

proCONTROLLライブラリを使うことで、Processingからジョイスティックやゲームパッド、キーボードやマウスが利用できるようになります。他にも、MacOSX上でなら、2つ以上のマウスを利用できるようになります。proCONTROLLはJInputを改良したものをベースとしています。他のデバイスにアクセスしたいのであれば、ネイティブ・ライブラリを書くことで、利用できるようになるでしょう。

proCONTROLL上で任意のデバイスを利用するためには、デバイス・ドライバ等のインストールが確実に行われていなければなりません。またジョイスティックは適切に調節が行われている必要があります。使用可能なデバイスのリストを表示するためには printDevices() 関数を利用できます。proCONTROLLの使用方法には大きく分けて2通りがあります。一つはデバイスにアクセスし、ボタンやスライダーの状態を得る方法。もう一つはボタンの状態に対するイベントハンドラーを設定する方法です。

proCONTROLLはWIndowsだけでなくLinuxやMac OS Xでもテストされています。

setTolerance() Toleranceというのは、それ以下の値はゼロとみなす、しきい値のことです。

@arosh
arosh / gist:3682866
Created September 9, 2012 06:00
ファイルを直接コマンドラインから実行したかどうか区別する方法
if __FILE__ == $0
# 直接呼ばれた時に実行したい処理
end
@arosh
arosh / gist:3683682
Created September 9, 2012 10:29
Project Euler Problem 49
import scala.collection.mutable
val bs = mutable.BitSet( (2 to 9999): _*)
var cur = 2
while(cur * cur <= 9999) {
if(bs(cur)) {
var mul = 2 * cur
while(mul <= 9999) {
bs -= mul
@arosh
arosh / gist:3698676
Created September 11, 2012 13:55
Sieve of Eratosthenes
import scala.testing.Benchmark
import scala.collection.mutable
import scala.collection.immutable
import scala.annotation.tailrec
object PrimeNumbers {
def main(args: Array[String]) {
if (args.size != 2) {
println("usage: scala PrimeNumbers PRIME_MAX RUN_COUNT")
sys.exit()
@arosh
arosh / gist:3803693
Created September 29, 2012 10:56
basic compare in C
int cmp(int* a, int* b) {
return *a < *b ? -1 : *a < *b;
}