This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Number divOrig := Number getSlot("/") | |
| Number "/" := method(k, if(k == 0, 0, self divOrig(k))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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) |