Skip to content

Instantly share code, notes, and snippets.

@atton
atton / hoge.rb
Created March 28, 2013 10:53
prime division から再構成
299999.prime_division.map{|a,b| a**b}.inject(:*)
@atton
atton / lisp.rb
Last active December 15, 2015 17:59 — forked from tompng/lisp2.rb
require './lisp_base.rb'
LISP do (cons 1,2) end
LISP do (cond true,(cond false,(cons 1,2),(cons 3,4)),(cons 5,6)) end
LISP do (defun :fact,:x,(cond (eq :x,0),1,(mult (sqrt (square :x)),(fact (minus :x,1))))) end
LISP do (defun :abs,:x,(cond (lt :x,0),(minus 0,:x),:x)) end
LISP do
(defun :sqrtrec,:x,:y,:d,
(cond (lt :d,0.0000000001),
:y,
(cond (lt (mult :y,:y),:x),
@atton
atton / okrb2.rb
Last active December 17, 2015 05:59
flush するスタイルに変更
#!/usr/bin/env ruby
# Okinawarb.new.H.e.l.l.o.comma.space.w.o.r.l.d!.flush("\n")
# => output 'Hello, wrold!'
class String
CharTable = {comma:',', space:' '}
def flush str
print self, str
end
@atton
atton / HookMonad.hs
Last active December 21, 2015 05:49
HookMonad. but it's not satisfy Monad Law
data HookMonad a = Hook (a -> a) a
instance Monad HookMonad where
return = Hook id
Hook h x >>= f = f . h $ x
nonMinusPoint = Hook (\x -> if x < 0 then 0 else x)
getValue (Hook f x) = f x
@atton
atton / Vagrantfile
Created October 11, 2013 05:16
Fedora19 with MySQL on Vagrant and puppet
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "fedora-19"
config.vm.provision :puppet do |puppet|
@atton
atton / read_pypy.py
Created November 26, 2013 13:07
source for read astcompiler on pypy
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# script location : pypy top directory
import sys
from pypy.objspace.std import StdObjSpace
from pypy.interpreter.pyparser import pyparse, pytoken
from pypy.interpreter.pyparser.test import expressions
from pypy.interpreter.pyparser.error import SyntaxError, IndentationError
from pypy.interpreter.pycode import PyCode
@atton
atton / hoge.zsh
Created February 21, 2014 10:54
blog-zsh-completion
compctl -K _hoge hoge
_hoge() {
local words completions
read -cA words
completions="$(look ${words[-1]})"
reply=("${(ps:\n:)completions}")
}
; east asian ambiguous settings
(defun set-east-asian-ambiguous-width (width)
(cond ((= emacs-major-version 22) (set-east-asian-ambiguous-width-22 width))
((> emacs-major-version 22) (set-east-asian-ambiguous-width-23 width))))
; for emacs 22
(defun set-east-asian-ambiguous-width-22 (width)
(if (= width 2)
(utf-translate-cjk-set-unicode-range
; east asian ambiguous character table
(defun east-asian-ambiguous-characters ()
'(
(#x00A1 . #x00A1) (#x00A4 . #x00A4) (#x00A7 . #x00A8)
(#x00AA . #x00AA) (#x00AD . #x00AE) (#x00B0 . #x00B4)
(#x00B6 . #x00BA) (#x00BC . #x00BF) (#x00C6 . #x00C6)
(#x00D0 . #x00D0) (#x00D7 . #x00D8) (#x00DE . #x00E1)
(#x00E6 . #x00E6) (#x00E8 . #x00EA) (#x00EC . #x00ED)
(#x00F0 . #x00F0) (#x00F2 . #x00F3) (#x00F7 . #x00FA)
(#x00FC . #x00FC) (#x00FE . #x00FE) (#x0101 . #x0101)
@atton
atton / my-bool.hs
Created March 28, 2014 01:49
foldl and foldr on flipped Bool for infinite list
data B = T | F
deriving (Eq, Show)
(&&&) :: B -> B -> B
b &&& T = b
_ &&& F = F
(|||) :: B -> B -> B
_ ||| T = T
b ||| F = b