Skip to content

Instantly share code, notes, and snippets.

@zby
zby / gist:2623391
Created May 6, 2012 17:25
writing to a file
Import System
Import System.IO
Class Test
Public Shared Sub Main()
Try
' Create an instance of StreamReader to read from a file.
Dim sr As StreamReader = New StreamReader("TestFile.txt")
Dim line As String
' Read and display the lines from the file until the end
@zby
zby / gist:2508353
Created April 27, 2012 10:53
pure but using objects
sub markdown {
my( $text, $title ) = @_;
my $parser = Markdent::Simple::Document->new();
return $parser->markdown_to_html(
title => 'My Document',
markdown => $markdown,
);
}
sub sum {
my @values = @_;
my $sum = 0;
for my $i ( @values ){
$sum += $i;
}
return $sum;
}
@zby
zby / gist:2404904
Created April 17, 2012 09:37
OUTPUT
ok 1 - literal
not ok 2 - eval
# Failed test 'eval'
# at tmp/unicode_test.pl line 18.
Wide character in print at /usr/share/perl5/Test/Builder.pm line 1759.
# got: '�'
# expected: 'ó'
SV = PV(0x1c87dd8) at 0x1cca1b8
REFCNT = 1
FLAGS = (PADMY,POK,pPOK,UTF8)
@zby
zby / gist:2404891
Created April 17, 2012 09:35
A Data::Dumper bug - or Latin1 strikes again
use strict;
use warnings;
use utf8;
use Devel::Peek;
use Test::More;
use Data::Dumper;
$Data::Dumper::Terse = 1;
@zby
zby / gist:1992168
Created March 7, 2012 09:27
Moose based had made Factory (instead of Bread::Board)
{
package Factory;
use Moose;
has log_file_name => ( is => 'ro', default => "logfile.log" );
has logger => ( is => 'ro', lazy_build => 1 );
sub _build_logger { FileLogger->new( log_file_name => shift->log_file_name ) }
has dsn => ( is => 'ro', default => "dbi:SQLite:dbname=my-app.db" );
@zby
zby / gist:1986752
Created March 6, 2012 15:15
without Bread::Board
my $log_file_name = "logfile.log";
my $logger = FileLogger->new( log_file_name => $log_file_name );
my $dsn = "dbi:SQLite:dbname=my-app.db";
my $username = "user234";
my $password = "****";
my $dbh = do {
require DBI;
@zby
zby / gist:1986741
Created March 6, 2012 15:13
Bread::Board synopsis
use Bread::Board;
my $c = container 'MyApp' => as {
service 'log_file_name' => "logfile.log";
service 'logger' => (
class => 'FileLogger',
lifecycle => 'Singleton',
dependencies => [
@zby
zby / gist:1176451
Created August 28, 2011 09:04
ioc library versus hand coded deps injection
$scope->register('routes', class => 'Lamework::Routes');
$scope->register(
'dispatcher',
class => 'Lamework::Dispatcher::Routes',
deps => 'routes'
);
$scope->register(action_namespace => (ref $self) . '::Action::');
$scope->register(
'action_builder',
@zby
zby / gist:766591
Created January 5, 2011 17:00
After DI
package MyClass;
sub new {
my ( $class, $dbh );
my $self = bless { dbh => $dbh }, $class;