Derek Kwok

Full-stack developer. Creator of 500boards.

About Me

[picture of me will be added soon]

I'm currently working on 500boards.

I'm a full-stack web developer - which means I manage servers, write back-end and front-end code for web applications.

This blog's engine is built with Python and Django. See my GitHub Repo for more information.

More about me:

Contact

Send me an email to: [email protected]

  • Listing Directory Sizes [Command Line Edition]

    The command to use is:
    du -hd 1 <directory>
    For example, if I wanted to list the size of all directories in my home folder, I would use:
    $ du -hd 1 ~
      0B	/Users/derekkwok/.Trash
     83M	/Users/derekkwok/.android
     56M	/Users/derekkwok/.bower
     96K	/Users/derekkwok/.dbvis
    6.8M	/Users/derekkwok/.dropbox
      0B	/Users/derekkwok/.dvdcss
    253M	/Users/derekkwok/.env
    
        ... snipped ...
    
     12K	/Users/derekkwok/Pictures
    957M	/Users/derekkwok/Projects
      0B	/Users/derekkwok/Public
     20G	/Users/derekkwok
    This command is also convenient in that it lists the total folder size also as the last entry.

    Loading...

  • Remember to close zip in python!

    I spent an hour today trying to debug the following code:
    if self.zip:
        self.zip.storage.delete(self.zip.path)
    
        temp_zip_file = tempfile.NamedTemporaryFile(mode='w')
        temp_zip = zipfile.ZipFile(manga_zip_file.name, 'w')
    
        # write other files into temp_zip
    
        self.zip.save('', File(open(temp_zip_file.name)))
    
    I spent a good chunk of time trying to figure out why the zip being saved is invalid. It turns out that I needed to add:
    temp_zip.close() # this writes the zip file ending records, making this a valid zipfile
    I should have read the [documentations](http://docs.python.org/2/library/zipfile) more closely!

    Loading...

  • Keeping Track of CSS Rule and Selector Count

    I came across a very useful little snippet of JS today that counts the number of CSS rules and selectors you have.
    function countCSSRules() {
        var results = '',
                log = '';
        if (!document.styleSheets) {
            return;
        }
        for (var i = 0; i < document.styleSheets.length; i++) {
            countSheet(document.styleSheets[i]);
        }
        function countSheet(sheet) {
            var count = 0;
            if (sheet && sheet.cssRules) {
                for (var j = 0, l = sheet.cssRules.length; j < l; j++) {
                    if (!sheet.cssRules[j].selectorText) continue;
                    count += sheet.cssRules[j].selectorText.split(',').length;
                }
    
                log += '\nFile: ' + (sheet.href ? sheet.href : 'inline <style> tag');
                log += '\nRules: ' + sheet.cssRules.length;
                log += '\nSelectors: ' + count;
                log += '\n--------------------------';            
            }
        }
        console.log(log);
        console.log(results);
    };
    countCSSRules();
    Usually I place this script inside a <script> tag in my projects, which outputs the results to the browser console. This script is only loaded in development environments. Source: https://gist.github.com/psebborn/1885511

    Loading...

  • Using FFmpeg to extract MKV subtitles

    Source: http://superuser.com/questions/556179/unable-to-extract-mkv-attachments-with-ffmpeg In short, the command you should run is this:
    ffmpeg -dump_attachment:t "" -i test.mkv
    This dumps all the attachment files into your current working directory.

    Loading...

  • List of Image Placeholder Services

    Source: http://news.ycombinator.com/item?id=4906942 Below is an organized list of placeholder sites mentioned in the comments section: * [Fake images please?](http://fakeimg.pl/) * [lorempixel](http://lorempixel.com/) * [Placehold.it](http://placehold.it/) * [{placekitten}](http://placekitten.com/) * [pugholder!](http://pugholder.com/) * [Dummy Images](http://www.dummyimages.com/) Leave a comment on any other image placeholder sites you use, and I will add them to this list.

    Loading...