Skip to content

Instantly share code, notes, and snippets.

View hdemon's full-sized avatar

Masami Yonehara hdemon

  • LINE
  • Fukuoka, Japan
  • 21:29 (UTC +09:00)
View GitHub Profile
@hdemon
hdemon / yukkuri.rb
Created August 17, 2011 17:52
ゆっくり動画クローラ v0.1のコア部分 2011/8/17
# -*- encoding: utf-8 -*-
require 'rubygems'
require 'mechanize'
require 'kconv'
require 'mysql'
require 'date'
require 'damerau-levenshtein'
require 'cgi'
load 'unicode.rb'
@hdemon
hdemon / yukkuri-log.txt
Created August 18, 2011 02:22
ゆっくり動画クローラ v0.1のログ例
# 初期化とログイン
Mechanize initialized.
connect to https://secure.nicovideo.jp/secure/login_form
Logged in Niconico.
#検索画面のスクレイピング
connect to http://www.nicovideo.jp/search/%E3%82%86%E3%81%A3%E3%81%8F%E3%82%8A%E5%AE%9F%E6%B3%81?page=1&sort=f&order=d
connect to http://www.nicovideo.jp/search/%E3%82%86%E3%81%A3%E3%81%8F%E3%82%8A%E5%AE%9F%E6%B3%81?page=2&sort=f&order=d
connect to http://www.nicovideo.jp/search/%E3%82%86%E3%81%A3%E3%81%8F%E3%82%8A%E5%AE%9F%E6%B3%81?page=3&sort=f&order=d
...
# 検索結果6ページの28番目の動画を取得する、という意味。なぜここから始まるかというと、
@hdemon
hdemon / make.sh
Created August 26, 2011 09:53
分割ファイルを統合してバージョンを付けるスクリプト
#! /bin/bash
rm explorizer-[0-9.]*.js
version=$(head -n 1 version)
cd src
cat core.js >> code
cat util.js >> code
cat resizer.js >> code
@hdemon
hdemon / .zprofile
Created August 28, 2011 03:10
.zshrc
# path
PATH=$PATH:$HOME/bin:/sbin:/usr/sbin:~/.nave
# alias
alias la="ls -a"
alias lf="ls -F"
alias ll="ls -l"
alias du="du -h"
alias df="df -h"
alias su="su -l"
@hdemon
hdemon / xhr.js
Created August 28, 2011 11:38
xhr.js
var xhr = function(){
var xhr = new XMLHttpRequest();
return function( method, url, param, callback ){
xhr.onreadystatechange = function(){
if ( xhr.readyState === 4 ){
callback( xhr.responseText );
}
};
xhr.open( method, url+(method==="get" ? "?"+param : ""), true );
xhr.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
@hdemon
hdemon / quicksort.js
Created August 28, 2011 11:39
quicksort.js
function quickSort(array, start, end){
var start = ( typeof start === "undefined" ? 0 : start),
end = ( typeof end === "undefined" ? array.length - 1 : end),
p, tmp,
L, R;
p = array[ Math.floor((end + start) / 2) ];
L = start;
R = end;
while (true){
@hdemon
hdemon / mergesort.js
Created August 28, 2011 11:39
mergesort.js
function mergeSort(array){
//
if( array.length <= 1 ) return;
// division phase
var leftSize = Math.floor(array.length / 2),
rightSize = array.length - leftSize,
left = array.slice(0, leftSize),
right = array.slice(leftSize);
@hdemon
hdemon / bind.js
Created August 30, 2011 04:41
ES5のbindメソッドと同等の機能を、Functionオブジェクトの拡張で実現する。
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind
if (!Function.prototype.bind) {
Function.prototype.bind = function (oThis) {
if (typeof this !== "function") // closest thing possible to the ECMAScript 5 internal IsCallable function
throw new TypeError("Function.prototype.bind - what is trying to be fBound is not callable");
var aArgs = Array.prototype.slice.call(arguments, 1),
@hdemon
hdemon / dropbox-install.sh
Created August 31, 2011 05:17
DropBox設定スクリプト RHEL 64bit用
#!/usr/bin/bash
# Amazon EC2 / Amazon Linux 64bitでも起動
cd ~
# wget -O dropbox.tar.gz "http://www.dropbox.com/download/?plat=lnx.x86"
wget -O dropbox.tar.gz "http://www.dropbox.com/download/?plat=lnx.x86_64"
tar xvzf dropbox.tar.gz
rm dropbox.tar.gz
~/.dropbox-dist/dropboxd
@hdemon
hdemon / gettweet.js
Created August 31, 2011 07:19
サイト用簡易tweet取得スクリプト
<script>
var hdemon = hdemon || {};
hdemon.getTweet = {
get : function(json) {
var displayTweet = function(){ hdemon.getTweet.display(json); }
window.addEventListener("load", displayTweet);
},