Skip to content

Instantly share code, notes, and snippets.

View gudata's full-sized avatar
🏢
Working from office

gudata

🏢
Working from office
View GitHub Profile
# unicorn_rails -c /data/github/current/config/unicorn.rb -E production -D
rails_env = ENV['RAILS_ENV'] || 'production'
# 16 workers and 1 master
worker_processes (rails_env == 'production' ? 16 : 4)
# Load rails+github.git into the master before forking workers
# for super-fast worker spawn times
preload_app true
@gudata
gudata / _manufacturer.erb.html
Created December 22, 2011 14:47 — forked from sanaumair/_manufacturer.erb.html
code logic review
<%= simple_form_for @search, :as => :search_manufacturer, :url => search_index_url(:search => @search.to_hash), :html => {:novalidate => true, :method => :get} do |search_form|%>
<% SimpleForm.wrapper_tag = nil %>
<!-- Center everything -->
<div class="center-content" itemscope itemtype ="http://schema.org/Product">
<article>
<!-- 1 column box with tabs -->
<div class="tabs">
<nav>
<%= render_filter search_form, @search.filter("boat_manufacturer") %>
</nav>
def validate params
raise OURERROR if !(self.manufacturer == params[:manufacturer] and self.country_code and params[:country_code] and self.model == params[:model])
end
def validate params
[:manufacturer, :model, :country_code].each do |field|
incoming_param = params[field].blank? ? '' : params[field]
field_value = self.send(field).blank? ? '' : self.send(field)
if field_value != incoming_param
error = Api::Errors::BadRequest.new('Bad Request it should be like manufacturer-country_code-model')
raise error
end
end
end

Sublime Text 2 – Useful Shortcuts (Windows)

General

Ctrl+KB toggle side bar
Ctrl+Shift+P command prompt
Ctrl+` python console
Ctrl+N new file

Editing

class SampleJob
def perform
begin
# do all your work in the begin block.
puts "hello world"
rescue Exception => e
# rescue any errors so that you know something went wrong. Email yourself the error if you need.
error_msg = "#{Time.now} ERROR (SampleJob#perform): #{e.message} - (#{e.class})\n#{(e.backtrace or []).join("\n")}"
puts error_msg
ensure
# An example of elasticsearch & Tire setup for ActiveRecord associations.
#
# A `Book has_many :chapters` scenario, with mapping and JSON serialization
# for indexing associated models.
#
# Demonstrates three important caveats as of now:
#
# 1. You you have to use `touch: true` in the `belongs_to` declaration,
# to automatically notify the parent model about the update.
#
def search
paginate_per = 30
group_id = params[:part_group]
make_id = params[:make]
model_id = params[:model]
vehicle_category_id = params[:category]
vehicle_power = params[:power]
capacity = params[:capacity]
q = params[:q]
connection = Faraday::Connection.new('http://example.com') do |builder|
builder.request :url_encoded # for POST/PUT params
builder.adapter :net_http
end
# same as above, short form:
connection = Faraday.new 'http://example.com'
# GET
connection.get '/posts'
@gudata
gudata / Gemfile
Created July 19, 2013 12:12 — forked from zernel/Gemfile
gem 'devise'
gem 'omniauth'
gem 'omniauth-github'
gem "omniauth-twitter"
gem "omniauth-facebook"
gem "omniauth-google-oauth2"