Mittwoch, 28. Dezember 2011

Install xfce4-power-manager Slackware 13.37 - shows no Battery status

http://goodies.xfce.org/projects/applications/xfce4-power-manager needs upower (http://slackbuilds.org/repository/13.37/system/upower/) - install upower, restart power-manager and battery state is fine.

Mittwoch, 21. Dezember 2011

setTimeout() && setInterval() scope problem solver

This is so handy from time to time:
setInterval(
    function () {
        var myVar = document.getElementById("givenID");
        setTimeout(
            function() {
                // myVar is available because the inner closure 
                // gets the outer closures scope
                myVar.innerHTML = "Junk";
        },2000);
    }, 10000);

Source: Stackoverflow

Dienstag, 20. Dezember 2011

Sencha Touch 1.1 - Adding a record and removing it doesn't work

I did the following and it worked well:
Add an entry - reload the app - delete that entry

I did the following and it didn't work:
Add an entry - delete that entry

Why?
I started to debug both cases paralelly. In both cases I found the new record in the object that is used to determine what has to be done, but for some strange reason in the case of adding and directly deleting that entry Sencha Touch doesn't find the entry. 

What I did is really simple: After running the store.remove(record) method I check if there's a record in the store.removed property. If not, I add that record manually. You can as well fully remove the store.remove(record) method call and write the record directly into the property. It's up to you.

After you did that you just need to call
store.destroy() to remove the record.

Sencha Touch 1.1 - CRUD actions & callbacks via REST proxy

CRUD actions
Methods without value param (update, destroy):
store.update({
    callback: function(answer, object, success) {
        if (success) { ... }
    }
});

store.destroy({
    callback: function(answer, object, success) {
        if (success) { ... }
    }
});


Methods with value param (create, load):
store.create(values, {
    callback: function(answer, object, success) {
        if (success) { ... }
    }
});

store.load({
    callback: function(answer, object, success) {
        if (success) { ... }
    }
});


CRUD action executes only once?
If you can run some of these functions once and after that no XHR is made, it may be because you encountered this bug: Bug @ Sencha Forum

I solved this bug by setting store.snapshot to false, so the function that engages the XHR is no longer looking for changes in the snapshot but in the store object.

Sonntag, 11. Dezember 2011

Enable cups

chmod +x /etc/rc.d/rc.cups
/etc/rc.d/rc.cups start

Source: alien slackbook 

Slackware local shutdown script (to wipe out /tmp etc.)

Doesn't exist, but according to rc.local it's ok to create & use it :)

/etc/rc.d/rc.local_shutdown

Chrome 15 from Slackbuild.org

Install libevent:
http://slackbuilds.org/repository/13.37/libraries/libevent/

then chromium:
http://slackbuilds.org/repository/13.37/network/chromium/

Customize XFCE4 Menu

http://wiki.xfce.org/howto/customize-menu

Desktop files are located here: /usr/local/share/applications | /usr/share/applications/

List only symbolic links in current directory

find . -type l -exec ls -la {} \;

Got to say that here: find with -exec param is sooooo mighty!

Mittwoch, 7. Dezember 2011

Copy files recursively without keeping directory structure (Linux)

We had to copy many files that were located in a very complex directory structure. The following snippet searches the current directory and its subdirectories for *.xml files & executes the cp command on every file it finds (the braces {} represent the file):

find -type f -iname '*.xml' -exec cp {} /target/dir/for/all/xmls/ \;

The target dir now contains all *.xml files without directories.

All Methods from a Javascript Object

I wrote that little helper because webdeveloper toolbar didn't show all methods to me. Maybe it's useful for you too.

https://gist.github.com/1441816

Donnerstag, 1. Dezember 2011

console.log & debug flag?

Instead of checking the DEBUG flag everytime you need a debug info, like this:

    if (DEBUG) {
        console.log("my debug output");
    }

you can just check the DEBUG flag once and disable the console.log function, like this:

    if (DEBUG === false) {
        console = {
            log: function() {}
        };
    }

This enables you to simply call:

    console.log("my debug output")

in your application. If DEBUG is true, you'll get your output. If DEBUG is false, console.log() will be called but is an empty function and thus will produce no output / error.

Samstag, 19. November 2011

Automated slackware package creation from given sourcefile

Slackware packages are a great (the only good way) to keep track of the installed software on (and to cleanly remove installed software from) your slackware machine.

