Friday, 5 October 2012

Useful mysql commands

So, using MySQL on the command line I faced the annoyance that any tables I completed were not subject to autocomplete during that session. It really is so much quicker when table names and columns autocomplete.


It was one of the more challengingly obscure thing to find on google since I wasn't really sure what I was looking for.

Finally discovered it was called 'rehashing'.


Slashdot suggests that you can set up auto-rehash by either opening the client using the command
mysql --auto-rehash -u root -p

or putting it into the my.cnf file:
[mysql]
auto-rehash

source: http://stackoverflow.com/questions/8332338/mysql-console-autocomplete-names


To do it in an active session I finally found the commands
\# 
or
rehash

source: http://kedar.nitty-witty.com/blog/5-useful-mysql-command-options-pager-prompt-rehash-tee-system 






update - another one (23/10/2015). to view one screen of results at a time, you can use less:
pager less;


to revert back to standard output
pager;

Friday, 28 September 2012

Bash shortcuts

works in MySQL too:  
 
CTRL-a - Moves the cursor the start of the line
CTRL-e - Moves the cursor to the end of the line

Benchmarking Perl functions

 Benchmark is outstanding for comparing performance of perl functions.

#!/usr/bin/perl
use Benchmark qw(:all) ;

cmpthese(10000, {
        'Trial 1' => sub{
                my $i=0;
                for(my $j=1; $j<100; $j++){
                        $i=$j;
                }
        },

        'Trial 2' => sub{
                my $i=99;
        },

});

print "Done\n";




Gives output:

          Rate Trial 1 Trial 2
Trial 1  977/s      --    -86%
Trial 2 6803/s    597%      --
Done



Through this I was able to determine that for high speed use you shouldn't bother testing the existence of a key in a hash table.

I was also able to determine that nested ifs are better than multiple conditions in a single if.

I.e.
if(A && B && C && D){
}
is worse than
if(A){
  if(B){
    if(C){
      if(D){
      }
    }
  }
}



*best not doing this in an Amazon ec2 micro instance as repeated tests may put a limit on CPU usage and skew results*

Thursday, 27 September 2012

Man in the middle (MITM) attacks

It's bloody hard to set up sslsniff.

After trying Fiddler, Burp and Charles, I found Charles the most useful and used it for my totally legal experiments.

www.charlesproxy.com

(I bought it too, to thank them for the effort they saved me)