Sublime Text 2: sync project side bar with active file

It is simple like adding tiny plugin:

import sublime
import sublime_plugin

class SideBarListener(sublime_plugin.EventListener):
    
    def on_activated(self, view):
        view.window().run_command('reveal_in_side_bar')

Plugin: https://github.com/sobstel/SyncedSideBar.

Actual author: http://www.sublimetext.com/for….#p19213

This was posted 3 weeks ago. sublime text 2

Internet Explorer under Linux or Mac OS X

  • Download and install VirtualBox 
  • Download Internet Explorer
  • Adjust RAM settings as it’s only 256MB by default (I’ve used 1GB for each on box with 8GB RAM and 768MB for each on box with 4GB RAM).
  • Run virtual machine and log in to Windows as Administrator (password: Password1).
  • Execute slmgr –rearm from terminal (to run terminal just type cmd into start menu input).
  • Add your hosts to C:\Windows\System32\drivers\etc\hosts file, eg. 10.0.2.2 my-super-site.local (10.0.2.2 is your host’s localhost).
  • Install VirtualBox guest additions.
  • Shutdown and make a snapshot, so you can use it as a starting point if the trial period expires (it’s not illegal, even Microsoft themselves tell us to do it this way, which is understandable as it’s all about adjusting our websites to work on their faulty browsers).

This was posted 1 month ago. linux mac os x internet explorer

Javascript lazy loading with dependencies

Here it is, yet another javascript lazy loader. Sadly, none of existing ones has been solving my problem and I was even using great $script.js for some time, but eventually written new one.

Why?

  • extremely lightweight (less than 0.5KB gzipped)
  • lazy (on-demand) loading
  • support for google.load out of the box
  • any code (not only loaders) can be executed 

Link: https://github.com/sobstel/scru.js.

Sample usage:

// Adding to queue:

$scru.queue('google:jsapi', $scru.fn.async_load('http://www.google.com/jsapi'));
$scru.queue('google:visualization', $scru.fn.google_load('visualization', '1', {packages:['corechart']}), ['google:jsapi']);

// Somewhere in some script (called only when needed)

$scru.execute(drawChart, ['google:visualization']);

All jsapi, visualization js are loaded only when “execute” is called.

This was posted 2 months ago. javascript

Call class method via instance in Ruby

This was posted 3 months ago. ruby

CSS Image

Using Data URI scheme you can embed images directly in HTML or CSS. It can be useful for two things:

  1. To save on requests to image files (images are loaded and cached only in one single request together with CSS file).
  2. To embed images in HTML emails and bypass filters that normally would prevent them from displaying.

You can encode string with Base64.encode64 (Ruby) or base64_encode (PHP).

<?php
$image = base64_encode(file_get_contents('image.jpg'));
echo '<img src="data:image/png;base64,'.$image.'/>';
?>

See the output by inspecting source tag for the image.

This was posted 3 months ago. css htmlemail

Codility sample demo test

I have taken Codility sample demo test at last. I was delaying this memorable moment for a few months, probably for fear that it could somehow turn out Im not that good as I think I am, which is surely the case for most developers. So I did the test and I’m going to take more tests there as it’s quite good fun. And here are my solutions for sample demo test below, both in PHP and Ruby.

This was posted 4 months ago. php ruby codility

Devise: find by username OR e-mail

This was posted 4 months ago. ruby devise rails

PHP date conversions between timezones

In PHP 5.x line dates are handled properly (thanks to Derick Rethans). Even in PHP 5.3 we have loads of nice date/time improvements.

One of nice things is posibility to convert dates between timezones easily.

This was posted 5 months ago. php

DISTINCT vs GROUP BY

Although it may seem so, they do NOT do exactly same thing.

While GROUP BY groups results only by those columns that are explicitly listed after the clause, DISTINCT groups results by ALL columns that are present in SELECT statement (and not only by the one it precedes).

So following queries

SELECT DISTINCT article_id FROM article_authors
SELECT article_id FROM article_authors GROUP BY article_id
return same results,

but

SELECT DISTINCT article_id, author_id FROM article_authors
SELECT article_id FROM article_authors GROUP BY article_id
return different results,

though

SELECT DISTINCT article_id, author_id FROM article_authors
SELECT article_id FROM article_authors GROUP BY article_id, author_id
again return same results.

As a sidenote, with GROUP BY you have HAVING clause by your hand as well.

This was posted 5 months ago. mysql sql

Avoid temporary table when using MySQL’s ORDER BY

If there is an ORDER BY clause and a different GROUP BY clause, or if the ORDER BY or GROUP BY contains columns from tables other than the first table in the join queue, a temporary table is created.

If all columns in ORDER BY and GROUP BY clauses come from the same table, that table is preferred first when joining.

More tips like this in manual’s WHERE Clause Optimization.

This was posted 6 months ago. mysql