Skip to content

Instantly share code, notes, and snippets.

@mugyu
mugyu / gist:1804489
Created February 11, 2012 21:56
N-gram
class String
def ngram(n)
characters = self.each_char.to_a
return [self] if characters.size <= n
return characters.each_cons(n).map(&:join)
end
end
@mugyu
mugyu / gist:1807002
Created February 12, 2012 07:08
Gaucheでプロセス実行
;;;; Gauche process
(use gauche.process)
(run-process '(notepad) :wait #t)
(let1 process (run-process '(notepad))
; ...do some other work ...
(process-wait process))
@mugyu
mugyu / gist:1807158
Created February 12, 2012 07:58
Gauche で hello world!
;;;; Gauche hello
(print "Hello, Gauche!!!")
(format #t "Hello, ~s!~s\n" 'Gauche '!!)
(print (format #f "Hello, ~s!~s\n" 'Gauche '!!))
(display "Hello, Gauche!!!\n")
(write "Hello, Gauche!!!")
@mugyu
mugyu / gist:1808352
Created February 12, 2012 12:58
Gauche でカリーとクロージャー
;;;; Gauche Closure
(define make_person
(lambda (name)
(lambda (say)
(print name ": " say))))
(define (make_person2 name) ; syntax sugar
(lambda (say)
(print name ": " say)))
@mugyu
mugyu / gist:1808435
Created February 12, 2012 13:23
Gauche で引数をとる。ファイル名
;;;; Gauche Arguments
(define (main args)
(print args)
(print (car args)) ; SRFI22
(print *program-name*) ; Gauche
)
; (args.scm foo bar)
; args.scm
; args.scm
@mugyu
mugyu / gist:1908429
Created February 25, 2012 13:09
Rubyでニコ動のタイトルやサムネ画像URLを取得したりとか
#!/usr/bin/env ruby
# vim: fileencoding=utf-8
require 'open-uri'
module NicoVideo
GETTHUMBINFO_URL = "http://ext.nicovideo.jp/api/getthumbinfo"
OK_STRING = %q|<nicovideo_thumb_response status="ok">|
FAIL_STRING = %q|<nicovideo_thumb_response status="fail">|
ELEMENTS = [:title,
:description,
@mugyu
mugyu / gist:2001143
Created March 8, 2012 14:09
Gaucheでニコ動のタイトルやサムネ画像URLを取得したりとか
(use rfc.http)
(use rfc.uri)
(define-constant *getthumbinfo-url* "http://ext.nicovideo.jp/api/getthumbinfo")
(define-constant *ok-string* "<nicovideo_thumb_response status=\"ok\">")
(define-constant *fail-string* "<nicovideo_thumb_response status=\"fail\">")
(define-constant *elements* '(title description thumbnail_url watch_url))
(define (getthumbinfo video-id)
(receive (code status body)
@mugyu
mugyu / gist:2011065
Created March 10, 2012 10:17
GaucheでhttpファイルをGET
(use rfc.http)
(use rfc.uri)
(define (uri-get uri)
(receive (code status body)
(receive (scheme user-info hostname port path query frament)
(uri-parse uri)
(if (eq? path #f)
(http-get hostname "/")
(http-get hostname path)))
@mugyu
mugyu / gist:2013285
Created March 10, 2012 21:25
schemeで等価述語の例
(equal? (list 1 2 3) (list 1 2 3)) ; => #t
((lambda (p) (eq? p p)) (cons 1 2)) ; => #t
(eq? 'example 'example) ; => #t
(eqv? 1 1) ; => #t
(eqv? 1 1.0) ; => #f
(= 1 1.0) ; => #t
(char=? #\a #\a) ; => #t
(string=? "example" "example") ; => #t
(char-ci=? #\a #\A) ; => #t
(string-ci=? "example" "EXAMPLE") ; => #t
@mugyu
mugyu / gist:2015387
Created March 11, 2012 07:12
Schemeで等価述語以外の述語の例
(pair? '(1)) ; => #t
(null? '()) ; => #t
(list? (list)) ; => #t
(boolean? #f) ; => #t
(symbol? 'example) ; => #t
(number? 1) ; => #t
(char? #\a) ; => #t
(string? "string") ; => #t
(odd? 1) ; => #t
(even? 2) ; => #t