Skip to content

Instantly share code, notes, and snippets.

View draftcode's full-sized avatar

Masaya Suzuki draftcode

View GitHub Profile
Number divOrig := Number getSlot("/")
Number "/" := method(k, if(k == 0, 0, self divOrig(k)))
sum_two_dim := method(ll,
ll map(l, l sum) sum
)
sum_two_dim(list(list(1,2,3), list(4,5,6), list(7,8,9,10))) println
sum_dim_flat := method(ll,
ll map(l, if(l isKindOf(List), sum_dim_flat(l), l)) sum
)
List foldLeft := method(
context := Object clone prependProto(call sender)
if(call sender hasLocalSlot("self"),
context setSlot("self", call sender self)
)
initValue := call message evalArg(0)
eName := call message argAt(1) name
eResult := call message argAt(2) name
#include <stdio.h>
#include <IOKit/IOCFPlugIn.h>
#include <IOKit/hid/IOHIDKeys.h>
#include <CoreFoundation/CoreFoundation.h>
int main(void)
{
IOReturn result = kIOReturnSuccess;
io_iterator_t hidObjectIterator = 0;
io_object_t hidDevice = IO_OBJECT_NULL;
#!/usr/bin/ruby
# ISBN13のコードをISBN10に変換して読書メーターのページを開くスクリプト
def isbn13_to_isbn10(s)
i = 10
sum = 0
s[3..-2].split(//).each do |c|
sum += c.to_i * i
i -= 1
end
#!/usr/bin/ruby
# レーベンシュタイン距離を算出するスクリプト
def LevenshteinDistance(s1, s2)
arr = Array.new(s1.size+1)
(0..(s1.size)).each do |i|
arr[i] = Array.new(s2.size+1)
arr[i][0] = i
end
(0..(s2.size)).each do |i|
replicate :: Int -> a -> [a]
replicate n x = [x | _ <- [1..n]]
pyths :: Int -> [(Int, Int, Int)]
pyths n = [(x,y,z) | x <- [1..n], y <- [1..n], z <- [1..n], x^2 + y^2 == z^2]
factors :: Int -> [Int]
factors n = [x | x <- [1..n], n `mod` x == 0]
perfects :: Int -> [Int]
import Data.Char
positions :: (Eq a) => a -> [a] -> [Int]
positions t xs = [n | (x,n) <- zip xs [0..(length xs)-1], x == t]
count :: Char -> String -> Int
count c (x:xs) | c == x = 1 + count c xs
| otherwise = count c xs
count _ [] = 0
import os, re, datetime
class CST_tzinfo(datetime.tzinfo):
def utcoffset(self, dt):
return datetime.timedelta(hours=+8) + self.dst(dt)
def dst(self, dt):
return datetime.timedelta(0)
def tzname(self, dt):
#!/usr/bin/env python
import urllib
import re
import logging
def extract_booklist(user_id, category="", kininaru="0"):
page = 1
while(True):
url = "http://book.akahoshitakuya.com/u/%s/booklist%s&p=%s" % \
(user_id, category, page)