Skip to content

Instantly share code, notes, and snippets.

View cesare's full-sized avatar

SAWADA Tadashi cesare

View GitHub Profile
(define (sum-digits n)
(fold + 0 (map (lambda (c) (- (char->integer c) 48)) (string->list (number->string n)))))
(define (display-sum-digits n)
(print (sum-digits n)))
;; inspired by technohippy. see also http://gist.github.com/271049
def sumDigits(n:Int) = (0 /: ((n toString) toCharArray)) {(x,y) => x + y - '0'}
def displaySumDigits(n: Int) = println(sumDigits(n))
sumDigits n = foldl (+) 0 (splitNumber n)
where splitNumber x | x < 10 = [x]
| otherwise = ((mod x 10):splitNumber (div x 10))
#!/usr/bin/env ruby
#
# make a summary of attendees who registered an event on ATND.org
# Usage:
# ATNDees.rb ${event_id}
#
# Output:
# creates CSV file in the current directory.
#
# see also: http://atnd.org
(define (remains lst key)
(cond ((null? lst) -1)
((eq? (car lst) key) (length (cdr lst)))
(else (remains (cdr lst) key))))
(define sample-list '(World is not enough))
(remains sample-list 'World) ;; => 3
(remains sample-list 'is) ;; => 2
(remains sample-list 'enough) ;; => 0
remains :: (Eq a) => [a] -> a -> Int
remains lst key = length (dropWhile (/= key) lst) -1
-- inspired by yuroyoro.
-- see also http://d.hatena.ne.jp/yuroyoro/20100205/1265363784
-- http://kaitenn.blogspot.com/2010/01/scala-list.html
#!/usr/bin/env ruby
# -*- mode: ruby; coding: utf-8 -*-
require 'base64'
require 'pp'
require 'rubygems'
require 'rev'
require 'json'
require 'g'
# -*- mode: ruby; coding: utf-8 -*-
#
# naive imitation #1 of NSNotificationCenter of Cocoa Framework
#
class NotificationCenter
def self.default
@instance ||= NotificationCenter.new
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'base64'
require 'digest'
require 'openssl'
def encode(cryptkey, iv, cleardata)
cipher = OpenSSL::Cipher.new('AES-256-CBC')
cipher.encrypt
#! /usr/bin/perl -w
use Crypt::Rijndael;
use Digest::SHA;
my $cleartext = "Here is some data for the coding"; # 32 bytes
my $iv = 'a2xhcgAAAAAAAAAA';
my $hash_1 = Digest::SHA->new(256); # SHA256
$hash_1->add("Nixnogen");