Skip to content

Instantly share code, notes, and snippets.

View suchi's full-sized avatar
👨‍💼

suchi suchi

👨‍💼
View GitHub Profile
@suchi
suchi / list_all_controllers.html.erb
Created June 23, 2009 01:46
登録されているadmin/以下のコントローラを表示する
<% ActionController::Routing.possible_controllers.sort.each {|c| %>
<%= link_to c.gsub(/^admin\//, "").camelize, :controller => c.to_sym %> |
<% } %>
@suchi
suchi / YYYYMMDD.HHMMSS.bat
Created August 5, 2010 11:39
YYYYMMDD.HHMMSSという環境変数を生成する
: YYYYMMDD.HHMMSSを作成する
: うしろ3桁をカット
set TIMEHHMMSS0=%TIME:~0,-3%
: ':'を削除
set TIMEHHMMSS=%TIMEHHMMSS0::=%
: '/'を削除
set DATEYYYYMMDD=%DATE:/=%
set DATETIME=%DATEYYYYMMDD%.%TIMEHHMMSS%
: ' 'を0にする
set DATETIME=%DATETIME: =0%
@suchi
suchi / ipad2_alive.rb
Created April 27, 2011 09:27 — forked from mackato/ipad2_check.rb
iPad2を待ちながら
require 'open-uri'
WAIT = 180
loop do
begin
open('http://onlineshop.mb.softbank.jp/ols/html/model/ipad/')
puts "iPad2 online shop page opened!"
rescue Exception => e
unless e.to_s =~ /^403/
puts "iPad2 online shop status changed #{e}"
end
@suchi
suchi / compare_sample.rb
Created May 12, 2011 06:55
hamamatsu.rb#3 protectedなインスタンス変数getterを利用した比較
class Foo
include Comparable
def initialize(x, y)
@x = x
@y = y
end
def <=>(rhs)
return nil unless rhs.instance_of? Foo
@suchi
suchi / mc.cs
Created May 25, 2011 12:44
「プログラミング作法」The Practice of Programming MarkovChainのC#実装例(Generics不使用)
/* PoP 3 Markov Chain in C# */
/* 2003/02/17: suchi -- */
using System;
using System.IO;
using System.Collections;
using System.Text.RegularExpressions;
class Prefix {
const int MULTIPLIER = 31; // for hashcode
@suchi
suchi / jsplit.cpp
Created May 25, 2011 12:47
日本語テキストを0x20区切りの分かち書きに簡易変換します。「プログラミング作法」 "The Practice of Programming" のMarkovChainを日本語でも楽しめるようにするためのもの。
#include <stdio.h>
#include <ctype.h>
typedef unsigned char uchar;
struct wc {
enum wctype {
KANJI, // 0
HIRAKATA, // 1
PUNKT, // 2
@suchi
suchi / gist:1000092
Created May 31, 2011 07:07
コンテナをcopyとostream_iteratorを使って出力するイディオム
copy(vs.begin(), vs.end(), ostream_iterator<string>(cout, "\n"));
@suchi
suchi / mongrel.rb
Created June 14, 2011 13:30 — forked from metaskills/mongrel.rb
Redmine 1.2.0 + Mongrel 1.1.5の不具合対応
if ['2.3.8', '2.3.9', '2.3.10', '2.3.11'].include?(Rails.version) && Gem.available?('mongrel', Gem::Requirement.new('~>1.1.5')) && self.class.const_defined?(:Mongrel)
# Pulled right from latest rack. Old looked like this in 1.1.0 version.
#
# def [](k)
# super(@names[k] ||= @names[k.downcase])
# end
#
module Rack
module Utils
@suchi
suchi / ManpukuPermLinker.js
Created June 30, 2011 09:55
HTB幸せ満腹道場にPermLinkを追加する Greasemonkeyスクリプト
// ==UserScript==
// @name ShiawaseDojo Permlinker
// @namespace SDP
// @description ShiawaseDojo Permlinker
// @include http://www.htb.co.jp/announcers/mami/*
// ==/UserScript==
d=document,e=d.querySelectorAll('.entry-date'),a=d.querySelectorAll('a[name*="entry_"]');for(i=0;i<a.length;i++){a[i].appendChild(e[i]);a[i].href='#'+a[i].name}void(0)
@suchi
suchi / gist:1079576
Created July 13, 2011 01:50
Practice of Programming p.169
#include <stdio.h>
#define _USE_MATH_DEFINES 1
#include <math.h>
int main()
{
int n = 1;
double d = M_PI;
printf("%d %f\n", d, n);