Saturday, September 17, 2011

Monday, September 12, 2011

Clean up CodeIgniter's database (ActiveRecord) memory usage

As what I have found when I was researching there are 2 ways:
  • Prevent ActiveRecord from saving query
by
$this->db->save_queries = false;
credit: how can I free the memory used by $this->db->insert()

  • Free result memory - CodeIgniter will only reclaim memory when http query processing was returned. If you request is long, you have to free by yourself
by
$query = $this->db->query('SELECT title FROM my_table');
$query->free_result();
credit: last section of Generating Query Results

Friday, September 9, 2011

Useful VIM command that I still can't remember



  • “0p - pastes the last explicitly copied text
  • :reg - Show a list of registers
  • J - Merge current line With Next Line
  • =, == - Fix indention
  • u,U(in visual mode) - lower, uppercase
  • q: - list command history
  • q/ - list search history
  • Ctrl ^ - go to previous buffer
  • :w !sudo tee % - save readonly file
  • diw - delete a word
  • di(, da( - delete text inside/include ()
  • di", da" - delete text inside/include ""
For rails.vim
  • gf - open file from cursor
  • :R{view,model,controller,spec} {file}

Thursday, August 18, 2011

Git - Global gitignore

Some types of temporary files are spanding across project, such as .swp (VIM temporary file type).

To put *.swp to every project's repositories makes duplicate job.

One way to solve this issue is to put it to Global gitignore.

From this blog Git global ignores, i will copy to here, also.

- Create .gitignore file at somewhere, mostly at ~/
git config --global core.excludesfile ~/.gitignore


- An pattern of file, you want to do global ignore in to that file.

That's it.

Tuesday, August 16, 2011

[VIM] Mostly use FuzzyFinder and NERDTree shortkeys

Basic VIM
- Open new horizontal split :sp file
- Open new vertical split :vs file
- Switch between split pane: Ctrl-w + { h|j|k|l }
- Rotate pane down/right: Ctrl-w + r
- For more, see Vim documentation: windows

FuzzyFinder
- Open in vertical split: Ctrl-k
- Open in horizontal split: Ctrl-j

NERDTree
- Open in vertical split: s

Friday, August 12, 2011

[Solved] autoscan: not found

If you are in process of compiling something on Ubuntu and you get error similar to these
./bootstrap.sh: 24: autoscan: not found

You have to install autoscan program but you can not find autoscan with
sudo aptitude search autoscan

The package name you have to install is autoconf. I don't know why because I'm not an expert on C/Linux but after below command, the compilation works.
sudo apt-get install autoconf

Monday, August 1, 2011

Create simple Ubuntu(Debian?) start up script

- Create a file at /etc/init.d/<filename>
#!/bin/bash

case "${1:-''}" in
'start')
# put the command to start
;;
'stop')
# stop command here
;;
'restart')
# restart command here
;;
*)
echo "Usage: $SELF start|stop|restart"
exit 1
;;
esac


sudo update-rc.d <filename> defaults


sudo /etc/init.d/<filename> <start|stop|restart>


- To remove
sudo rm /etc/rc*/*<filename>


Credit: Ivan in How do I make sphinx restart when I reboot my Ubuntu server?

Collectd PostgreSQL Plugin

I couldn't find this link when searching with google https://www.collectd.org/documentation/manpages/collectd.conf.html#plugin-postgresq...