Skip to content

Instantly share code, notes, and snippets.

View omkz's full-sized avatar
🏠
Working from home

Kurnia omkz

🏠
Working from home
View GitHub Profile
@omkz
omkz / gist:8965608
Created February 12, 2014 22:11
create new rails application with spesicfic version
rails _VERSION_ new myapp
ex :
➜ rails rails _3.2.16_ new tirtosocial
create
create README.rdoc
create Rakefile
create config.ru
create .gitignore
create Gemfile
@omkz
omkz / chat.rb
Created March 1, 2014 14:36 — forked from emad-elsaid/chat.rb
require 'sinatra' # gem install sinatra --no-rdoc --no-ri
set :port, 3000
set :environment, :production
html = <<-EOT
<html><head><style>
#text{width:100%; font-size: 15px; padding: 5px; display: block;}
</style></head><body>
<input id="text" placeholder="Write then press Enter."/>
<div id="chat"></div>
@omkz
omkz / staging.txt
Created March 24, 2014 05:11
Creating a staging environment on Heroku
Creating a staging environment on Heroku
If you’re hosting your app on Heroku (possibly even if you aren’t) it is a good idea to create a staging environment also. Heroku has docs on this but the short version for a new app is:
heroku create staging-app-name --stack cedar --remote staging(if the app is already on Heroku, just add the remote: git remote add staging git-url-on-heroku)
git push staging master
heroku rake db:migrate --remote staging
heroku rake db:seed --remote staging
Hopefully you have a staging environment set in config/environments/staging.rb so:
@omkz
omkz / gist:9734295
Created March 24, 2014 04:43
rails 3 - change column data type
_ saya ingin merubah data type pada column start dan column end di tabel segments dari float menjadi integer.
$ rails g migration ChangeStartForSegments
class ChangeStartForSegments < ActiveRecord::Migration
def up
change_column :segments, :start, :integer
change_column :segments, :end, :integer
@omkz
omkz / gist:9727397
Created March 23, 2014 18:31
rails - heroku - multi env
➜ tictools git:(master) ✗ heroku run rake db:migrate --app tictools-staging
/Users/admin/.heroku/client/lib/heroku/helpers.rb:212: warning: Insecure world writable dir /usr/local in PATH, mode 040777
Running `rake db:migrate` attached to terminal... up, run.4368
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/Rakefile:7)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4
@omkz
omkz / gist:9869116
Created March 30, 2014 07:41
deep_cloneable ~ ScenarioDetail
2.0.0-p247 :017 > sd = ScenarioDetail.first
ScenarioDetail Load (0.8ms) SELECT "scenario_details".* FROM "scenario_details" LIMIT 1
=> #<ScenarioDetail id: 2, scenario_id: 1, intersection_id: 2, created_at: "2013-12-15 11:45:06", updated_at: "2013-12-15 11:45:06">
2.0.0-p247 :018 > test = sd.dup :include => [:scenario, :intersection]
Scenario Load (0.8ms) SELECT "scenarios".* FROM "scenarios" WHERE "scenarios"."id" = 1 LIMIT 1
Intersection Load (1.2ms) SELECT "intersections".* FROM "intersections" WHERE "intersections"."id" = 2 LIMIT 1
=> #<ScenarioDetail scenario_id: nil, intersection_id: nil, created_at: nil, updated_at: nil>
2.0.0-p247 :019 > test.save
@omkz
omkz / gist:9929621
Created April 2, 2014 07:44
rails - get secondtolast record
2.0.0p247 :003 > s = Segment.all
2.0.0p247 :006 > s[-2]
=> #<Segment id: 174, name: "top", facility_id: nil, created_at: "2014-04-01 14:59:47", updated_at: "2014-04-01 14:59:47", scenario_id: 26, data: {}, start: 260, end: 261>
2.0.0p247 :007 > Segment.order("created_at DESC").limit(2).last
Segment Load (43.5ms) SELECT "segments".* FROM "segments" ORDER BY created_at DESC LIMIT 2
=> #<Segment id: 174, name: "top", facility_id: nil, created_at: "2014-04-01 14:59:47", updated_at: "2014-04-01 14:59:47", scenario_id: 26, data: {}, start: 260, end: 261>
2.0.0p247 :008 > Segment.order("id DESC").offset(1).first
Segment Load (6.6ms) SELECT "segments".* FROM "segments" ORDER BY id DESC LIMIT 1 OFFSET 1
=> #<Segment id: 174, name: "top", facility_id: nil, created_at: "2014-04-01 14:59:47", updated_at: "2014-04-01 14:59:47", scenario_id: 26, data: {}, start: 260, end: 261>
2.0.0p247 :009 > Segment.order("id DESC").offset(1).first.id
require 'tumblr_client'
require 'mechanize'
require 'date'
require 'yaml'
require 'uri'
Tumblr.configure do |config|
config.consumer_key = "consumer_key"
config.consumer_secret = "consumer_secret"
config.oauth_token = "oath_token"
<% [:notice, :error, :alert].each do |level| %>
<% unless flash[level].blank? %>
<div class="alert-message <%= flash_class(level) %>">
<a class="close" href="#">×</a>
<%= content_tag :p, flash[level] %>
</div>
<% end %>
<% end %>
@omkz
omkz / api.js
Created April 29, 2014 22:45 — forked from fwielstra/api.js
/* The API controller
Exports 3 methods:
* post - Creates a new thread
* list - Returns a list of threads
* show - Displays a thread and its posts
*/
var Thread = require('../models/thread.js');
var Post = require('../models/post.js');