Rails Own Logger

On July 16, 2011, in Uncategorized, by tov

I was in need of a logging mechanism that prints all log messages with a “severity” that equals or is higher of “INFO” to STDOUT (I’m using multilog for actual logging stuff).

As I wasn’t able to google a solution I came up with the following (not quite elaborated) code:

 

class OwnLogger < Logger

    include Severity
    SEV_LABEL = %w(DEBUG INFO WARN ERROR FATAL ANY)

    def add(severity, message = nil, progname = nil, &block)
      time = Time.now
      if ENV['LOG_FROM_INFO_TO_STDOUT']
        if severity >= INFO
          msg = "#{$$}:#{SEV_LABEL[severity]}:" + time.strftime("%Y-%m-%dT%H:%M:%S.") << "%06d " % time.usec + ":"
          if message.nil?
            if block_given?
              message = yield
            else
              message = progname
              progname = @progname

            end
            msg += message.to_s
            puts msg
          end
        end
        super
      end

    end

So if you put the following lines in your /config/application.rb you’ll get what I got :-)

config.logger = OwnLogger.new(File.dirname(__FILE__) + "/../log/#{ENV['PROCNAME']}#{Rails.env}.log")

AND (most important) you’ll still have the “normal” logfile containing all messages


						
 

Schuhmacherei Janisch

On July 12, 2011, in Empfehlungen, by tov

Schamlose Werbung :-)

Wenn Ihr liebgewordene Schuhe mal nicht wegwerfen sondern lieber reparieren lassen wollt und zufällig in der Nähe von Solingen seid, dann besucht doch mal die Familie Janisch.

Die erledigen das dann für Euch…

Details unter Schuhmacherei-Janisch.de

Klare Empfehlung von mir!

Tagged with:  

Just took me 2 hours of Googling…

I found:
http://stackoverflow.com/questions/246983/informix-how-to-get-an-id-of-the-last-inserted-record

[...]The value of the last SERIAL insert is stored in the SQLCA record, as the second entry in the sqlerrd array. Brian’s answer is correct for ESQL/C, but you haven’t mentioned what language you’re using.
If you’re writing a stored procedure, the value can be found thus:
LET new_id = DBINFO(‚sqlca.sqlerrd1‘);
It can also be found in $sth->{ix_sqlerrd}[1] if using DBI
There are variants for other languages/interfaces, but I’m sure you’ll get the idea.
[...]

I got the idea and have created the following procedure

CREATE PROCEDURE lastid ()
RETURNING integer;
DEFINE lastid integer;
LET lastid = DBINFO(‘sqlca.sqlerrd1′);
RETURN lastid;
END PROCEDURE

So to get the latest column you just use

select lastid() from table(set{1})

btw.: If you want to make use of this in Rails, I’d some success with:

class InformixConnect < ActiveRecord::Base
self.abstract_class = true
establish_connection :development_informix

def save
super
self.id = self.connection.select_value(“select lastid() from table(set{1})”)
end

end

so a model like

class Customer < InformixConnect
        
end

would be able to connect to Informix and to get correct values from the DB without the
usage of sequences!

ERROR
Unfortunately the stuff above (overwriting the save method) does not work for some reasons.

I have patched

class InformixAdapter < AbstractAdapter

def prefetch_primary_key?(table_name = nil)
false
end
….

def insert(sql, name= nil, pk= nil, id_value= nil, sequence_name = nil)
execute(sql)
select_value(“select lastid() from table(set{1})”)
end
…..

This works!

Tagged with:  

So it happened again:

Most of my application icons were broken, i.e. only visible in a very low resolution.

After googling a bit I found the following discussion:
http://discussions.apple.com/thread.jspa?threadID=2142401

mdi’s suggestion did the trick for me: http://discussions.apple.com/message.jspa?messageID=10296267#10296267

What I did:

  • open Terminal.app (If you never did… : Try „spotlight-search“ –> Terminal)
  • enter cd /private/var/folders
  • enter sudo find . -name “com.apple.QuickLook.thumbnailcache”|xargs sudo rm -rf

                (you will have to enter your password)

  • Restart Finder.app using „Apple-Menu–> „quit immediately (It’s „Sofort Beenden“ in German. Dunno the english term) or press
  • command+option+escape“. Chose „Finder restart“.
  • Be happy :-)

OK, to be honest I had to restart to be really happy :-|

Tagged with:  

Argh…
This f…ine error message above has been thrown during a

records = Model.find(:first).

Guess why:

I made use of a legacy table that contained the attribute „type“. I just had to add a

self.inheritance_column=’itype’

into my model and now everything’s OK.

Rails: Do you consider this as friendly error messages?

 

Brainfuck

On March 16, 2010, in Development, Programmierung, by tov

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 = ; 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 < @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";
 

Blogging via MacJournal

On March 10, 2010, in Apple, by tov

Umpft.
Ich konnte dem aktuellen http://www.macheist.com Nano-Bundle natürlich doch nicht widerstehen. Monkey-Islands war eine Versuchung wert und vor allen Dingen Tweetie 2.0.

Jetzt habe ich auch noch MacJournal dazu bekommen und bin eigentlich ziemlich begeistert.

  • Blogging mit einem vernünftigen Client
  • Verschlüsselung privater Einträge
  • Export von Einträgen als HTML, PDF etc.
  • Volltextsuche via Spotlight.
  • Synchronisation via Mobile-Me (muss noch TeamDrive ausprobieren)

Und alle so „Yeah“!

P.S. Und die Probleme von Safari mit WordPress brauchen mich jetzt auch nicht mehr zu kümmern

 

Spendenaktion für Haiti

On January 15, 2010, in Politics, by tov

@johnny von Spreeblick hat eine Spendenaktion für die Erdbebenopfer von Haiti in’s Leben gerufen.

Nicht, dass es nicht auch andere Wege des Spendens gäbe, aber das Problem ist ja (und das löst sich durch solche Aktionen halt), dass “man” (ja, auch ich) in der Regel den A… ja nicht hochkriegt.

Also: Wenn Ihr Eure Kontonummer noch kennt, einfach mal auf obigen Link clicken!

Danke sehr!

 

How to delete an LVM snapshot

On December 21, 2009, in Hosting, Linux, by tov

Problem: Centos did not boot after a failure with an LVM snapshot.

It got stuck at:

Setting up Logical Volume Management: (part of rc.sysinit)

Solution:

Boot:
1) grub “e” (to edit the first line)
2) append “init = /bin/bash” to kernel parameters
3) boot (Enter, “b”)

(append “Single” should work as well but it didn’t as far as I remember)

Console
1) mount / -o remount (enables rw mode)
2) vi /etc/lvm/lvm.conf
3) replace
locking_dir = “/var/lock/lvm”
by
locking_dir = “/tmp”
(this is because “lvremove” does not recognize the –ignorelockingfailure parameter)
4) cd /sbin
5) ./lvm.static lvdisplay –ignorelockingfailure (not sure if this param is necessary after editing lvm.conf)
6) Find the snapshot path: /dev/your_volumegroup/your_logical_volume_snapshot
7) remove: ./lvm.static lvremove /dev/your_volumegroup/your_logical_volume_snapshot
8) reboot
9) be happy as it works now!

10) ask yourself if you should have re-edited lvm.conf…

I have forgotten to do so but as “/tmp” is more or less recommended in lvm.conf.

Hope that helps either people or me (in future).

 

Seems that it sometimes only pretends to have deleted the f…ine dustbin.

Try

cd /d C:\$Recycle.bin
dir /AH
rd /s /q “NameOfFolder”

if you need some space