Skip to content

Instantly share code, notes, and snippets.

View kaosf's full-sized avatar
🏠
Working from home

ka kaosf

🏠
Working from home
View GitHub Profile
@kaosf
kaosf / login-to-yahoo-jp-with-mechanize-on-ruby.rb
Created March 5, 2012 04:42
login to Yahoo! JAPAN with Mechanize on Ruby - Ruby の Mechanize を使って Yahoo! JAPAN にログインする
# coding: utf-8
require 'mechanize'
Id = 'id'
Password = 'password'
Mechanize.new do |agent|
agent.user_agent = 'Mozilla/5.0 (Linux; U; Android 2.3.2; ja-jp; SonyEricssonSO-01C Build/3.0.D.2.79) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'
agent.get 'http://login.yahoo.co.jp/config/login?.lg=jp&.intl=jp&logout=1&.src=www&.done=http://www.yahoo.co.jp'
@kaosf
kaosf / stable_sort_by.rb
Created March 5, 2012 20:28
stable_sort_by (Ruby)
class Array
def stable_sort_by
n = 0
sort_by { |x| [yield(x), n += 1] }
end
end
p [[83, 'annette'], [82, 'kate'], [82, 'lucy']].sort_by { |x| x[0] }
p [[83, 'annette'], [82, 'kate'], [82, 'lucy']].stable_sort_by { |x| x[0] }
# p [[83, 'annette'], [82, 'kate'], [82, 'lucy']].stable_sort_by #=> no block given (yield) (LocalJumpError)
@kaosf
kaosf / how_to_install_node_js_to_local_on_ubuntu_10_04_server.sh
Created March 13, 2012 06:42
How to install Node.js to local on Ubuntu 10.04 Server
# 2012-03-13
# preparation for installation
sudo aptitude install build-essential libssl-dev
echo 'export PATH="$HOME/local/bin:$PATH"' >> .zshrc # or .bashrc
# installation process
mkdir -p $HOME/local/src # if doesn't exist yet
@kaosf
kaosf / ls.d
Created April 11, 2012 15:57 — forked from noqisofon/ls.d
execute "ls" command with D language (D 言語で ls コマンド実行)
// tested with DMD64 D Compiler v2.058
import std.process;
void main() {
system( "ls" );
}
<!DOCTYPE html>
<html lang="ja">
<head>
<meta http-equiv="content-type" content="text/html" charset="utf-8">
<meta name="robots" content="noindex, nofollow">
<title>flickable test</title>
<!-- use jQuery 1.5.2 daringly
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.min.js"></script>
<script type="text/javascript" src="http://lagoscript.org/files/jquery/flickable/jquery.flickable-1.0b3.min.js"></script>
-->
(1..9).each do |i1|
(2..9).each do |i2|
(3..9).each do |i3|
(4..9).each do |i4|
if i1 < i2 && i2 < i3 && i3 < i4
print("#{i1}#{i2}#{i3}#{i4}\n")
end
end
end
end
@kaosf
kaosf / clockwork-init.sh
Created June 23, 2012 01:28 — forked from tomykaira/clockwork-init.sh
Create a new project with clockwork for heroku.
#!/bin/sh
# Licence: MIT
# Created by tomykaira, 2011-10-25
if [ $# -ne 1 ]; then
echo "Give me your new project name (only)"
exit 1
fi
@kaosf
kaosf / file0.txt
Created June 29, 2012 07:40
uri, net/http, multi_json memo ref: http://qiita.com/items/100c5da99fad8751231c
require 'uri'
require 'net/http'
require 'multi_json'
uri = URI.parse('http://exapmle.com/contents/1.json')
res = Net::HTTP.get_response(uri)
json = MultiJson.load(res.body, symbolize_keys: true)
p json
@kaosf
kaosf / gist:3067930
Created July 7, 2012 20:03
LiveScript my first practice
# ref. http://d.hatena.ne.jp/mizchi/20120706/1341568588
# http://twilog.org/ka_/date-120708
global <<< require \prelude-ls
take(n, [x, ...xs]:list) =
| n <= 0 => []
| empty list => []
| otherwise => [x] +++ take n - 1, xs
# | otherwise => x & take n - 1, xs # obsolete from version 0.9.11
@kaosf
kaosf / PushNotification.coffee
Created December 1, 2012 13:07
rewrite PushNotification.js by CoffeeScript
# rewrite this https://github.com/Guti/Google-Cloud-Messaging--Titanium-/blob/6ac1270026f3cc266f37812b64ef40f2ab1b9055/example/PushNotification.js
exports.pushNotification = ->
hostURL = 'http://YOUR_HOST_URL/register?'
gcm = require 'com.activate.gcm'
Ti.API.info "module gcm is => #{gcm}"
Ti.API.info 'Registering...'