Skip to content

Instantly share code, notes, and snippets.

@nebuta
nebuta / haskell_advent_2012_26.md
Last active July 31, 2022 17:32
HaskellでWebスクレイピング - Haskell Advent Calendar 2012

HaskellでWebスクレイピング

この記事はHaskell Advent Calendar 2012の26日目の記事です。Haskell Advent Calendar初参加です。コメントなどお待ちしております。

前提知識 - Haskellでの文字列処理

HaskellではString([Char]の別名)が文字列の基本型で、これはリストであるためにパターンマッチ・再帰やPreludeやData.Listにあるリスト用の関数を使って処理ができるという利点があります。ただし、実用上はパフォーマンスが低いため、TextByteStringが代わりに用いられます。Textはいわゆるユニコード文字列、ByteStringはバイト列という区別です。この使い分けに関してはちょうどAdvent Calendarの@brain_appleさんのこの記事で解説されました。StackOverflowでの質問も参考になります。

HaskellでのHTMLパーシング用ライブラリの概観

Hackageを見ると、

@nebuta
nebuta / montecarlo.rs
Last active December 13, 2015 21:18
Monte carlo simulation for hard spheres written in Rust language
//
// Monte carlo simulation for hard spheres written in Rust language.
//
//To compile and execute this (on Mac OSX):
// rustc -O test.rs -L/opt/local/lib
// ./test
//
extern mod core;
@nebuta
nebuta / verlet.hs
Last active December 14, 2015 17:29
Prototype of Verlet method in Haskell
import Data.List
import Control.Monad.Random
import Text.Printf
import System.Environment
import Debug.Trace
data PhaseSpace = PhaseSpace {
particles :: [(Pos,Momentum)]
}
@nebuta
nebuta / quicksort.rs
Last active December 14, 2015 18:39
Quick sort using generics in Rust
// quicksort.rs
use cmp::Ord;
fn partition<T: Ord>(ns: &mut [T], l: uint, r: uint) -> uint {
let p = &mut ns[l];
let mut i = l + 1;
for uint::range(l+1,r) |j| {
if ns[j] < *p {
ns[i] <-> ns[j];
@nebuta
nebuta / dijkstra.scala
Created March 11, 2013 07:25
Dijkstra's algorithm in Scala
/**
* Created with IntelliJ IDEA.
* User: hiroyuki
* Date: 3/10/13
* Time: 8:34 PM
* To change this template use File | Settings | File Templates.
*/
@nebuta
nebuta / gist:5538501
Created May 8, 2013 05:49
MutationObserver example
function findTitle(rec){
var res = undefined;
$.each(rec,function(){
if(this.localName == 'title'){
res = this.innerText;
}
});
return res;
}
@nebuta
nebuta / jubatus.rb
Created May 19, 2013 05:19
Jubatus classifier test
# -*- coding: utf-8 -*-
$host = "localhost"
$port = 9199
$name = "paper_genre"
require 'json'
require 'find'
require 'jubatus/classifier/client'
@nebuta
nebuta / jubatus_classify_tweetts.rb
Created May 19, 2013 07:59
Tweets classification test
# -*- coding: utf-8 -*-
$host = "localhost"
$port = 9199
$name = "twitter_user"
require 'json'
require 'find'
require 'jubatus/classifier/client'
@nebuta
nebuta / tweet_classify_result.txt
Created May 19, 2013 08:00
Twitter classification test result
今朝の朝日新聞。国家のコミットメントに関する岡崎哲二さんの議論が面白かった。 https://pic.twitter.com/rUa3uRWq8K
--->kenichiromogi
あー、実は、小倉→名古屋→小倉です。 @KimuSuhanえー!明日博多なのに!小倉→東京→博多ですか。頭下がります。お疲れ様です。@kenichiromogi: 新幹線なう。
--->kenichiromogi
慶一郎くん、ちゃんと寝なさいね! ‏@keiichiroshibuy事務所のソファで目覚めましとぅあ
--->kenichiromogi
読み方わからん! https://pic.twitter.com/GwGmAHEFEy
@nebuta
nebuta / tweet.json
Created May 19, 2013 08:04
Jubatus Twitter classification test
{
"method": "AROW",
"converter": {
"num_filter_types": {},
"num_filter_rules": [],
"string_filter_types": {},
"string_filter_rules": [],
"num_types": {},
"num_rules": [],