Most packages that you can find in the www (slackbuilds.org, http://packages.slackware.it, ...) are outdated. You know that: Looking at slackbuilds.org for a tool, then looking at the version number and see that there's a source on the builders homepage that's x major and y minor releases further.

I, personally, hate to install 'old' software. I want the newest. So I have to built from source - make, ./configure --flags, make install to a DESTDIR, cp docs, change rights and makepkg at the end.

This sucks. To learn a bit about writing shellscripts I started to write a shellscript that does the job (yes, I know about pkgbuild). Currently it's able to:
  • remove old sources
  • remove old package
  • extract the source package (tar.gz / tar.bz2)
  • copy a given layout file (supported by apache httpd for instance)
  • make install to DESTDIR
  • create documentation directory
  • copy documentation files (like README, INSTALL, AUTHORS...)
  • chown root.root DESTDIR
  • build package with makepkg
  • echo build time
 And here is what I plan to add:
  • remove sources after successful build
  • remove installation from DESTDIR after successful build
  • automatically search SRCDIR for documentation and copy it
  • really important: create slack_desc for created package
  • really important: output last 5 rows if build fails
  • really important: check for $DESTDIR support
  • make it much cleaner
  • less params
Yesterday I built the whole xfce4 from source in approx 15 minutes. Added install.sh to installpkg the packages in the right order and et voilĂ  - installed xfce4 in 30 seconds. :-)

