A Dark Room

Example of $this and self:: in PHP

Saw this good example from stackoverflow

class Person {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }

    public function getTitle() {
        return $this->getName()." the person";
    }

    public function sayHello() {
        echo "Hello, I'm ".$this->getTitle()."<br/>";
    }

    public function sayGoodbye() {
        echo "Goodbye from ".self::getTitle()."<br/>";
    }
}

class Geek extends Person {
    public function __construct($name) {
        parent::__construct($name);
    }

    public function getTitle() {
        return $this->getName()." the geek";
    }
}

$geekObj = new Geek("Ludwig");
$geekObj->sayHello();
$geekObj->sayGoodbye();

Output:

Hello, I'm Ludwig the geek
Goodbye from Ludwig the person

$this will refer to current object(extended class), but self:: only refer to current class. If you want to refer to current object, you can use static:: (>= PHP5.3.0)

Hide Any File or Folder with Command

Mac only

hide:

chflags hidden /path/to/file-or-folder

unhide:

chflags nohidden /path/to/file-or-folder

Jekyll and Vagrant

Sometimes I want to run jekyll on office’s computer which is using windows. I dont want to spend too much time to setup ruby or compile setup on windows, or even install linux on office’s computer. Vagrant is a quick virtual machines to do the work!

Follow the instruction on vagrant website, and vagrant init in your project folder. Then open Vagrantfile to configure Vagrant

Vagrant.configure("2") do |config|
    config.vm.box = "precise32"
    config.vm.network :forwarded_port, guest: 4000, host: 4000
    config.vm.provision :shell, :inline => "sudo apt-get update && sudo apt-get -y install build-essential ruby-compass && sudo /opt/vagrant_ruby/bin/gem install jekyll rdiscount --no-ri --no-rdoc"
end

Then you are ready to start VM

$vagrant up
$vagrant ssh
$cd /vagrant
$jekyll server

After vagrant up successflly. You should be able to visit via http://localhost:4000 by your web browser.

500px Workflow for Alfred v2

Please register your own api key on 500px via here, and put Consumer Key after $api="" in workflow.

For example, you want to save this photo with id: 27042559 on 500px to your local. Call Alfred, and type: 500px 27042559

It will download size 5 image into your desktop with name 27042559_5.jpg

Download: 500px.workflow

Monday Calendar

Monday Calendar

Monday Calendar is a day based todo app which is similar with Teuxdeux, but it has better interface(at least for me), works on iPhone/iPad as well with browser, and more functions coming.

Usually, I use Omnifocus as my project GTD app, and it is still the best GTD app for Mac, iPhone, and iPad.

However, sometimes I just need a simple list app especially for my work. I tried Monday Calendar one day, and I feel this is what I am looking for. Simple, clearly, easy, and with elegant interface.

It’s worth to try, and I think you will like it. Go website and request invite now.

Sublime Text 2 nil Theme

A nice Sublime Text 2 Theme And a good font: PragmataPro

Powder manages Pow

A good tools to manage Pow

According to this post, if you dont need Pow and MAMP Pro together. You can use Powder to run powder down to disable pow first, then start MAMP Pro.

Running Pow And MAMP Pro Together

source: Running Pow with Apache

I use both Pow for rails development and MAMP Pro for PHP development. I need them work simultaneously.

Before start, if you have Pow installed, uninstall it with

curl get.pow.cx/uninstall.sh | sh

Then let pow’s firewall run to redirect all traffic from port 88 instead of port 80

echo 'export POW_DST_PORT=88' >> ~/.powconfig

Then you can install Pow as normal

curl get.pow.cx | sh

Now, open MAMP Pro, create a new host. Doesn’t matter what it is named and which directory is selected (though I use ‘rails.dev’ and the folder I keep my Rails apps in).Also, deselect the select box for “local name resolution”, just in case. Then go to the Advanced tab, and fill this in to the textarea labeled “Customized virtual host general settings”:

ServerName pow
ServerAlias *.dev    

ProxyPass / http://localhost:20559/
ProxyPassReverse / http://localhost:20559/
ProxyPreserveHost On

About Rails Depoly

This topic is about some general problems when I depoly rails app.

After I set up server environment, I cloned source code by git. Usually, we need do some steps to make sure it works on production environment.

gem we need install

bundle install

initial mongodb

rake db:seed

compile files we need for production

rake assets:precompile --trace RAILS_ENV=production

install javascript runtime

sudo apt-get install nodejs

or from package src

apt-get install make python g++
mkdir ~/nodejs && cd $_
wget -N http://nodejs.org/dist/node-latest.tar.gz
tar xzvf node-latest.tar.gz && cd \`ls -rd node-v*\`
make install