
No idea how to solve hard IT problems? Try to do something new. Open your mind!
/Stanislaw Wyspianski, "The creation of the world", stained glass, Franciszkanow church, Krakow, PL/
Talking uses energy, doing creates it
current perl:
$foo = [ map { ... } @$bar ]
better perl:
$foo = map { } $bar
%hash = (foo => 42);
$hash{foo} # where is hash sign, % ?
@list = qw/foo bar baz/;
$list[1] # where is list sign, @ ?
$list[1][2] # wolf
$$list[1][2] # dog1
$list->[1][2] # dog2
$list->[1]->[2] # dog3
$ref = \@list;
$ref = [@ref]
# maybe it is @list?
$ref = [ $some->method ]
# or maybe it is %hash?
$ref = { $some->method }
# could be better to make something like
$ref = $some->method->return_as_hashref
$ref = $some->method->return_as_arrayref
Controller app::foo;
sub index : Private {
my ($self, $c, $param1) = @_;
}
sub show : Local {
my ($self, $c, $param1) = @_;
}
sub index : LocalRegex('^(.*)$') {
my ( $self, $c ) = @_;
my ($param1) = @{ $c->req->captures };
}
ALTER TABLE `news` CHANGE `body` `body` BLOB NULL DEFAULT NULL; ALTER TABLE `news` CHANGE `body` `body` TEXT CHARACTER SET utf8 NULL DEFAULT NULL;
$wide_char_string = Encode::decode_utf8($octets)
Encode::is_utf8($checked_string)
length($octets) > length($wide_char_string)
(octet_string eq unicode_string) == falseYou cannot compare such strings without decode/encode, they are natively different!
{linux, osx, freebsd, solaris}$ groups {windows - active directory}> dsquery user -samid %USERNAME%|dsget user -memberof
{linux, osx, bsd}$ du -sh
{linux}$ du --max-depth=1 {osx, bsd}$ du -d1 {SunOS}$ du
{linux}$ du --max-depth=1 -kx|sort -n {osx, bsd}$ du -d1 -kx|sort -n
{linux}$ find . -regextype posix-extended -type f -regex ".*\.(java|class)" {osx, bsd}$ find -E . -type f -regex ".*\.(java|class)"
{linux, osx}$ lsof {freebsd}$ fstat
{linux}$ vmstat 3 {osx, bsd}$ iostat 3
{linux}$ free {freebsd}$ swapinfo {osx}$ vm_stat {osx}$ top -l 1 -s 0 -n 0
{linux}$ netstat -apne --inet {osx}$ lsof -i {freebsd}$ sockstat {SunOS}$ netstat {windows}$ netstat -b netstat -b -v # slower but with tree of dependencies
{linux}$ lsmod {osx}$ kextstat {freebsd}$ kldstat
{linux}$ modprobe SomeModule {freebsd}$ kldload SomeModule
{linux}$ rmmod SomeModule {freebsd}$ kldunload SomeModule
{linux}$ strace {osx}$ dtrace {freebsd}$ truss (strace is also available in /usr/ports/devel/strace)
{linux}$ ldconfig -p {freebsd}$ ldconfig -r
{freebsd}$ pkg_info -W /path/to/checked_file {debian ubuntu}$ dpkg -S /path/to/checked_file {redhat centos}$ rpm -qf /path/to/file {osx, for brew}$ ls -l `which node`|perl -lane '{print $F[-1]}'
OsX - it shows the original brew package/file this command is linked to
{linux}$ apt-cache search your_name {freebsd}$ cd /usr/ports; make search key=your_name make search name=pear display=name,path you can also try simple locate (only in package names): {freebsd}$ locate -i your_name | grep "/usr/ports/" {redhat centos}$ yum search name yum provides name
{debian ubuntu}$ apt-get install package_name {redhat centos}$ yum install name {freebsd}$ pkg_add -r package_name {windows}$ msiexec /i package.msi {osx}$ ???In FreeBSD you have packages made in distribution release time - unfortunately there are no binary upgrades for released version)
{debian ubuntu}$ apt-get update; apt-get upgrade {redhat centos}$ yum update
{debian ubuntu}$ apt-src {freebsd}$ cd /usr/ports/path/package; make install clean {osx}$ use brew or macports
Couldn't instantiate component "app::Model::app", "->config->{schema_class} must be defined for this model
app.yaml
app_local.yaml
$> Python
>>> foo = "bla bla bla"
>>> foo.upper()
'BLA BLA BLA'
>>> foo.len()
Traceback (most recent call last):
File "", line 1, in ?
AttributeError: 'str' object has no attribute 'len'
>>> len(foo)
11
irb> foo.upcase
=> "BLA BLA BLA"
irb> foo.length
=> 11
var = 123 # string
$var = 123 # global variable
@var = 123 # class variable
@@var = 123 # package variable
def class1
attr_reader :duration
end
# which is a shortcut of:
def class1
attr_reader(:duration)
end
# which is a shortcut of:
def class1
def duration
@duration
end
end
# which is a shortcut of:
def class1
def duration
return(@duration)
end
end
runfastcgi(method="threaded", daemonize="false")
TypeError: runfastcgi() got an unexpected keyword argument 'method'
===============================>
Concurrency Level: 25
Failed requests: 21 (in 15k reqs)
Average: 127 requests/sec.
1-min load after: 11.93
=============================>
Concurrency Level: 25
Failed requests: 0 (in 15k reqs)
Average: 118 requests/sec.
1-min load after: 2.49
Server Software:
Server Hostname: localhost
Server Port: 3000
Document Path: /gallery/
Document Length: 7185 bytes
Concurrency Level: 1
Time taken for tests: 64.568406 seconds
Complete requests: 5000
Failed requests: 0
Write errors: 0
Total transferred: 36675000 bytes
HTML transferred: 35925000 bytes
Requests per second: 77.44 [#/sec] (mean)
Time per request: 12.914 [ms] (mean)
Time per request: 12.914 [ms] (mean, across all concurrent requests)
Transfer rate: 554.68 [Kbytes/sec] received
Server Software: WSGIServer/0.1
Server Hostname: localhost
Server Port: 8000
Document Path: /
Document Length: 4981 bytes
Concurrency Level: 1
Time taken for tests: 61.358104 seconds
Complete requests: 5000
Failed requests: 0
Write errors: 0
Total transferred: 25625000 bytes
HTML transferred: 24905000 bytes
Requests per second: 81.49 [#/sec] (mean)
Time per request: 12.272 [ms] (mean)
Time per request: 12.272 [ms] (mean, across all concurrent requests)
Transfer rate: 407.84 [Kbytes/sec] received
urlpatterns = patterns('',
('', 'hnl.photos.views.index'), # root page
(r'^admin/', include('django.contrib.admin.urls')), # admin
(r'^photo/update', 'hnl.photos.views.update'), # update
)
{% for repo in gallery_list %}
* {{ repo.galleryname }}
{% endfor %}
sub new {
my $classname = shift;
my $rh = {}; # Reference to Hash, rh :)
bless $rh, $classname;
return $rh;
}
my $foo = my_class->new();
$foo->{bar} = 42;
print $foo->{bar};
package my_class;
use fields qw(bar); # declare used object vars
sub new {
my $classname = shift;
return fields::new $classname;
}
# usage:
my my_class $foo = my_class->new();
$foo->{baz} = 42; # trying to use not declared field - error!
print $foo->{bar}; # works
package my_class;
{
my %bar; # All vars are declared as hashes
sub new {
my $classname = shift;
my $rs = \do{ my $scalar }; # reference to scalar
bless $rs, $classname;
return $rs;
}
sub set_bar {
my $this = shift;
$bar{$this} = shift;
}
sub get_bar {
my $this = shift;
return $bar{$this};
}
}
Potential problem: it's not working with threads. To have a copy of such object instance in threads, you need to workaround this closure with get_all_data()/set_all_data() methods - and all object data need to be passed as additional parameters when creating new thread.
my $foo = my_class->new();
$foo->{bar} = 42; # sorry, no bonus! Use set/get method instead.
print $foo->{bar}; # This is private variable, not accessible outside class.
print $foo->get_bar(); # works!
use Perl6::Classes;
class Composer {
submethod BUILD { print "Giving birth to a new composer\n" }
method compose { print "Writing some music...\n" }
}
class ClassicalComposer is Composer {
method compose {
print "Writing some muzak...\n";
$_->do_private;
}
method do_private is private { print "really private thing\n" }
}
class ModernComposer is Composer {
submethod BUILD($) { $.length = shift }
method compose() { print((map { int rand 10 } 1..$.length), "\n") }
has $.length;
}
my $beethoven = new ClassicalComposer;
my $barber = new ModernComposer 4;
my $mahler = ModernComposer->new(400);
$beethoven->compose; # Writing some muzak...
$barber->compose; # 7214
#$beethoven->do_private;
compose $mahler; # 8927586934796837469875
Perl6::Classes works as a filter for code and do all this translation job. Well, we pay for it - it is 20x slower than hash/scalar blessed objects. If this latency doesn't matter - use it.