Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View komasaru's full-sized avatar

mk-mode komasaru

View GitHub Profile
@komasaru
komasaru / twitter_get_lists.rb
Created December 19, 2012 08:01
Ruby script to get twitter lists by Twitter API.
# -*- coding: utf-8 -*-
require 'twitter'
require 'oauth'
require 'time'
# Twitter UserName
USER_NAME = "foo"
# Consumer key, Secretの設定
CONSUMER_KEY = "XXXXXXXXXXXXXXXXXXXX"
CONSUMER_SECRET = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
@komasaru
komasaru / twitter_get_list_members.rb
Created December 19, 2012 08:42
Ruby script to get members of lists by Twitter API.
# -*- coding: utf-8 -*-
require 'twitter'
require 'oauth'
require 'time'
# Twitter UserName
USER_NAME = "foo"
# Consumer key, Secret の設定
CONSUMER_KEY = "XXXXXXXXXXXXXXXXXXXX"
CONSUMER_SECRET = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
@komasaru
komasaru / test_mecab.rb
Created December 30, 2012 06:27
Ruby script to test of mecab.
# -*- encoding: utf-8 -*-
require 'MeCab'
sentence = "太郎はこの本を二郎を見た女性に渡した。"
begin
c = MeCab::Tagger.new
n = c.parseToNode(sentence)
while n do
print n.surface, "\t", n.feature, "\t", n.cost, "\n"
n = n.next
@komasaru
komasaru / unicorn.rb
Created January 7, 2013 02:26
Configuration of unicorn on rails application.
# ワーカーの数
worker_processes 2
# RAILS_ROOT を指定
working_directory "/var/www/rails/rails_app/"
# ソケット
listen "/var/www/rails/rails_app/tmp/sockets/unicorn.sock"
# PID
@komasaru
komasaru / unicorn_rails
Created January 7, 2013 02:56
Script to start unicorn.
#!/bin/sh
NAME="Unicorn"
ENV=production
ROOT_DIR="/var/www/rails/rails_app"
PID="${ROOT_DIR}/tmp/pids/unicorn.pid"
CONF="${ROOT_DIR}/config/unicorn.rb"
OPTIONS="--path /rails_app"
@komasaru
komasaru / nanoc_helper_related_articles.rb
Last active December 11, 2015 09:18
Ruby script to generate a list of related articles.
@komasaru
komasaru / nanoc_helper_pager.rb
Last active December 11, 2015 12:38
Ruby script to generate pager for each article.
# Previous(Older) article
def prev_link
prv = sorted_articles.index(@item) + 1
unless articles.size - 1 < prv
link_to(
'&laquo;[Older] ' + sorted_articles[prv][:title],
sorted_articles[prv].reps[0],
:class => "prev"
)
end
@komasaru
komasaru / archive_generator.rb
Created February 1, 2013 07:54
Octopress plugin to generate monthly archive pages.
# encoding: utf-8
#
# Jekyll monthly arvchive page generator.
module Jekyll
class ArchiveIndex < Page
def initialize(site, base, dir, period, posts)
@site = site
@base = base
@dir = dir
@name = 'index.html'
@komasaru
komasaru / month_list.rb
Created February 1, 2013 07:58
Octopress plugin to generate a month list.
# encoding: utf-8
#
# Month List for Octopress
module Jekyll
class MonthList < Liquid::Tag
def initialize(tag_name, markup, tokens)
@opts = {}
if markup.strip =~ /\s*counter:(\w+)/i
@opts['counter'] = ($1 == 'true')
markup = markup.strip.sub(/counter:\w+/i,'')
@komasaru
komasaru / benchmark.rb
Created February 20, 2013 01:37
Ruby script for benchmarks.
require 'benchmark'
# 階乗を普通に計算
def fact_1(n)
f = 1
n == 0 ? f : (1..n).each {|i| f = f * i}
end
# 階乗を再帰的に計算
def fact_2(n)