Skip to content

Instantly share code, notes, and snippets.

@mahm
mahm / SpriteButton.cs
Created February 17, 2014 21:32
SpriteButton (Unity)
using UnityEngine;
using System.Collections;
public class SpriteButton : MonoBehaviour
{
public Sprite buttonDownSprite = null;
public GameObject targetObject = null;
public string messageName = "";
private Sprite normalSprite;
@mahm
mahm / angel.rb
Last active August 29, 2015 14:05
# members_controller.rb
class MembersController < ApplicationController
def destroy
if !checkadmin? then return end
@member = Member.find(params[:id])
@member.destroy
respond_to do |format|
format.html { redirect_to members_url }
format.json { head :no_content }
@mahm
mahm / blog_sample01.rb
Last active August 29, 2015 14:09
2014/11/12のブログ記事のサンプルコード
class Post
def initialize(title, body)
@title, @body = title, body
end
def render
<<-EOS
<article>
<h1>#{@title}</h1>
<p>#{@body}</p>
@mahm
mahm / normal_vs_lazy_1.rb
Last active August 29, 2015 14:09
normal select vs lazy select
require 'benchmark'
def normal_selector(array, word)
array.select{|hash| hash[:name].match "#{word}"}.to_a
end
def lazy_selector(array, word)
array.lazy.select{|hash| hash[:name].match "#{word}"}.to_a
end
@mahm
mahm / benchmark.rb
Last active August 29, 2015 14:09
'each commit' vs 'transaction' vs 'bulk_insert'
require 'benchmark'
def each_commit(size)
project = Project.create!(name: "each_commit #{size}")
size.times.with_index(1) do |_, index|
project.tasks.create!(name: "Task #{index}")
end
end
def transaction(size)
@mahm
mahm / ruby_vs_mongo.rb
Last active August 29, 2015 14:09
Ruby vs MongoDB
require 'benchmark'
require 'mongo'
def generate_parts(size)
area_patterns = [['main'], ['sub'], ['header', 'footer']]
enable_patterns = [true, false]
level_patterns = ['/level1', '/level1/level2', '/level1/level2/level3']
(1..size).map do |n|
{
@mahm
mahm / projects_controller.rb
Last active August 29, 2015 14:10
AngularJS + Railsでネストしたリソースを取得する
class ProjectsController < ApplicationController
def index
@projects = Project.all
end
def show
@project = Project.find(params[:id])
end
end
@mahm
mahm / Gemfile
Last active August 29, 2015 14:10
AngularJS & Rails
source 'https://rubygems.org'
gem 'rails', '4.1.7'
gem 'pg', group: :production
gem 'rails_12factor', group: :production
gem 'uglifier', '>= 1.3.0'
gem 'jbuilder', '~> 2.0'
gem 'enumerize'
gem 'inherited_resources'
@mahm
mahm / sample.jmx.rb
Created November 23, 2014 07:00
ruby-jmeter sample
require 'ruby-jmeter'
test name: 'JMX Sample' do
threads count: 5, loops: 5 do
cookies
visit name: 'Login Page', url: 'http://0.0.0.0:3000/users/sign_in' do
extract name: 'csrf-token', xpath: "//meta[@name='csrf-token']/@content", tolerant: true
extract name: 'csrf-param', xpath: "//meta[@name='csrf-param']/@content", tolerant: true
end
http_header_manager name: 'X-CSRF-Token', value: '${csrf-token}'
@mahm
mahm / sprockets_ext.rb
Created November 27, 2014 01:19
Rails3.1 + Ruby2.0 with Sprockets
# Rails 3.2.13以前のバージョン + Ruby2.0の組み合わせだと適切にDirectiveをパースできない不具合がある
# ref: https://github.com/sstephenson/sprockets/issues/352
directive_pattern = /
^ \W* = \s* (\w+.*?) (\*\/)? $
/x
Sprockets::DirectiveProcessor.class_eval do
remove_const(:DIRECTIVE_PATTERN)
const_set(:DIRECTIVE_PATTERN, directive_pattern)
def directives