This file contains 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
(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 |
This file contains 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
def sumDigits(n:Int) = (0 /: ((n toString) toCharArray)) {(x,y) => x + y - '0'} | |
def displaySumDigits(n: Int) = println(sumDigits(n)) |
This file contains 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
sumDigits n = foldl (+) 0 (splitNumber n) | |
where splitNumber x | x < 10 = [x] | |
| otherwise = ((mod x 10):splitNumber (div x 10)) |
This file contains 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 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 |
This file contains 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
(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 |
This file contains 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
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 |
This file contains 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 ruby | |
# -*- mode: ruby; coding: utf-8 -*- | |
require 'base64' | |
require 'pp' | |
require 'rubygems' | |
require 'rev' | |
require 'json' | |
require 'g' |
This file contains 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
# -*- mode: ruby; coding: utf-8 -*- | |
# | |
# naive imitation #1 of NSNotificationCenter of Cocoa Framework | |
# | |
class NotificationCenter | |
def self.default | |
@instance ||= NotificationCenter.new |
This file contains 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 ruby | |
# -*- coding: utf-8 -*- | |
require 'base64' | |
require 'digest' | |
require 'openssl' | |
def encode(cryptkey, iv, cleardata) | |
cipher = OpenSSL::Cipher.new('AES-256-CBC') | |
cipher.encrypt |
This file contains 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/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"); |
OlderNewer