Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / AudioManager.cs
Created February 16, 2014 04:27
Unity de sashimi
using UnityEngine;
using System.Collections;
public class AudioManager : SingletonMonoBehaviour<AudioManager> {
AudioClip bgm_Game;
AudioClip se_Tanpopo;
private const int source_bgm_Game = 0;
private const int maxAudio = 10;
@mahm
mahm / NodeWebkit.sublime-build
Created February 13, 2014 02:05
NodeWebkit.sublime-build
{
"cmd": ["node-webkit", "${project_path:${folder}}"],
"working_dir": "${project_path:${folder}}",
"path": "/Applications/node-webkit.app/Contents/MacOS/"
}
@mahm
mahm / ex_mixin.css
Created February 10, 2014 02:35
mixinとplaceholderの違い
.menu > li {
display: inline-block;
*display: inline;
*zoom: 1;
background-color: gray; }
footer > li {
display: inline-block;
*display: inline;
*zoom: 1;
@mahm
mahm / _try.sass
Created February 4, 2014 12:57
for Twitter Bootstrap
$base-color: #f2eff0
$main-color: #333333
$accent-color: #1e965c
$base-text-color: darken($base-color, 50%)
@mahm
mahm / wordpress_post_preview.rb
Created January 30, 2014 05:35
rubypressでWordPressの記事一覧を取得する
pry(main)> wp.getPosts(filter: {order: 'desc'}).first
=> {"post_id"=>"5904",
"post_title"=>"モバイルアプリ向けUIフレームワークionicがSassで作られている&AngularJSに最適化されていて俺得すぎる",
"post_date"=>
#<XMLRPC::DateTime:0x007fb3988f0068
@day=29,
@hour=18,
@min=32,
@month=1,
@sec=21,
@mahm
mahm / reaction_survey.rb
Created January 7, 2014 05:31
時間毎のtweetのretweet数とfavorite数の合計を求める。どの時間帯のtweetが一番反応が良いか?という簡易的な調査。
require 'twitter'
if ARGV[0].nil? || ARGV[0] == ''
puts 'Usage:'
puts ' ruby reaction_survey.rb [twitter user name]'
exit
end
username = ARGV[0]
@client = Twitter::REST::Client.new do |config|