Skip to content

Instantly share code, notes, and snippets.

@miyohide
miyohide / hatena_entry_list.rb
Created August 14, 2011 05:50
はてなダイアリーの記事一覧を取得する
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'pit'
require 'wsse'
require 'net/http'
Net::HTTP.version_1_2
@miyohide
miyohide / hatena_entry_post.rb
Created August 28, 2011 10:11
はてなダイアリーに記事を投稿するサンプルコード
require 'rexml/document'
require 'time'
require 'pit'
require 'wsse'
require 'net/http'
class HatenaDiary
attr_accessor :title, :content, :updated
def initialize
@miyohide
miyohide / gist:1647914
Created January 20, 2012 15:37
特定基準日の開始日を求める
require 'active_support'
require 'active_support/core_ext'
def my_start_of_month(today, base)
today.prev_month.change(:day => base)
end
my_start_of_month(Date.today, 28) # => 2012年1月21日に実行した場合、 Wed, 28 Dec 2011 が返る
@miyohide
miyohide / gist:1653038
Created January 21, 2012 15:17
配列の累積を求める
a = []
[1,2,3,4,5].inject(0) { |r,i| s = r + i ; a << s ; s }
puts a # => [1,3,6,10,15]
@miyohide
miyohide / gist:3781517
Created September 25, 2012 12:36
正規表現のサンプル
# pass_check.rb
# coding: utf-8
def pass_check(password)
password =~ /[[:alnum:]!\"#\$%&\'\(\)]/
end
# test_pass_check.rb
# coding: utf-8
@miyohide
miyohide / gist:3946532
Created October 24, 2012 14:54
dynatreeサンプル
<!DOCTYPE HTML>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>Dynatree Sample</title>
<link rel="stylesheet" href="./src/skin/ui.dynatree.css" />
<script type="text/javascript" src="./jquery/jquery.js"></script>
<script type="text/javascript" src="./jquery/jquery-ui.custom.js"></script>
<script type="text/javascript" src="./jquery/jquery.cookie.js"></script>
<script type="text/javascript" src="./dist/jquery.dynatree.min.js"></script>
@miyohide
miyohide / windowlicker_build.txt
Created March 23, 2013 05:04
windowlickerビルド
[~/work/windowlicker]$ svn export http://windowlicker.googlecode.com/svn/trunk
A trunk
A trunk/LICENSE.txt
A trunk/tools
A trunk/tools/tools.iml
A trunk/tools/apache-ant-1.7.0
A trunk/tools/apache-ant-1.7.0/WHATSNEW
A trunk/tools/apache-ant-1.7.0/LICENSE.dom
A trunk/tools/apache-ant-1.7.0/NOTICE
A trunk/tools/apache-ant-1.7.0/LICENSE
@miyohide
miyohide / gist:9269498
Created February 28, 2014 11:28
メソッドの呼び出し直後と終了直後にログを出力したい
class Hello
def say_hello
puts "hello"
end
end
## Hello.new.say_helloとしたら、下のような出力をしたい
##
## Method say_hello start
## hello
@miyohide
miyohide / gist:9269550
Created February 28, 2014 11:32
メソッドの呼び出し直後と終了直後にログを出力したい(解決編)
module AddLogging
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def method_added(name)
# すでにhookメソッドがあったり、without_hookメソッドがある場合は定義しない
return if /hook/.match(name.to_s) || method_defined?("#{name}_without_hook")
# 開始と終了時にメッセージを出す
version = "1.9.3-p123"
vers = version.tr("-p",".").split(".").delete_if { |i| i.size == 0 }.map { |i| i.to_i }
patch_level = vers.pop
sum = vers.each_with_index.map { |x, i| x.to_i * 10 ** (5 - i) }.inject { |sum,i| sum + i }
sum + patch_level # => 193123