Stoppt die Vorratsdatenspeicherung - www.vorratsdatenspeicherung.de

Archive for the ‘Development’ Category

Brainfuck

Tuesday, March 16th, 2010

Hmmm… Kleine Fingerübung in Perl (pre-alpha :-) )

Ah ja: Brainfuck: http://lmgtfy.com/?q=Brainfuck

#!/usr/bin/env perl
use Term::ReadKey;
ReadMode 'raw';
my $debug = 0;

my $code;
if ($ARGV[0]){
  { local $/ = undef; local *FILE; open FILE, "<".$ARGV[0]; $code = <FILE>; close FILE }
}

$code ||=
">+++++++++[<+++++++++++++>-]<-.-----.+++++++
.>+++[>++++++++++<-]
>++.<<----.+++.
--------- . -------.>++++[<+++++>-]<+.>++++++++++.";

$code =~ s/[^\.,+-\[\]<>]//msg;
$| = 1;
my @val;
@val[ 0 .. 29999 ] = (0) x 30000;
my $vpt = 0;
my @ls;
my @le;
my $lpt = 0;
my $cc  = 0;
my @c   = split( '', $code );
my $nc  = @c;
while ( $cc < $nc ) {
    $_ = $c[ $cc++ ];
    print "vpt:$vpt \$val[\$vpt]"
      . $val[$vpt]
      . " loop_counter:$loop_counter loop(counter)_start:"
      . $ls[$loop_counter]
      . " loop(counter)_end:"
      . $le[$loop_counter]
      . " cc:$cc command:$_\n"
      if $debug;
    /</ and do { $vpt        and $vpt--; next };
    />/ and do { $vpt < @val and $vpt++; next };
    /\+/ and do { $val[$vpt] = $val[$vpt] + 1; next; };
    /\-/ and do { $val[$vpt] = $val[$vpt] - 1; next; };
    /\./ and do { print chr( $val[$vpt] ); next; };
    /\,/ and do { $val[$vpt] = ord( ReadKey 0 ); next; };
    /\[/ and do {
        if   ( $val[$vpt] ) { $ls[ $lpt++ ] = $cc - 1 }
        else                { $cc = defined $le[$lpt] ? $le[$lpt] : (index($code,']',$cc)+1) }
        next;
    };
    /\]/ and do {
        $le[ --$lpt ] = $cc;
        $cc = $ls[$lpt];
        next;
    };
}
print "\n";

Establish a 2nd database connection in Rails

Thursday, June 18th, 2009

OK, you can find some howto’s everywhere on the web but only on this site I found the complete solution:

class SecondConnection < ActiveRecord::Base

SecondConnection.establish_connection(
:adapter  => "informix",
:host     => "localhost",
:username => "hansnase",
:password => "very_secret",
:database => "ccdb@localhost"
)

self.abstract_class = true
end

“self.abstract_class = true” makes the thing actually work. Otherwise Rails seems to cache the database connection and does not switch back if you access any other classes but SecondConnection.

Yeah!

Later: Not so Yeah…

I had to establish another call to

  ActiveRecord::Base.establish_connection
       logger.info { "Establishing Base Connection" }
       log_connections

I assume it’s either an Informix problem or related to the old rails version I’m driving with.
Nevertheless: It works now.

Rails and incoming mails on a Mac Leopard workstation

Wednesday, June 17th, 2009

Obviously I’m in a need of such an installation, otherwise I wouldn’t have googled about this (btw.: Do you know lmgtfy.com).

Here are some snippets from:

  1. ChrizDee
  2. Craig Ambrose

And? What did I do:

I first enabled Postfix using 1). After this I have changed /etc/aliases:


echo 'rails_mailer: "|/usr/local/bin/mail_handler.rb"' >> /etc/aliases
chmod 755 /usr/local/bin/mail_handler.rb"' >> /etc/aliases
sudo newaliases
sudo postfix reload
#!/usr/bin/ruby
require 'net/http'
require 'uri'Net::HTTP.post_form URI.parse('http://localhost:3000/emails'), { "email" => STDIN.read }

The script above will be triggered by every mail that will be sent to rails_mailer@localhost (resp. your hostname). It will put a post-request to localhost:3000/email including the email in the parameter “email”.

Ein paar Ruby-Schnipsel

Wednesday, June 10th, 2009

Ein paar Lebensretter für mich:

Sourcecode and Wordpress

Friday, March 20th, 2009

At last…

I found the plugin SyntaxHilighter forWordPress (wasn’t that hard. It’s part of the WordPress FAQ) to solve my formatting problems…

Rails Snippets — Arbitrary SQL

Thursday, February 26th, 2009

Seems I’m in a Ruby/Rails mood today

Sometimes you don’t need the whole Rails stuff and just want to place a query.

