Skip to content

Instantly share code, notes, and snippets.

@kasei-san
kasei-san / application.rb
Last active December 11, 2015 08:58
RSpec on Railsで、controllerで使うライブラリのテストをする (環境 : ruby 1.9.2, rails : 3.0.9, rspec-rails : 2.1.12)
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)
module AppLibTest
class Application < Rails::Application
@kasei-san
kasei-san / gist:4632635
Created January 25, 2013 07:59
rubyで、URI.unescapeするワンライナー
ruby -r uri -ne 'puts URI.unescape $_.chomp'
@kasei-san
kasei-san / fms_switcher.js
Last active December 17, 2015 21:38 — forked from zentooo/fms_switcher.js
最新のvimpだと、PLUGIN_INFO の所でエラーが出るので修正
let PLUGIN_INFO = xml`
<VimperatorPlugin>
<name>fms_switcher</name>
<description>This script allows you to switch FireMobileSimulator status with Vimp CLI.</description>
<version>1.0.1</version>
<author>zentooo</author>
<license>Creative Commons</license>
<detail><![CDATA[
== Subject ==
This script allows you to switch FireMobileSimulator status from Vimperator CLI.
@kasei-san
kasei-san / .autotest
Created June 25, 2013 06:13
autospec で、結果を Growl で通知 【参考】autotest + growl で楽々テスト - 僕は発展途上技術者 http://blog.champierre.com/774
# vim: set ft=ruby
module Autotest::Growl
def self.growl title, msg, pri=0, sticky=""
msg += " at #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}"
system "growlnotify -n autotest -p #{pri} -m #{msg.inspect} #{title} #{sticky}"
end
Autotest.add_hook :ran_command do |at|
output = at.results.last
output = output.gsub!(/\e\[\d+m/,'').gsub!(/\n/,'')
@kasei-san
kasei-san / gist:10003192
Last active August 29, 2015 13:58
スレッド操作いろいろ
#include <stdio.h>
#include <pthread.h>
#include <iostream>
class LedMatrix {
private:
pthread_t thread; // スレッドハンドラ
pthread_mutex_t mutex; // ミューテックス(排他処理で優先権を決めるやつ)
int data;
public:
class StringListerViewer
attr_reader :items, :type
def initialize(items, type)
@items = items
@type = type
end
def string_lister(items)
Object.const_get("#{type.to_s.capitalize}StringLister").new(items)
end
引数 klass で指定したクラスだけに対して、ブロックで指定した機能を提供で きるモジュールを定義します。定義した機能は Module#refine を使用せずに直 接 klass に対して変更を行う場合と異なり、限られた範囲のみ有効にできます。 そのため、既存の機能を局所的に修正したい場合などに用いる事ができます。
アルゴリズムを実行時に選択することができるデザインパターンである。
# ファイルを生成して、upload するという流れ
class FileUploader # Client
def initialize(factory)
@file_maker = factory.file_maker
@uploader = factory.uploader
end
def make_flie(items)
@file = file_maker.make(item)
end
require "open-uri"
class Titles
include Enumerable
def initialize
@urls = []
end
def <<(url)
@urls << url