Skip to content

Instantly share code, notes, and snippets.

View chezou's full-sized avatar

Aki Ariga chezou

View GitHub Profile
@chezou
chezou / re2test.cpp
Created November 25, 2011 12:39
Sample of re2 libirary in Japanese
#compile g++ -Wall re2test.cpp -o re2.out -lre2 -lpthread
#include <iostream>
#include <string>
#include <re2/re2.h>
#include <cassert>
using namespace std;
int main(int argc, char **argv){
@chezou
chezou / re2test2.cpp
Created November 25, 2011 15:42
Sample cord of re2 of PartialMatchN
#include <iostream>
#include <string>
#include <re2/re2.h>
#include <vector>
using namespace std;
int main(){
string str("あぶらかたぶら");
@chezou
chezou / re2test3.cpp
Created November 26, 2011 01:09
Sample code of re2 using FindAndConsume for repeatable match
#include <iostream>
#include <string>
#include <re2/re2.h>
#include <vector>
using namespace std;
int main(){
string str("あぶらかたぶら");
@chezou
chezou / re2testbasic.cpp
Created November 26, 2011 12:05
Sample code of re2 basic regexp functions.
#include <iostream>
#include <string>
#include <re2/re2.h>
#include <vector>
using namespace std;
void test_fullmatch(){
string s,t;
string str("あぶらかたぶら");
@chezou
chezou / split_url.rb
Created February 28, 2013 13:57
Split a url file into some files. Same hosts are written in the same file.
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'URI'
file = ARGV.shift
num_split = ARGV.shift.to_i
order = Math::log10(num_split).truncate + 1
url_hash = {}
@chezou
chezou / gist:6246395
Last active December 21, 2015 03:59
lvc with pygments
function lvc() { if [ -f $1 ]; then pygmentize -O encoding=utf-8 "$1" |lv -c; fi; }
@chezou
chezou / gist:6247546
Created August 16, 2013 05:34
pygmentsの使い方
```
$ pip install pygments
```
```
$ diff templates.py templates.py.old
57d56
< filenames = ['*.erb']
```
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import Mykytea
import sys, codecs
class WordSegmenter:
def __init__(self, opt = "-out tok"):
self.mk = Mykytea.Mykytea(opt)
@chezou
chezou / gist:7659172
Created November 26, 2013 14:26
linear regression
require 'narray'
require 'rational'
phi = NMatrix.object(3,4).collect!{ Rational(rand(10)) }
t = NVector.float(4).collect!{ Rational(rand(10)) }
w = (phi.transpose * phi).lu.solve(phi.transpose * t)
foo = 'foo'
str = <<EOS, foo
hoge
EOS
# => ["hoge\n", "foo"]