Skip to content

Instantly share code, notes, and snippets.

View nikuuchi's full-sized avatar

uchida nikuuchi

  • Tokyo, Japan
View GitHub Profile
@nikuuchi
nikuuchi / brain.rb
Created August 20, 2011 12:47
テキストファイルをbrainf*ckにエンコードするスクリプト。とりあえず思いつくままに書いた。
def square op,len
s = (len**(0.5)).to_i
t = (s<8)? "+"*s : square("+",s)
m = len - (s**2)
m = (m< 8) ? op * m : square( op,m)
">"+t+"[<"+op*s+">-]<"+m
end
def encode ch,point
@nikuuchi
nikuuchi / fizzbuzz.ml
Created October 8, 2011 06:21
OcamlでFizzBuzz
let fizzbuzz n = match n mod 3, n mod 5 with
| 0,0 -> print_string "fizzbuzz\n"
| 0,_ -> print_string "fizz\n"
| _,0 -> print_string "buzz\n"
| _,_ -> print_int n;
print_string "\n";;
let rec loop x = match x with
| 100 -> fizzbuzz(x)
@nikuuchi
nikuuchi / split.cc
Created December 5, 2011 04:39
split関数の自作
#include <iostream>
#include <vector>
#include <string>
using namespace std;
//split()
void split(string str,string delim,vector<string> *v){
int i=0;
while((i = str.find_first_of(delim)) != string::npos){
@nikuuchi
nikuuchi / random.sh
Created December 9, 2011 05:13
100個の8桁以下のランダムな整数を出力する。あんまりうまくない作りなので、もう少し良いものが必要になったら作る。
#!/usr/bin/env bash
for i in {0..99};\
do \
num=`expr $i % 8 + 1`\
cat /dev/urandom | tr -c -d "[:digit:]" | head -c $num |sed -e 's/^00*/1/g';\
echo '';\
done;
@nikuuchi
nikuuchi / emacsrun.sh
Created January 23, 2012 04:31
Emacsのデーモンを立ち上げる時に、既にデーモンが立ち上がっているときに早めに検出して無駄に立ち上げる時間を省く。
#!/usr/bin/env bash
num=`ps aux|grep emacs\ -nw\ --daemon|wc -l`
if [ $num = 1 ]
then
TERM=xterm-256color emacs -nw --daemon
else
echo 'Emacs is already running.'
fi
@nikuuchi
nikuuchi / xss_helper.php
Created January 24, 2012 12:20
CodeIgniterでXSS対策のhtmlspecialcharsを使いやすくするだけのhelper
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if ( ! function_exists('h'))
{
function h($str)
{
return htmlspecialchars($str,ENT_QUOTES,"UTF-8");
}
}
@nikuuchi
nikuuchi / closure.php
Created January 29, 2012 10:49
PHP5.3以降ならクロージャが使えると聞いて。
<?php
function f(){
$i=0;
return function() use(&$i){
return $i++;
};
};
$c = f();
foreach(range(0,10) as $a){
echo $c(),"\n";
@nikuuchi
nikuuchi / fibo.ml
Created March 7, 2012 05:52
ocamloptとocamlcの速度の違いを見たかったのでフィボナッチ書いてみた。
let rec fibo n = if n < 2
then 1
else fibo(n-1)+fibo(n-2);;
print_int(fibo(36));;
print_string("\n");;
@nikuuchi
nikuuchi / dict.rb
Created November 2, 2012 07:48
辞書引くためにブラウザ使うのが面倒だったから。
#!/usr/bin/env ruby
require 'open-uri'
require 'nokogiri'
dict = Nokogiri::HTML(open("http://ejje.weblio.jp/content/#{ARGV[0].downcase}")).search("div.Kejje")
dict.search("script").remove
dict.search("div.level0").each{|node| puts node.text.delete("\r")}
@nikuuchi
nikuuchi / hosts
Created November 5, 2012 07:37
東海道線
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.59.150 totsuka
192.168.59.151 ofuna
192.168.59.160 fujisawa