Skip to content

Instantly share code, notes, and snippets.

@oojikoo-gist
oojikoo-gist / rails_carrierwave_upload.rb
Created October 22, 2015 15:02
rails: carrierwave_upload
# POST /pictures
# POST /pictures.json
def create
#check if file is within picture_path
if params[:picture][:picture_path]["file"]
picture_path_params = params[:picture][:picture_path]
#create a new tempfile named fileupload
tempfile = Tempfile.new("fileupload")
tempfile.binmode
@oojikoo-gist
oojikoo-gist / seed_per_env.rb
Created October 18, 2015 06:03
rails: seed per environment
['all', Rails.env].each do |seed|
seed_file = "#{Rails.root}/db/seeds/#{seed}.rb"
if File.exists?(seed_file)
puts "*** Loading #{seed} seed data"
require seed_file
end
end
@oojikoo-gist
oojikoo-gist / sidekiq.rb
Created October 17, 2015 07:56
rails: reliable sidekiq configuration
# /config/initializers/sidekiq.rb
current_web_concurrency = Proc.new do
web_concurrency = ENV['WEB_CONCURRENCY']
web_concurrency ||= Puma.respond_to?
(:cli_config) && Puma.cli_config.options.fetch(:max_threads)
web_concurrency || 16
end
local_redis_url = Proc.new do
@oojikoo-gist
oojikoo-gist / heroku_custom_domain.md
Created October 15, 2015 09:22
heroku: custom_domain
@oojikoo-gist
oojikoo-gist / random_location_circle.rb
Created October 14, 2015 19:26
ruby: random_location_circle
def random_location_from(center_lat, center_lng, distance)
radius = distance
radiusInDegrees=radius/111000.to_f
r = radiusInDegrees
origin_x = center_lat
origin_y = center_lng
u = rand(0.00..1.00)
v = rand(0.00..1.00)
@oojikoo-gist
oojikoo-gist / rails_sidekiq_with_redis_.rb
Created October 3, 2015 06:19
rails: sidekiq with redis
# /config/initializers/sidekiq.rb
current_web_concurrency = Proc.new do
web_concurrency = ENV['WEB_CONCURRENCY']
web_concurrency ||= Puma.respond_to?
(:cli_config) && Puma.cli_config.options.fetch(:max_threads)
web_concurrency || 16
end
local_redis_url = Proc.new do
@oojikoo-gist
oojikoo-gist / rails_db.yml.sqlite3
Created September 14, 2015 15:57
rails: db sqlite
# SQLite version 3.x
# gem install sqlite3
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
@oojikoo-gist
oojikoo-gist / rails_db_pg
Created September 14, 2015 15:57
rails: db postgresql
# PostgreSQL. Versions 7.4 and 8.x are supported.
#
# Install the pg driver:
# gem install pg
# On Mac OS X with macports:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
@oojikoo-gist
oojikoo-gist / database.yml.mysql2
Created September 14, 2015 14:36
rails: db mysql2
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql2
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
@oojikoo-gist
oojikoo-gist / database.yml.mysql2
Created September 14, 2015 14:35
rails: database.yml msql2
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql2
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8