Try the following:
[code]]czo0OTpcIkFjdGl2ZVJlY29yZDo6QmFzZS5jb25uZWN0aW9uLihzZWxlY3RfYWxsfHVwZGF0ZSlcIjt7WyYqJl19[[/code]
will do the trick.
Example:

[code]]czo3NDpcImxpc3QgPSBBY3RpdmVSZWNvcmQ6OkJhc2UuY29ubmVjdGlvbi5zZWxlY3RfYWxsKFwic2VsZWN0IGEsYiBmcm9tIGNfdGFie1smKiZdfWxlXCIpXCI7e1smKiZdfQ==[[/code]

==> [ {a => Value_for_a, b => Value_for_b}, {a => Value...}...]

[code]]czoxMTc6XCIgbnVtYmVyX29mX3Jvd3MgPSBBY3RpdmVSZWNvcmQ6OkJhc2UuY29ubmVjdGlvbi51cGRhdGUoXCJ1cGRhdGUgbW9udGgge1smKiZdfXNldCBtb250aF9pZCA9IG1vbnRoX2lkICsxIHdoZXJlIG1vbnRoX2lkID0gMTFcIilcIjt7WyYqJl19[[/code]

If you make use of an already created Rails Model instead of the base class, you will get the benefit of accessors (instead of hash-keys) for the  selected objects.

Example (necessary, I know :-) )

  • create the model

[code]]czozMDpcIiMgc2NyaXB0L2dlbmVyYXRlIG1vZGVsIENUYWJsZVwiO3tbJiomXX0=[[/code]

  • use it in your code

[code]]czo1MzpcIiBsaXN0ID0gQ1RhYmxlLmZpbmRfYnlfc3FsKFwic2VsZWN0IGEsYiBmcm9tIGNfdGFibGVcIilcIjt7WyYqJl19[[/code]

  • access elements

[code]]czoxMjpcInBwIGxpc3RbMF0uYVwiO3tbJiomXX0=[[/code]

Rails Snippets

Thursday, February 26th, 2009

OK, this is more Ruby than Rails but nevertheless helpful…

If you come from a Perl background you will be surprised that in Ruby an array is definitively not a list. So if you want to pass a list of elements to a method that you have stored in an array, you may want to use the following idiom:
[code]]czoxMTU6XCJsaXN0ID0gW10NCmxpbmVzID0gRmlsZS5yZWFkbGluZXMoXCJGSUxFTkFNRVwiKQ0KbGluZXMuZWFjaCBkbyB8bGluZXwNCntbJiomXX1saXN0LnB1c2goUmVzdWx0Lm5ldygqbGluZS5zcGxpdChcIiBcIikpKQ0KZW5kDQpcIjt7WyYqJl19[[/code]
The [code]]czoxNjpcIipsaW5lLnNwbGl0KFwiIFwiKVwiO3tbJiomXX0=[[/code] creates an element list out of the array that the split command has created.

I fear a real Rubyist would have done it in a different way but OK.

P.S. Does someone know what I'm doing wrong with the code formatting in WordPress? I'm quite sure to have included whitespaces in the code above...

Jboss Seam

Thursday, February 26th, 2009

Hobbyprojekt :-)

Ich wollte mal ausprobieren, was es mit SEAM so auf sich hat.

Vor dem Erfolg (Hello World) gibt’s allerdings erst ‘mal ne Menge Installationsarbeit zu erledigen. Da ich masochistisch veranlagt bin (?) habe ich das ganze Geraffel unter Mac OS-X Leopard installiert und mich dabei von dieser Anleitung hier inspirieren lassen.

Auf geht’s:

  1. Download bzw. Installation von Eclipse Ganymede (ich hab’ die neueste Version genommen)
  2. JBoss Application Server (AS) laden: Hier (auch hier die neueste… Ich erwähn’s nicht mehr :-) )
    Achtung: Es geht nur mit Version 4.2.X für JDK 1.5
    Leopard ist da etwas zurück (nix mit 1.6)
  3. SEAM
  4. Mysql installieren über diesen Link
  5. Der Mysql-Connector: Hier
  6. Ordner anlegen z.B. unter /Users/tov/Documents/Development/Seam
  7. Ganymede in diesen Ordner packen (Terminal; tar xzvf DATEINAME.tgz) –> Ordner “eclipse”
  8. Dann mkdir jboss
  9. cd jboss
  10. mv ~/Downloads/jboss* .
  11. tar xzvf jboss… und tar xzvf jboss-seam… (Dateinamen bitte anpassen)
  12. cd ..
  13. eclipse/eclipse -data workspace -vmargs -Xmx512M -Xms254M -XX:MaxPermSize=254M
  14. warten… (zumindestens auf meinem 2GHz/2GByte MacBook)
  15. Eclipse Updates installierenHelp->Software Updates…->Available Software Tab->Add Sitehttp://download.jboss.org/jbosstools/updates/development eintragen