NOTE: I don't make any warranties that my script will work for you or won't fuck up your machine.
    So if you want to give it a try, look here: https://gist.github.com/1379368

    NOTE: I don't make any warranties that my script will work for you or won't fuck up your machine.

    Change keyboard layout in Slackware 13.37

    /usr/share/X11/xorg.conf.d/90-keyboard-layout.conf

    Sonntag, 2. Oktober 2011

    Measuring compile time to check overclocking of cpu

    Step 1:
    Use standard cpu clock and a source of medium size:
        time -p ./configure && make
    and note down time next to 'real'.

    Step2:
    Remove sources, extract again, overclock cpu and run

        time -p ./configure && make
    again. Compare the value next to 'real' with the noted down value.

    Dienstag, 27. September 2011

    Dienstag, 30. August 2011

    Styling Browser Validation Messages

    With HTML5 there came the great power of using the browsers built-in validation methods for <input> fields. Some days ago I heared a co-worker arguing that it's not possible to style the error messages generated by the browser. It's just wrong. You can style them, they are using pseudo classes and, of course, every browser uses different pseudo classes:

    Firefox: https://developer.mozilla.org/en/CSS/%3ainvalid
    Chrome [Webkit]: http://trac.webkit.org/browser/trunk/Source/WebCore/css/html.css (search for 'bubble' there)

    Sadly, if you want to use it today, you have to implement a fallback for IE.



    Donnerstag, 25. August 2011

    Coding Backwards

    Now this is a really cool idea how to get a gerneral idea of the design you really need (and this is NOT the design that comes to your mind FIRST):

    "I decided that I’d [...] write out a script using the yet unwritten API. I’d reverse-engineer a good design by pretending I’d already written one!"

    "A better design quickly appeared when I forced myself to preemptively eat my own dogfood. Instead of shoehorning use-cases into a class structure I’d already designed, I coded backwards and the opposite happened: a design evolved from daydreaming about an API that I’d like using."

    SOURCE: http://jameso.be/2011/08/19/coding-backwards.html



    Montag, 25. Juli 2011

    For all your opacity needs

    in this order:

    opacity: .5; // for all other browsers
    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; // for IE8
    filter: alpha(opacity=50); // for IE5-7

    Samstag, 23. Juli 2011

    JS Module Pattern

    var someModule = (function(){
    //private attributes
      var privateVar = 5;
    
      //private methods
      var privateMethod = function(){
      return 'Private Test';
      };
    
      return {
        //public attributes
        publicVar: 10,
        //public methods
        publicMethod: function(){
          return ' Followed By Public Test ';
        },
    
        //let's access the private members
        getData: function(){
          return privateMethod() + this.publicMethod() + privateVar;
        }
      }
    })(); //the parens here cause the anonymous function to execute and return
            
    someModule.getData();
    
    SOURCE: http://addyosmani.com/resources/essentialjsdesignpatterns/book/

    Dienstag, 19. Juli 2011

    Nyromodal Wiki Startpage is defective, use this older version instead

    http://bit.ly/qUra4h

    Nyromodal strips / removes script tag on ajax / xhr load

    Got me some time to get 'round this, here's the solution:

    "If you need to use an external JavaScript content, you could add the attribute rel="forceLoad" to the script tag and nyroModal will load it during the opening modal."


    "If you want to use a script which need the content to be visible (many jQuery UI script for instance) you could add the setting rev="shown" to the inline or external script tag to execute it juste before the endShowContent callback."

    Source: http://bit.ly/oJ8AeD

    Donnerstag, 14. Juli 2011

    "WindowsUpdate_80070570" "WindowsUpdate_80073712" Errors

    Fixed the above stated problem for me. EDIT: It also fixed a problem where the Service Pack couldn't be installed!

    net stop wuauserv
    net stop bits
    net stop cryptsvc
    ren %systemroot%\System32\Catroot2 Catroot2.old
    net start cryptsvc
    ren %systemroot%\SoftwareDistribution SoftwareDistribution.old
    regsvr32 wuapi.dll
    regsvr32 wuaueng.dll
    regsvr32 wucltux.dll
    regsvr32 wups2.dll
    regsvr32 wups.dll
    regsvr32 wuwebv.dll
    net start bits
    net start wuauserv
    net start Eventlog
    exit
    Reboot and try update again.

    SOURCE: http://answers.microsoft.com/en-us/windows/forum/windows_other-windows_update/windowsupdate80070570-windowsupdate80073712-errors/8a1ff2d4-0c96-495c-b22a-759f9b66f2e6

    Freitag, 8. Juli 2011

    On event.preventDefault() error messages in IE 8 (9? 7? 6?)

    If checking for event.preventDefault() you get error messages in IE.

    A better way is to check for the existence of event.returnValue (which is IEs preventDefault()) and if it doesn't exist you know that you're not on IE.

    if (event.returnValue) {
        // this is IE
        event.returnValue = false;
    } else {
        // this is Chrome, Firefox, Safari etc.
        event.preventDefault();
    }

    Sonntag, 19. Juni 2011

    JPG to DIV

    Spent some minutes doing this after a co-worker of mine had this idea. Here's the PHP-Script:
    <!doctype html>
    <html>
    <head>
    <style type="text/css">
    div {position: absolute;width: 1px; height: 1px;}
    </style>
    </head>
    <body>
    <?php
    $imagePath = 'path/to/picture/and/picname.jpg';
    $img = imagecreatefromjpeg($imagePath);
    $heightWidth = getimagesize($imagePath);
    $imgH = --$heightWidth[1];
    $imgW = --$heightWidth[0];
    for ($xc=0; $xc<=$imgH; $xc++) {
    for ($yc=0; $yc<=$imgW; $yc++) {
    $color_index = imagecolorat($img, $yc, $xc);
    $color_tran  = imagecolorsforindex($img, $color_index);
    echo '<div style="background:rgb('.$color_tran['red'].','.$color_tran['green'].','.$color_tran['blue'].');top:'.$xc.'px;left:'.$yc.'px;"></div>';
    }
    }
    ?>
    </body>
    </html>

    Using this one with a picture with more than 160.000 pixel will produce a html-file with a size of more than 10 Megabyte. The Script runs trough in less than a second, rendering the divs in the browser is what makes it unuseable, but it works well to around 200.000 pixel.

    Optimization ideas:
    • float instead of absolute (have no idea if that speeds up or slows down)
    • reduce the markup as much as possible
    • if the pixel next to the last rendered pixel hast the same color, the element could be extended, insted of placing a new element
    • some more, too lazy to write them down now...

    Mittwoch, 15. Juni 2011

    Javascript OOP Cheatsheet

    var MyClass = function() {

        // self to get "this" in private / global / anonymous methods
        var self = this;

        // public var
        this.publicVar = 'public';
        // private var
        var privateVar = 'private';

        // public method
        this.publicMethod = function() {}
        // private method
        function privateMethod() {}
        // global method
        globalMethod = function() {}

    }

    Freitag, 10. Juni 2011

    Imagemagick Ubuntu Install & Batch

    sudo apt-get install imagemagick
    convert -resize 25% -quality 80% *.jpg

    Installing php-unit via PEAR on Ubuntu 11.04 Natty

    sudo apt-get install apache2
    sudo apt-get install php5
    sudo apt-get install php5-curl

    enable curl.so in php5.ini

    sudo apt-get install php-pear
    sudo pear channel-discover pear.phpunit.de
    sudo pear channel-discover components.ez.no
    sudo pear channel-discover pear.symfony-project.com
    sudo pear update-channels
    sudo pear upgrade
    sudo pear install phpunit/PHPUnit

    sudo /etc/init.d/apache2 restart