Skip to content

Instantly share code, notes, and snippets.

mk-mode komasaru

Block or report user

Report or block komasaru

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@komasaru
komasaru / twitter_get_lists.rb
Created Dec 19, 2012
Ruby script to get twitter lists by Twitter API.
View twitter_get_lists.rb
# -*- 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 Dec 19, 2012
Ruby script to get members of lists by Twitter API.
View twitter_get_list_members.rb
# -*- 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 Dec 30, 2012
Ruby script to test of mecab.
View test_mecab.rb
# -*- 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 Jan 7, 2013
Configuration of unicorn on rails application.
View unicorn.rb
# ワーカーの数
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 Jan 7, 2013
Script to start unicorn.
View unicorn_rails
#!/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 Dec 11, 2015
Ruby script to generate a list of related articles.
View nanoc_helper_related_articles.rb
@komasaru
komasaru / nanoc_helper_pager.rb
Last active Dec 11, 2015
Ruby script to generate pager for each article.
View nanoc_helper_pager.rb
# 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 Feb 1, 2013
Octopress plugin to generate monthly archive pages.
View archive_generator.rb
# 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 Feb 1, 2013
Octopress plugin to generate a month list.
View month_list.rb
# 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 Feb 20, 2013
Ruby script for benchmarks.
View benchmark.rb
require 'benchmark'
# 階乗を普通に計算
def fact_1(n)
f = 1
n == 0 ? f : (1..n).each {|i| f = f * i}
end
# 階乗を再帰的に計算
def fact_2(n)
You can’t perform that action at this time.