Ich habe dann mal die MySQL etc. Anweisungen aus obigem Post befolgt und bin an der Stelle “Neuanlegen eines Projektes” gescheitert (classpath, error, mail.jar etc.)

Die (wahrscheinlich nicht korrekte) Lösung für das Problem war dann ein beherztes:
[code]]czoxMDM6XCINCmNkIC9Vc2Vycy90b3YvRG9jdW1lbnRzL0RldmVsb3BtZW50L1NlYW0vamJvc3MvamJvc3MtNS4wLjEuR0ENCmNwIC17WyYqJl19UiBjb21tb24vbGliLyogc2VydmVyL2RlZmF1bHQvbGliL1wiO3tbJiomXX0=[[/code]

Danach ließ sich das Projekt anlegen!

Nochmal Achtung Ich glaube, dass das bei dem 4.2x er JBoss nicht nötig ist!

Projekt

Rails Snippets

Wednesday, February 25th, 2009

Some small snippets of Rails/Ruby codes that I’d like to not forget…

I found an interesting site on the Web: http://matthall.wordpress.com/2006/12/06/how-to-execute-a-rails-controller-action-via-cron/ 

Tweaking it a bit:
[code]]czoyMTQ6XCJyZXF1aXJlIFwnLi4vY29uZmlnL2Vudmlyb25tZW50XCcNCnJlcXVpcmUgXCdwcFwnDQppZCA9IEFSR1ZbMF0NCmlmIGlkLm5pe1smKiZdfWw/DQpyYWlzZSAmbHQ7PGVvZj4NClVTQUdFOiAkMCBSRVNFTExFUl9JRA0KZW9mDQplbmQNCmFwcCA9IEFjdGlvbkNvbnRyb2xsZXJ7WyYqJl19OjpJbnRlZ3JhdGlvbjo6U2Vzc2lvbi5uZXcNCmFwcC5nZXQgXCIva3VuZGVuL3N0YXR1c19tYWlsLyN7aWR9XCI8L2VvZj5cIjt7WyYqJl19[[/code]

This works fine from a Rails subdirectory and calls the same action like http://RAILSSITE/kunden/status_mail/ID

_Mein_ Everyday GIT

Friday, February 6th, 2009

Mal ein Versuch meinen privaten GIT-Arbeitszyklus zu dokumentieren…

Dieses Post wird wohl ab und zu verändert werden :-)

 

 

Arbeitszyklus mit GIT

Start

  1. Entweder neu erstellen eines Repositories oder kopieren:
    1. Erstellen
      1. mkdir Name
      2. cd Name
      3. git init
    2. Kopieren
      1. git clone username@hostname:/PFAD/Name
  2. edit/compile/fix
  3. Commit
    1. git add . (fügt alle neuen Dateien hinzu)
    2. git commit -a -m „KOMMENTAR“ 
    3. git push (zurück ins Repository)

Wenn das Repository ein sogenanntes „non-bare“ Repository ist (also mit Working-Tree), werden die Änderungen dort _nicht_ ins Working Directory eingetragen. Wenn dort nichts verändert wurde (also kein Merge notwendig ist), kann mittels

git reset –hard (http://git.or.cz/gitwiki/GitFaq#head-b96f48bc9c925074be9f95c0fce69bcece5f6e73)

der neue Sourcecode aktiviert werden. 

Alternative: Benutzen eines „post-update-hooks“

http://utsl.gen.nz/git/post-update

Eintragen in .git/hooks/post-update (auf dem Ziel-Repository)

  1. auch: http://www.mail-archive.com/git@vger.kernel.org/msg03458.html

Damit reicht dann das „push“ von der Remote-Maschine, um ein Merge des Repositories zu erreichen!

Wenn im Master Repository (also dem, in das gerade gepushed wurde) vorher kein Commit durchgeführt wurde, werden die lokalen Änderungen gestashed

http://www.kernel.org/pub/software/scm/git/docs/git-stash.html

Mittels 

git stash apply

können die ebenfalls reingemerged werden

 

 

Rollback nach einem fehlgeschlagenen Merge

[code]]czoxNzpcImdpdCBwdWxsIGJsYWZhc2VsXCI7e1smKiZdfQ==[[/code]
hat mal wieder (OK... Das kommt nicht so häufig vor; Es ist ja schließlich nicht Subversion :-) ) diverse Konflikte gemeldet und nur weil vorher lokal irgendetwas vergessen wurde.
Ausweg:

[code]]czoxNjpcImdpdCByZXNldCAtLWhhcmRcIjt7WyYqJl19[[/code]
Alles ist wieder gut (wie vorher).