Skip to content

Instantly share code, notes, and snippets.

View giosakti's full-sized avatar
✍️
Writing code

Giovanni Sakti giosakti

✍️
Writing code
View GitHub Profile
@giosakti
giosakti / es.sh
Created June 29, 2012 07:19
Install ElasticSearch on Ubuntu 12.04
cd ~
sudo apt-get update
sudo apt-get install openjdk-7-jre -y
wget https://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.19.7.tar.gz -O elasticsearch.tar.gz
tar -xf elasticsearch.tar.gz
rm elasticsearch.tar.gz
sudo mv elasticsearch-* elasticsearch
sudo mv elasticsearch /usr/local/share
@giosakti
giosakti / culerity.js
Created June 29, 2012 13:33 — forked from jlindsey/culerity.js
[RoR] Using Cucumber/Capybara/Culerity, a step to wait until all AJAX calls are complete.
// this allows culerity to wait until all ajax requests have finished
jQuery(function($) {
var original_ajax = $.ajax;
var count_down = function(callback) {
return function() {
try {
if(callback) {
callback.apply(this, arguments);
};
} catch(e) {
@giosakti
giosakti / gist:3027026
Created July 1, 2012 05:52
[Git] Fetch & merge upstream/downstream repo
git remote add <upstream>/<repo> ssh://git@bitbucket.org/<upstream>/<repo>.git
git fetch <upstream>/<repo>
git checkout master
git merge remotes/<upstream>/<repo>/master
@giosakti
giosakti / gist:3027029
Created July 1, 2012 05:53
[Git] how to undo last commit
git commit ...
git reset --soft HEAD^
edit
git add ...
git commit -c ORIG_HEAD
@giosakti
giosakti / gist:3027041
Created July 1, 2012 05:58
[Server] Example configuration file to deploy a site in puppet (using nginx & unicorn module)
class example_com {
file {
"/var/www/":
ensure => directory,
owner => vagrant,
group => vagrant,
mode => 775;
"/var/www/example.com/":
ensure => directory,
owner => vagrant,
@giosakti
giosakti / commands.md
Created July 1, 2012 06:01
[RoR] Misc. command

RAILS_ENV=production PIDFILE=./tmp/resque.pid BACKGROUND=yes QUEUE="*" rake resque:work --trace another alternative is to use resque_pool: https://github.com/nevans/resque-pool

rvm --rvmrc --create jruby@projecta

bundle install --path .bundle/gems --binstubs .bundle/bin

sudo env ARCHFLAGS="-arch x86_64" gem install mysql2 -- --with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config

rake environment tire:import CLASS=Event FORCE=true

@giosakti
giosakti / gist:3027051
Created July 1, 2012 06:02
[RoR] Steps on using Elastic Search for a RoR project
1. install elastic search http://gist.github.com/3016441
2. include gem 'tire'
3. 'include Tire::Model::Search' dan 'include Tire::Model::Callbacks' di model yang mau dicari
4. jalankan rake db:setup untuk mengindex model yang sudah terlanjur masuk
5. buat search form dengan field query, panggil fungsi search di controller
@giosakti
giosakti / gist:3027055
Created July 1, 2012 06:03
[RoR] Steps on using 'friendly_id' gem
1. include gem friendly_id
2. ketik "extend FriendlyId" di model
3. gunakan slugs dengan membuat kolom & index 'slug' berjenis 'string' di model yang brsgkutan
4. lakukan reindexing (Article.find_each(&:save))
5. gunakan history? friendly_id :name, use: [:slugged, :history] & buat tabel baru (rails g friendly_id) (opsional)
6. lakukan redirect jika terjadi perubahan nama (opsional)
7. reserve keyword penting
8. gunakan scoped (2 record dengan nama sama bisa direfer dari tpt berbeda karena karakter berbeda contoh /new-york/john dan /chicago/john)
9. gunakan globalize
@giosakti
giosakti / gist:3027066
Created July 1, 2012 06:07
[Server] Deployment checklist
Check for the time & timezone on server computer
@giosakti
giosakti / spec_helper.rb
Created July 2, 2012 00:47
[RoR] Run ajax cucumber features remotely
require "selenium-webdriver"
profile = Selenium::WebDriver::Firefox::Profile.new
profile["network.http.use-cache"] = false
Capybara.register_driver :firefox_host do |app|
Capybara::Selenium::Driver.new(app,
:browser => :remote,
:url => 'http://10.0.2.2:4444/wd/hub',
:desired_capabilities => Selenium::WebDriver::Remote::Capabilities.firefox(:firefox_profile => profile)