render :text => 'test' # set layout layout 'layout' # print odd and even in table tr class=cycle('list_line_odd', 'list_line_even') # ruby inside javascript block [slim template] javascript: var config = { custom: "#{my_value ? 'truthy' : 'falsy'}", current_user: #{raw current_user.to_json} };
Thursday, September 26, 2013
Frequently used commands in Rails vs Slim
Monday, September 23, 2013
Solving “502 Bad Gateway” with nginx & php-fpm
After upgrading php-fpm, my PHP-based sites were returning “502 Bad Gateway” errors. Here’s how I managed to solve it.
Check to make sure that php-fpm is running with
The thing to notice here is that the order in which you install the packages is important. In the past I have found that installing them in the wrong order causes the packages to be configured incorrectly.
Next, get php-fpm to listen on the correct host/port. In /etc/php5/fpm/pool.d/www.conf change the following line from:
To:
Restart php-fpm with
Ref: http://wildlyinaccurate.com/solving-502-bad-gateway-with-nginx-php-fpm
Check to make sure that php-fpm is running with
ps auxww | grep php– if you can’t see any php-fpm processes in the output, then you may need to re-install php-fpm. If php-fpm is running okay, then skip this first step.
sudo apt-get remove php5 php5-cgi php5-fpm sudo apt-get install php5 php5-cgi php5-fpm
The thing to notice here is that the order in which you install the packages is important. In the past I have found that installing them in the wrong order causes the packages to be configured incorrectly.
Next, get php-fpm to listen on the correct host/port. In /etc/php5/fpm/pool.d/www.conf change the following line from:
listen = /var/run/php5-fpm.sock
To:
listen = 127.0.0.1:9000
Restart php-fpm with
sudo /etc/init.d/php5-fpm restartand everything should work normally again.
server { listen 80; server_name your_domain.com; root /your_document_root; index index.php; access_log /your_document_root/logs/access_log; error_log /your_document_root/logs/error_log; location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php last; break; } } location ~ \.php$ { include fastcgi_params; try_files $uri =404; fastcgi_pass 127.0.0.1:9000; # fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_param SCRIPT_FILENAME /your_document_root$fastcgi_script_name; fastcgi_index index.php; } }
Ref: http://wildlyinaccurate.com/solving-502-bad-gateway-with-nginx-php-fpm
Install RabbitVCS Svn, Git Client On Ubuntu 12.10/12.04/11.10/11.04
Overview
There are some cool interfaces for subversion control for windows however when it comes to desktop linux distros, you find very few that can match their windows counterpart like TortoiseSVN. RabbitVCS is one such client that comes with all the bells and whistles. Here is a post about installing it.
There are some cool interfaces for subversion control for windows however when it comes to desktop linux distros, you find very few that can match their windows counterpart like TortoiseSVN. RabbitVCS is one such client that comes with all the bells and whistles. Here is a post about installing it.
First install some prerequisites.
Download the tarball, untar it and run the setup script
Still inside the rabbitvcs-0.15.2 directory, cd to the nautilus-3.0 under the clients directory and copy the RabbitVCS.py to the extensions dir
$ cd clients/nautilus-3.0
Logout and log back in. Now create a folder and right click on it to see the RabbitVCS menu, perform a checkout.
Refs: http://linuxdrops.com/install-rabbitvcs-svn-git-client-on-ubuntu-12-1012-0411-1011-04/
Fix Error: Bomb icon
The bomb emblem means that there is some sort of error in the status checker. It is possible that error messages will show up in ~/.config/rabbitvcs/RabbitVCS.log but I'm not sure it will for your problem. I'm not sure what would cause your status checker to be getting errors but it could be that your svn or git dependencies are not correctly installed, or installed in a way that doesn't work with RabbitVCS. Are the bomb emblems showing up in git repositories or svn repositories or both?
One thing that might help is restarting the status checker. You can do this by killing the checkerservice.py process. Run "ps aux | grep rabbitvcs" and kill the process that says checkerservice.py. Once you do that, restart nautilus and see what happens.
$ sudo apt-get update $ sudo apt-get install python-nautilus python-configobj python-gtk2 python-glade2 python-svn python-dbus python-dulwich subversion meld gconf-editor
Download the tarball, untar it and run the setup script
$ wget http://rabbitvcs.googlecode.com/files/rabbitvcs-0.15.2.tar.bz2 $ tar jxvf rabbitvcs-0.15.2.tar.bz2 $ cd rabbitvcs-0.15.2/ $ sudo python setup.py install --install-layout=deb
Still inside the rabbitvcs-0.15.2 directory, cd to the nautilus-3.0 under the clients directory and copy the RabbitVCS.py to the extensions dir
$ cd clients/nautilus-3.0
$ sudo cp RabbitVCS.py /usr/share/nautilus-python/extensions/
Refs: http://linuxdrops.com/install-rabbitvcs-svn-git-client-on-ubuntu-12-1012-0411-1011-04/
Fix Error: Bomb icon
The bomb emblem means that there is some sort of error in the status checker. It is possible that error messages will show up in ~/.config/rabbitvcs/RabbitVCS.log but I'm not sure it will for your problem. I'm not sure what would cause your status checker to be getting errors but it could be that your svn or git dependencies are not correctly installed, or installed in a way that doesn't work with RabbitVCS. Are the bomb emblems showing up in git repositories or svn repositories or both?
One thing that might help is restarting the status checker. You can do this by killing the checkerservice.py process. Run "ps aux | grep rabbitvcs" and kill the process that says checkerservice.py. Once you do that, restart nautilus and see what happens.
Friday, September 20, 2013
Ruby on Rails + Slim & Nginx + Unicorn
The first, you must install Ruby and Rails for your computer.
Deploy website on Nginx & Unicorn
Install Nginx
Install Unicorn
After finish all above steps, you just start Nginx and Unicorn
Start Nginx
Setup Slim template
How to start?
Install Slim as a gem:
Include Slim in your Gemfile with gem 'slim' or require it with require 'slim'. That's it! Now, just use the .slim extension and you're good to go.
Deploy website on Nginx & Unicorn
Install Nginx
$ sudo apt-get install nginxSetup virtual host for Nginx. Open file /etc/nginx/sites-available/your_domain.name and add below lines:
server { listen 80; server_name your_domain.name; root /document_root; index index.php; #access_log /var/nginx/access.log }
Install Unicorn
$ gem install unicornSetup Unicorn to process request for Ruby Application on Nginx. Continue add more below lines into setup files of nginx
upstream unicorn { server unix:/tmp/unicorn.hello.sock fail_timeout=0; } server { listen 80 default deferred; server_name hello.jp; root /home/taind/svn/demo/hello; try_files $uri/index.html $uri @unicorn; location @unicorn { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://unicorn; } error_page 500 502 503 504 /500.html; client_max_body_size 4G; keepalive_timeout 10; }Add a boot loader file file Unicorn in document_root/config/unicorn.rb
root = "/home/taind/svn/demo/hello" working_directory root pid "#{root}/tmp/pids/unicorn.pid" stderr_path "#{root}/log/unicorn.log" stdout_path "#{root}/log/unicorn.log" listen "/tmp/unicorn.hello.sock" worker_processes 2 timeout 30 # Force the bundler gemfile environment variable to # reference the capistrano "current" symlink before_exec do |_| ENV["BUNDLE_GEMFILE"] = File.join(root, 'Gemfile') end
After finish all above steps, you just start Nginx and Unicorn
Start Nginx
$ service nginx startStart Unicorn
unicorn_rails -c document_root/config/unicorn.rb -D
Setup Slim template
How to start?
Install Slim as a gem:
$ gem install slim
Include Slim in your Gemfile with gem 'slim' or require it with require 'slim'. That's it! Now, just use the .slim extension and you're good to go.
Thursday, September 19, 2013
How to install Sublime Text 2 on Ubuntu 12.04 (Unity)
Step 1
Download the tarfile that suits you best and extract it. Here’s the command to extract tar.bz2 files:
1.
tar
xf Sublime\ Text\ 2.0.1\ x64.
tar
.bz2
You’ll notice that I got the 64-bit version. The reason is that it’s lightning fast. So, go for that if you can!
1.
tar
xf Sublime\ Text\ 2.0.1\ x64.
tar
.bz2
Step 2
You’ll get a “Sublime Text 2″ folder after extraction. This folder contains all the files that Sublime Text will need. So we have to move that folder somewhere more appropriate. Like the “/opt/” folder :
1.
sudo
mv
Sublime\ Text\ 2 /opt/
1.
sudo
mv
Sublime\ Text\ 2 /opt/
Step 3
At some point you’d want to be able to call Sublime Text from the Terminal by just typing “sublime”. To do that, we’ll just create a symbolic link in “/usr/bin” like thus:
1.
sudo
ln
-s /opt/Sublime\ Text\ 2/sublime_text /usr/bin/sublime
1.
sudo
ln
-s /opt/Sublime\ Text\ 2/sublime_text /usr/bin/sublime
Step 4
Now that our files are at the right place, we need to create a launcher in Unity. To do this, we’re going to create a .desktop file in “/usr/share/applications”:
1.
sudo
sublime /usr/share/applications/sublime.desktop
And paste the following content:
[Desktop Entry]
Version=1.0
Name=Sublime Text 2
# Only KDE 4 seems to use GenericName, so we reuse the KDE strings.
# From Ubuntu's language-pack-kde-XX-base packages, version 9.04-20090413.
GenericName=Text Editor
Exec=sublime
Terminal=false
Icon=/opt/Sublime Text 2/Icon/48x48/sublime_text.png
Type=Application
Categories=TextEditor;IDE;Development
X-Ayatana-Desktop-Shortcuts=NewWindow
[NewWindow Shortcut Group]
Name=New Window
Exec=sublime -n
TargetEnvironment=Unity
As you can see, these lines are quite straightforward. Go ahead and experiment a bit with them.
1.
sudo
sublime /usr/share/applications/sublime.desktop
And paste the following content:
[Desktop Entry] Version=1.0 Name=Sublime Text 2 # Only KDE 4 seems to use GenericName, so we reuse the KDE strings. # From Ubuntu's language-pack-kde-XX-base packages, version 9.04-20090413. GenericName=Text Editor Exec=sublime Terminal=false Icon=/opt/Sublime Text 2/Icon/48x48/sublime_text.png Type=Application Categories=TextEditor;IDE;Development X-Ayatana-Desktop-Shortcuts=NewWindow [NewWindow Shortcut Group] Name=New Window Exec=sublime -n TargetEnvironment=Unity
Step 5
Now you would probably want to open all text files with Sublime Text 2. The easiest way to do that is to open up the file associations list:
1.
sudo
sublime /usr/share/applications/defaults.list
And replace all occurrences of gedit.desktop with sublime.desktop.
Tada ! There you go. You now have Sublime Text 2 installed on Unity on Ubuntu 12.04, like a pro.
1.
sudo
sublime /usr/share/applications/defaults.list
Labels:
Sublim Text 2
,
Ubuntu
Subscribe to:
Posts
(
Atom
)