Skip to content

Instantly share code, notes, and snippets.

View ainame's full-sized avatar

Satoshi Namai ainame

View GitHub Profile
@ainame
ainame / remove_resnpond_block.rake
Created July 14, 2011 16:35
Rails3のscaffoldで生成されたコントローラーからrespond_toブロックを消す。lib/taskに配置して使う
# -*- coding: utf-8 -*-
require "tempfile"
desc "scaffoldで生成されたコントローラーからrespond_toブロックを消す"
namespace :my do
task :rm_respond_to do
Dir::glob("app/controllers/*_*.rb") do |ctrl|
if !(File::basename(ctrl) =~ /application/)
temp = Tempfile::new("tmp",Dir::pwd)
open(ctrl) do |f|
text = f.read
@ainame
ainame / jyanken_game.pl
Created August 3, 2011 12:08
じゃんけんをCUI上で行うだけの糞プログラム。Perl使って初めてプログラム書きました。
#! /usr/bin/env perl
use warnings;
use strict;
use 5.010;
sub prompt{
do{
my $hand;
say "グー[g], チョキ[c], パー[p]";
print "入力してください:";
@ainame
ainame / anyevent.pl
Created August 14, 2011 05:12
AnyEventでファイルの読み込み
use 5.010;
use strict;
use warnings;
use autodie;
use AnyEvent;
open my $fh, '< hoge.txt';
my $cv = AnyEvent->condvar();
my $reader = AnyEvent->io(
fh => $fh,
@ainame
ainame / app.rb
Created August 14, 2011 12:46
Ruby+SinatraでmixiのGraph APIを利用してユーザー情報を取得するチュートリアル
# -*- coding: utf-8 -*-
require 'oauth2'
require 'sinatra'
require 'httparty'
require 'yaml'
enable :sessions
# コンシューマキーとシークレットを設定
configure do
config = YAML.load_file("setting.yml") #yaml形式で設定を書いた
@ainame
ainame / *scratch*
Created August 25, 2011 11:26
Slimでmixi日記っぽい構成のフォーム
== form_tag '/submit', :id => 'entry' do
== field_set_tag do
.fields
== label_tag :title, :class => 'diary-title'
== text_field_tag :title, :name => 'title', :size => "40"
.fields
== label_tag :body, :class => 'diary-body'
== text_area_tag :body, :rows => "30", :cols => "50"
== hidden_field_tag :name => 'photo1'
== hidden_field_tag :name => 'photo2'
@ainame
ainame / .emacs
Created September 5, 2011 14:39
自分の.emacsからruby-mode周りを抜いた物
;;; Time-stamp: <2011-07-22 18:05:48 namai>
;;;
(add-to-list 'load-path "~/.emacs.d/elisp/")
;; auto-install
(setq auto-install-directory "~/.emacs.d/auto-install/")
(add-to-list 'load-path auto-install-directory)
(add-to-list 'load-path (expand-file-name "~/.emacs.d/auto-install"))
;;(add-to-list 'custom-theme-load-path "~/.emacs.d/elisp/")
(require 'auto-install)
@ainame
ainame / .emacs
Created September 20, 2011 18:44
;;; Time-stamp: <2011-09-19 19:59:30 namai>
;;ファイル保存時にコンパイル
(add-hook 'after-save-hook
(function (lambda ()
(if (string= (expand-file-name "~/.emacs")
(buffer-file-name))
(save-excursion
(byte-compile-file (expand-file-name "~/.emacs")))))))
(add-to-list 'load-path "~/.emacs.d/elisp/")
(defun anything-filelist+ ()
"Preconfigured `anything' to open files/buffers/bookmarks instantly.
This is a replacement for `anything-for-files'.
See `anything-c-filelist-file-name' docstring for usage."
(interactive)
(anything-other-buffer
'(anything-c-source-ffap-line
anything-c-source-ffap-guesser
anything-c-source-buffers+
@ainame
ainame / abstract_twitter_gem.rb
Created October 8, 2011 10:47
1分で分かるjunemaker/twitterでTwitter#userを呼び出すために行ってる継承等
module Twitter
module Request
def get
puts "Hello Twitter.user!!"
end
end
end
# !/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
# grep 関数の普通の使い方1
# 文字列の中にpが含まれている単語のフィルタリング
# grep EXP, LIST という構文
my @list = qw(perl ruby python php java c++);