Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Jumat, 28 Juni 2013
Developing Rails in Windows using Linux Server
Developing rails/ruby app in windows is painful as many gems aren't compatible or optimized for windows. But windows is OS that I'm most comfortable with.. Linux (ubuntu) lack some tools that I need and I simply hate OSX (stupid keyboard layout and hardware restriction), so I prefer dealing with gem problems rather than changing OS..
But then it occurred to me, why not just use virtual machine with linux for server? And turns out it's pretty neat.. And I think some people are too use windows as main OS so I posted here the step for setting up linux vm for rails..
Sabtu, 24 November 2012
Sublime Text 2: jump to definition
Since I moved from netbeans (which no longer officially support rails) to sublime text 2, the only thing that I missed is jump to definition function, often when I need to know how certain method from a gem works I'm forced to search it manually inside that gem folder while on netbeans I can just use alt+click to instantly navigate there..
After some googling I found SublimeCodeIntel which most of the time isn't working and make sublime heavier instead. But at long last I found about CTags and a Sublime Package for it.
First you need to build the tags file by using Rebuild Tags from command palette, after that using it is pretty much similar to netbeans, but instead of alt+click we use ctrl+shift+click plus ctrl+shift+rightclick for returning to previous position and it's works perfectly... for methods inside the project..
Sublime CTags readme show a script to generate tags for gems which is works perfectly, it will generate tags from all gems specified in Gemfile, but adding the script each time I work on a project is kinda troublesome so I created a simple gem to add several rake tasks for generating tags. The gem basically add 3 rake tasks, one for generating tags for project, one for gems, and the last one for both project and gems.
After some googling I found SublimeCodeIntel which most of the time isn't working and make sublime heavier instead. But at long last I found about CTags and a Sublime Package for it.
First you need to build the tags file by using Rebuild Tags from command palette, after that using it is pretty much similar to netbeans, but instead of alt+click we use ctrl+shift+click plus ctrl+shift+rightclick for returning to previous position and it's works perfectly... for methods inside the project..
Sublime CTags readme show a script to generate tags for gems which is works perfectly, it will generate tags from all gems specified in Gemfile, but adding the script each time I work on a project is kinda troublesome so I created a simple gem to add several rake tasks for generating tags. The gem basically add 3 rake tasks, one for generating tags for project, one for gems, and the last one for both project and gems.
Rabu, 24 Oktober 2012
Rails setup in linode
- Login to linode
- choose linux distribution (ubuntu)
- allocate disk space and swap
- boot
- remote access using ssh
- apt-get update
apt-get upgrade --show-upgraded - set hostname:
echo "ayahirano" > /etc/hostname
hostname -F /etc/hostname - nano /etc/hosts
127.0.0.1 localhost.localdomain localhost
12.34.56.78 ayahirano.invalid hirano
2600:3c01::a123:b456:c789:d012 ayahirano.invalid hirano - set timezone to UTC:
dpkg-reconfigure tzdata - install required libs:
apt-get install build-essential zlib1g-dev libssl-dev libreadline6-dev libxslt1-dev libcurl4-openssl-dev apache2-mpm-prefork apache2-prefork-dev libapr1-dev libaprutil1-dev
git-core
- install require lib for postgresql (optional):
apt-get install postgresql postgresql-contrib libpq-dev - create new user:
adduser example_user
usermod -a -G sudo example_user - logout and relogin user the new user
- disable root login:
sudo nano /etc/ssh/sshd_config
PermitRootLogin no - setup postgresql (optional):
sudo -u postgres createuser --superuser example
sudo -u postgres psql postgres
\password example
\q
sudo nano /etc/postgresql/8.4/main/postgresql.conf:
listen_addresses = 'localhost'
sudo nano /etc/postgresql/8.4/main/pg_hba.conf:
local all all md5
sudo /etc/init.d/postgresql start - install rvm:
\curl -L https://get.rvm.io | bash -s stable
source /home/example_user/.rvm/scripts/rvm - install ruby:
rvm install ruby - disable gem documentation installation:
nano ~/.gemrc
gem: --no-ri --no-rdoc
- install passenger:
gem install passenger
rvmsudo passenger-install-apache2-module - get your app to /var/www/example
- disable default virtual host:
sudo a2dissite default
- create new virtual host config:
sudo nano /etc/apache2/sites-available/example
<VirtualHost *:80>
ServerName ayahirano.invalid
ServerAlias *.ayahirano.invalidRailsEnv production
DocumentRoot /var/www/example/public
<Directory /var/www/example
/public>
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost> - enable it:
sudo a2ensite example -
edit apache configuration file:
sudo nano /etc/apache2/mods-available/passenger.load
LoadModule passenger_module /home/rails/.rvm/gems/ruby-1.9.3-p286/gems/passenger-3.0.17/ext/apache2/mod_passenger.so
sudo nano /etc/apache2/mods-available/passenger.conf
PassengerRoot /home/rails/.rvm/gems/ruby-1.9.3-p286/gems/passenger-3.0.17
PassengerRuby /home/rails/.rvm/wrappers/ruby-1.9.3-p286/ruby - enable passenger module:
sudo a2enmod passenger - restart apache:
sudo service apache2 restart
Extras
Installing nodejs for js runtime (needed by assets precompile):
https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
Creating deploy script
- cd $HOME
- nano deploy.sh
- #!/bin/sh
sudo echo -n "precompile assets? (y or n) : "
read precompile
echo -n "bundle install? (y or n) : "
read bundler
cd /var/www/example
git pull
if [ $bundler = y -o $bundler = Y -o $bundler = yes -o $bundler = Yes -o $bundler = YES ]; then
bundle install --without development test
fi
if [ $precompile = y -o $precompile = Y -o $precompile = yes -o $precompile = Yes -o $precompile = YES ]; then
bundle exec rake assets:precompile RAILS_ENV=production
fi
rake db:migrate RAILS_ENV=production
# any other thing you do when deploying...
sudo service apache2 restart - chmod 700 deploy.sh
- Done.. To run use: ./deploy.sh
Selasa, 18 September 2012
tcs-ruby: faster ruby for windows
As a rails developer using windows as my development machine I often getting annoyed on how much time needed to start things especially tests.
In case you're wondering why did I use windows instead of other OS-es better suited for ruby like MacOSX/linux it's because I'm comfortable with it and if you're disagree then feel free to stop reading at this point :)
Several days ago I found about this fork of ruby by TheCodeShop which will speed up things quiet significantly, I decided to try it and one of my project unit tests which needed around 45 sec to complete reduced to less than 20 sec.
This step assume you're using Win7 with pik to manage multiple ruby installation, if you don't have pik yet get it from https://github.com/vertiginous/pik
In case you're wondering why did I use windows instead of other OS-es better suited for ruby like MacOSX/linux it's because I'm comfortable with it and if you're disagree then feel free to stop reading at this point :)
Several days ago I found about this fork of ruby by TheCodeShop which will speed up things quiet significantly, I decided to try it and one of my project unit tests which needed around 45 sec to complete reduced to less than 20 sec.
Installation
This step assume you're using Win7 with pik to manage multiple ruby installation, if you don't have pik yet get it from https://github.com/vertiginous/pik
- Download one of ruby build from:
https://github.com/thecodeshop/ruby/wiki/Downloads
(I'm using winio one) - Extract it, for example to C:\Ruby-tcs193
- Modify Path to use ruby-tcs: go to Control Panel, System, Advanced System Settings, Environment Variables
- Edit Path in User variables, modify existing Ruby bin path to ruby-tcs bin (C:\Ruby-tcs193)
- Add new variable RUBYOPT with value: "-rfenix/replace"
- Next, add it to pik (you can stop here if you didn't use pik, but I recommend it in case you need to switch to standard ruby)
- open cmd, then enter "pik add [path to ruby-tcs bin]" for example "pik add C:\Ruby-tcs193\bin"
- Lastly install devkit for it, run "ruby c:\devkit\dk.rb init" then "ruby c:\devkit\dk.rb install"
- Done :)
Known problems
Heroku commands
heroku commands will raise error because of non existing fenix/replace, to fix simply remove RUBYOPT temporarily by entering "set RUBYOPT="Standard ruby
same as above because standard ruby didn't use fenix so remove RUBYOPT temporarilyKamis, 09 Agustus 2012
Web page Al Bhed translator javascript (bookmarklet)
well long time no post :D
recently I don't have much to do and rather than dying from boredom I created a simple javascript to translate a web page to Al Bhed language (from Final Fantasy X if you're wondering)
The Base translation mapping come from http://nysa.cx/albhed/ and I just converted it to javascript.
Anyway here are the script:
To translate the page back to original, simply use this script:
That's it :)
Known bugs:
- html encoded character such as &nbsp; didn't translate properly, it's fixable but I'm too lazy to fix it :P
- huge page might causing the browser to freeze, also should be fixable by adding some timeout but again, I'm lazy :D
recently I don't have much to do and rather than dying from boredom I created a simple javascript to translate a web page to Al Bhed language (from Final Fantasy X if you're wondering)
The Base translation mapping come from http://nysa.cx/albhed/ and I just converted it to javascript.
Anyway here are the script:
javascript: (function(){var f=document.createElement('script'); f.src = 'http://al-bhed-page-translator-js.googlecode.com/files/albhed.js'; document.head.appendChild(f);})();just copy and paste it into the browser address bar in the page you want to translate. (keep in mind that newer firefox block this kind of script, and you need to use bookmarklet for that)
To translate the page back to original, simply use this script:
javascript: (function(){alTranslate(true);})();
That's it :)
Known bugs:
- html encoded character such as &nbsp; didn't translate properly, it's fixable but I'm too lazy to fix it :P
- huge page might causing the browser to freeze, also should be fixable by adding some timeout but again, I'm lazy :D
Langganan:
Postingan (Atom)