Skip to content

Instantly share code, notes, and snippets.

@igaiga
igaiga / ruby-gsub.el
Created February 16, 2010 13:23
replace region using ruby regexp
; replace region using ruby regexp
(defun ruby-gsub(regexp dst)
(interactive "sruby -p -e '$_.gsub!(/regexp/, 'dst')' regexp: \nsruby -p -e '$_.gsub!(/regexp/, 'dst')' [regexp: /%s/ ] dst:" )
(let (( ruby_str (concat "ruby -p -e '$_.gsub!(/" regexp "/,%q`" dst "`)' ")))
; (message ruby_str) ;debug
(shell-command-on-region (region-beginning) (region-end) ruby_str t t)
)
)
@igaiga
igaiga / get_twitter_using_hash
Created March 4, 2010 08:08
get_twitter_using_hash
#! ruby -Ku
# coding: utf-8
require "rubygems"
require "twitter" # gem install twitter
tw_hash = 'igaiga'
page_max = 3
(1..page_max).each do |page_num|
@igaiga
igaiga / twitter dm sender
Created March 26, 2010 05:06
twitter dm sender
#! ruby -Ku
# -*- coding: utf-8 -*-
# twitter DM sender to any users.
# via http://cheebow.info/chemt/archives/2007/11/twitterdm.html
require 'net/http'
require 'kconv'
require 'yaml'
conf_file = ARGV.shift || 'default.yaml'
conf = YAML.load_file(conf_file)
@igaiga
igaiga / utf-8 to utf-32
Created March 28, 2010 08:41
utf-8 to utf-32
#!ruby -Ku
# -*- coding: utf-8 -*-
require 'nkf'
#str_u8 = 'apple'
str_u8 = 'いがいが'
str_u32 = NKF.nkf('-w32B0 -W',str_u8) # out: UTF-32(non BOM), in: UTF-8(non BOM)
str_u32.each_byte{ |b|
p b.to_s(16)
}
; 画面の大きさにあわせてウィンドウ高さ調整
; mac でデュアルディスプレイにすると、 x-display-pixel-height が 2画面の和になる
(setq expected_height 30) ; default
(if (= (x-display-pixel-height) 2000) (setq expected_height 60))
(if (= (x-display-pixel-height) 800) (setq expected_height 39))
(set-frame-height nil expected_height)
require 'Date'
def validate_date(year, month, day)
return false if month <= 0 || day <= 0
return false if Date.valid_civil?(year, month, day).nil?
true
end
<h3>Japanese Public Holidays 2010</h3>
<div id="agenda"></div>
<script>
function listEvents(root) {
var feed = root.feed;
var entries = feed.entry || [];
var html = ['<ul>'];
Dir.glob("./*") do |file|
next unless file =~ /\.png|\.jpg|\.gif/
basename = File.basename(file, ".*")
basename += '_' if file =~ /\.png$/
run_str = "convert -resize 240x320 -quality 90% #{file} #{basename}.png"
system run_str
end
/*
Erica Sadun, http://ericasadun.com
iPhone Developer's Cookbook, 3.0 Edition
BSD License, Use at your own risk
*/
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#define COOKBOOK_PURPLE_COLOR [UIColor colorWithRed:0.20392f green:0.19607f blue:0.61176f alpha:1.0f]
UIButton* button = [[[UIButton alloc] initWithFrame:CGRectMake(150, 240, 100, 30)] autorelease];
[button setBackgroundImage:[UIImage imageNamed:@"btn.png"]
forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"btn_on.png"]
forState:UIControlStateHighlighted];
[button addTarget:self action:@selector(button_pushed) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
- (IBAction) button_pushed {