Skip to content

Instantly share code, notes, and snippets.

View shouya's full-sized avatar

shouya

  • Open for Hire!
  • UTC+9
View GitHub Profile
@shouya
shouya / ngram.rb
Created June 28, 2015 22:37
an improved bigram word segmentating algorithm
def clean(txt)
mark = true
txt.each_char.map { |x|
if x.ascii_only? and mark
mark = false
' '
elsif x.ascii_only?
nil
else
mark = true
@shouya
shouya / change.rb
Last active September 27, 2015 02:55
presentation @ gzruby, oct 2014
class Operation < Struct.new(:name, :args, :block)
class << self
attr_accessor :opposite_operations
end
def self.define_opposite_operations(name, name_of_opposite)
@opposite_operations ||= {}
@opposite_operations[name] = name_of_opposite
@opposite_operations[name_of_opposite] = name
end
@shouya
shouya / 24pts.c
Created February 18, 2012 19:18
24-point implement using rpn way
#include <stdio.h> /* for printf */
/* constants declaration */
#define TOTAL 24.f
#define PRECISION 0.001f /* for float number comparison */
#define MAX_POINT 13
#define MIN_POINT 1
#define NUM_CARDS 4
@shouya
shouya / sync_photo.sh
Created March 17, 2012 08:49
A batch operation script to sync the pictures from my phone to pc.
#!/bin/bash
: << DOC
This script does scan all the photo from my phone and pull them out into a
temporary directory. After then, it will arrange the photos into special
directory by taken date, and if the target directory does not exist, the script
will create one to store such files. Subsequently and optionally, it could
convert all the photos imported into wiki image size and put the outputs into
another temporary directory, and show me them to deal.
@shouya
shouya / wikiphoto.sh
Created March 17, 2012 08:54
Resize photo to smaller scale for to upload to my wiki
#!/bin/bash
extname=".jpg"
def_size_wid=1024
new_wid=0
[[ "$#" -lt "1" ]] && exit 0
filename="$1"
@shouya
shouya / increaser.turing
Created June 22, 2012 15:41
A Turing Machine program of a simple increaser.
/*
A TURING MACHINE PROGRAM OF A SIMPLE INCREASER
(it does increase a binary number continously)
*/
TYPE SYMBOL:
. 0 1
TAPE:
@shouya
shouya / increaser.turing
Created June 22, 2012 15:41
A Turing Machine program of a simple increaser.
/*
A TURING MACHINE PROGRAM OF A SIMPLE INCREASER
(it does increase a binary number continously)
*/
TYPE SYMBOL:
. 0 1
TAPE:
@shouya
shouya / do-times.scm
Created June 22, 2012 15:48
A short scheme macro demonstration(like dotimes in Common Lisp)
(define-macro do-times
(lambda (times . body)
(let ((rest-time (gensym))
(loop-func-name (gensym)))
(begin
`(letrec ((,loop-func-name
(lambda (,rest-time)
(if (= ,rest-time 0) '()
(begin
,@body
(define-macro my-let
(lambda (args . body)
(let ((names (map car args))
(vals (map cadr args)))
(cons (cons 'lambda (cons names body)) vals))))
(define-macro my-let-2
(lambda (args . body)
@shouya
shouya / file.poem
Created September 15, 2012 07:44
挑戰龍的勇士
我崇敬挑戰龍而失敗的勇士,而不是皇帝。
我期待的是一種平衡,一種可以維持永久的,自然而包容萬物的平衡,將世界置於其中,然後,把發現者燒死。
我願意為機器賦予智慧,把所有人類的骸骨,變作空氣,把他們剩下的東西——如果有的話,完全消除。
我熱愛的統一已不在遠處,我來了,我來了,我會把整個世界,壓縮入一個原子之中,讓不存在的東西,歸於混沌。
我帶來的是劍,獻給我崇敬的挑戰龍的勇士。