A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Jump to

Quick reference

Showing posts with label comparisons. Show all posts
Showing posts with label comparisons. Show all posts

Flat file vs database

Flat file
  • Easy to set up, only have to consider local file permissions
  • Easy to implement in an ad-hoc way, ideal for a prototype
    • Plain text for very simple things like a list
    • JSON/YAML/Perl for complex data structures
  • Doesn't work when the app is load balanced across multiple servers
  • Not automatically backed up
  • Amazon S3 is relatively expensive
  • Have to make your own model
Database
  • Requires up-front schema design - more work, but forces you to consider design of data 
  • You can put business logic in the ResultSet models
  • Requires an instance to be provisioned
  • Easy cross-referencing of data
  • Works when the app is load balanced across multiple servers
  • Backup-as-a-service (i.e. replication)
  • Amazon RDS is cheaper than S3
  • Get the model for free with ORM
Conclusion

For production services that have redundancy (load balanced), always use a database unless the overhead of setting one up for the first time is considered too high for the business.

Use Data::Compare to compare data outside a test

Need to compare data outside of a test, without generating "ok" / "not ok" TAP output? Use Data::Compare.

Open source code review tools comparison

Options I'm familiar with for Subversion:
  • ReviewBoard - good, but fiddly to install. Emails all your comments in a batch when you're ready.
  • Atlassian Stash - okay but generates one email per comment. No, that's been fixed!
  • Kallithea - looks good, not tried.

Perl modules for SOAP

Options/notes:
  • W3C::Soap - not good
  • SOAP::Lite - not as good as XML::Compile
  • XML::Compile - recommended
    • XML::Compile::SOAP
    • XML::Compile::SOAP11
    • XML::Compile::WSDL11
...but generally SOAP isn't much fun.
Expect the WSDL to be wrong, you may need to store a "fixed" copy locally.

How to install ruby, rake, rubygems

https://www.ruby-lang.org/en/documentation/installation/

For ruby, tried:
  • https://rvm.io/ - wouldn't work on my Suse setup
  • https://github.com/sstephenson/rbenv#readme - worked on Suse. Promising, I like.
    • https://github.com/sstephenson/ruby-build#readme - doesn't work


For rubygems, tried:
  • https://rubygems.org/pages/download - worked

For rake:

  • It comes with ruby


Now learn Ruby:
https://github.com/neo/ruby_koans


Search engines

List:

  • HP Autonomy IDOL
  • Google search appliance
  • Solr / Lucene
  • Atlassian Jira/Wiki search
  • Knowledge bases (untested):
    • http://www.helpgizmo.com/
    • https://www.zendesk.com/knowledge-base
    • http://www.knowledgebase-script.com/
    • http://www.spiceworks.com/free-it-knowledge-base-software/

Perl Tests: Better output when comparison fails

use Test::More;
use Test::Differences;

is_deeply($actual, $expected, 'foo') or eq_or_diff($actual, $expected, 'oof');

or

is_deeply($actual, $expected, 'foo') or diag explain $actual;

Case sensitive MySQL column

Make a case sensitive varchar column:

CREATE TABLE `page_dm` (
`url` varchar(500) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL,
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html
http://dev.mysql.com/doc/refman/5.0/en/create-table.html

Perl test comparison methods

use Test::More tests => 23;
# or
use Test::More qw(no_plan);
ok($got eq $expected, $test_name);
like ($got, qr/expected/, $test_name);
is_deeply($got_complex_structure, $expected_complex_structure, $test_name);
Compare data structures
eq_or_diff $got, $expected, "description"
Test::Lazy
No descriptions required
# Will evaluate the code and check it:
try('qw/a/' => eq => 'a');
# Don't evaluate, but still compare:
check(1 => is => 1);

Bash variable comparisons

...bash logic...

Note that integer and string comparison use a different set of operators.
integer comparison
-eq
is equal to
if [ "$a" -eq "$b" ]
-ne
is not equal to
if [ "$a" -ne "$b" ]
-gt
is greater than
if [ "$a" -gt "$b" ]
-ge
is greater than or equal to
if [ "$a" -ge "$b" ]
-lt
is less than
if [ "$a" -lt "$b" ]
-le
is less than or equal to
if [ "$a" -le "$b" ]
<
is less than (within double parentheses)
(("$a" < "$b"))
<=
is less than or equal to (within double parentheses)
(("$a" <= "$b"))
>
is greater than (within double parentheses)
(("$a" > "$b"))
>=
is greater than or equal to (within double parentheses)
(("$a" >= "$b"))

string comparison
=

is equal to
if [ "$a" = "$b" ]
==
is equal to
if [ "$a" == "$b" ]
This is a synonym for =.