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 -Ku | |
# encoding: utf-8 | |
require 'rubygems' | |
require 'dm-core' | |
DataMapper::Logger.new($stdout, :debug) | |
DataMapper.setup(:default, 'sqlite3::memory:') | |
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
my $cursor = $collection->find( | |
{ run_mode => 'production' }, | |
{ sort_by => { start_time => 1 } }, | |
)->fields( { system_id => 1, main_stage => { duration => 1 } } ); | |
# Returns everything under "main_stage", not just "duration". | |
# Is it possible to do nested field spec like this? |
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
use strict; | |
use warnings; | |
use Data::Dumper; | |
# Assume that we've got sentence-aligned stuff | |
my $sentence_pairs = [ | |
[ [ qw( the book ) ], [ qw( das buch ) ], ], | |
# [ [ qw( the house ) ], [ qw( das haus ) ], ], |
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
ben@mini:~ $ sudo gem install rocco | |
Building native extensions. This could take a while... | |
ERROR: Error installing rocco: | |
ERROR: Failed to build gem native extension. | |
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb | |
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h | |
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/rdiscount-1.6.5 for inspection. |
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
# Hack to make Carp::Assert work with Log4perl | |
# Stops warnings like "Prototype mismatch: sub Foo::DEBUG: none vs () at ... | |
BEGIN { | |
use Carp::Assert; | |
use Carp::Assert::More; | |
*ADEBUG = *DEBUG; | |
undef *DEBUG; | |
}; |
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
use strict; | |
use warnings; | |
use utf8; | |
use MongoDB; | |
my $conn = MongoDB::Connection->new(host => 'unixdeva11', port => 21337); | |
my $db = $conn->get_database('foo'); | |
my $coll = $db->get_collection('bar'); |
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
# I admit I'm not really sure what's going on here | |
# UTF8 in Perl still confuses the hell out of me | |
# But i'm not sure what MongoDB is doing or trying to do either | |
# It seems that it's treating keys and values differently | |
# Namely, by encoding values and not encoding keys. | |
# Can anyone suggest what's I *Should* be doing? | |
# I want to store UTF8 data and get back UTF8 data | |
use strict; |
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
require 'pp' | |
input = <<eos | |
Hello there | |
eos | |
# Randomise order of a-z | |
rand_characters = ('a'..'z').sort_by { rand } | |
encoding = Hash.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
# Transliterate-hacked from Perl | |
# http://blog.naver.com/PostView.nhn?blogId=mokomoji&logNo=130013133481 | |
$KCODE = 'UTF8' | |
class String | |
# I think in the original the text was forced to cp949... | |
def split_korean | |
# ㄱ ㄲ ㄴ ㄷ ㄸ ㄹ ㅁ ㅂ ㅃ ㅅ ㅆ ㅇ ㅈ ㅉ ㅊ ㅋ ㅌ ㅍ ㅎ | |
chosung = [0x3131, 0x3132, 0x3134, 0x3137, 0x3138, 0x3139, 0x3141, 0x3142, 0x3143, 0x3145, 0x3146, 0x3147, 0x3148, 0x3149, 0x314a, 0x314b, 0x314c, 0x314d, 0x314e] |
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
# Ben's Magical Perceptron | |
def dot_product(a, b): | |
return sum([a[i]*b[i] for i in range(len(a))]) | |
def decision( x, w, theta ): | |
return (dot_product(x, w) > theta) | |
OlderNewer