Skip to content

Instantly share code, notes, and snippets.

View pablomarti's full-sized avatar
🧙‍♂️
💻

Pablo Martí pablomarti

🧙‍♂️
💻
View GitHub Profile
@pablomarti
pablomarti / webpacker_rails.md
Created August 26, 2020 15:42 — forked from maxivak/webpacker_rails.md
Webpack, Yarn, Npm in Rails
@pablomarti
pablomarti / webpacker_rails.md
Created August 26, 2020 15:42 — forked from maxivak/webpacker_rails.md
Webpack, Yarn, Npm in Rails
@pablomarti
pablomarti / rails_new_help_output.md
Created August 1, 2020 20:41 — forked from eliotsykes/rails_new_help_output.md
"rails new" options explained

Run rails new --help to view all of the options you can pass to rails new:

$ bin/rails new --help
Usage:
  rails new APP_PATH [options]

Options:
  -r, [--ruby=PATH]                                      # Path to the Ruby binary of your choice
                                                         # Default: /Users/eliot/.rbenv/versions/2.2.0/bin/ruby
@pablomarti
pablomarti / Dockerfile
Created April 8, 2020 07:04 — forked from oinak/Dockerfile
Example docker config for rails develompent
FROM ruby:2.4
## In case of postgresql for heroku:
# RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main" >> /etc/apt/sources.list.d/postgeresql.list \
# && wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
# && apt-get update \
# && apt-get update \
# && apt-get install -y --no-install-recommends \
# postgresql-client-9.6 pv ack-grep ccze unp htop vim \
# && rm -rf /var/lib/apt/lists/* \
@pablomarti
pablomarti / support.rb
Created February 20, 2019 05:29
Load supporting files into a Rails model
module Support
extend ActiveSupport::Concern
included do
support_path = "app/support/#{name.underscore}/"
actions_path = File.join('.', "#{support_path}actions/*.rb")
queries_path = File.join('.', "#{support_path}queries/*.rb")
events_path = File.join('.', "#{support_path}events/*.rb")
Dir[actions_path, queries_path, events_path].each do |f|
@pablomarti
pablomarti / model.rb
Created February 13, 2019 02:09
Modifying Rails validator on runtime
unique_email_validator = validators_on(:email).find { |v|
v.is_a?(ActiveRecord::Validations::UniquenessValidator)
}
def unique_email_validator.validate(*users)
return false if users.map(&:chatbox).all?
return false unless app_users?(users.collect(&:email))
super
@pablomarti
pablomarti / gist:21fc70dd09775ff225d46e3a9fc6dc4e
Created October 16, 2018 18:06
Force bundle to store in local using flags for OSX
ARCHFLAGS="-arch x86_64" bundle install --path vendor/bundle

If you're writing web applications with Ruby there comes a time when you might need something a lot simpler, or even faster, than Ruby on Rails or the Sinatra micro-framework. Enter Rack.

Rack describes itself as follows:

Rack provides a minimal interface between webservers supporting Ruby and Ruby frameworks.

Before Rack came along Ruby web frameworks all implemented their own interfaces, which made it incredibly difficult to write web servers for them, or to share code between two different frameworks. Now almost all Ruby web frameworks implement Rack, including Rails and Sinatra, meaning that these applications can now behave in a similar fashion to one another.

At it's core Rack provides a great set of tools to allow you to build the most simple web application or interface you can. Rack applications can be written in a single line of code. But we're getting ahead of ourselves a bit.

@pablomarti
pablomarti / rails http status codes
Created May 21, 2018 14:26 — forked from mlanett/rails http status codes
HTTP status code symbols for Rails
HTTP status code symbols for Rails
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings.
Status Code Symbol
1xx Informational
100 :continue
101 :switching_protocols
102 :processing
@pablomarti
pablomarti / gist:80e5dee84a1e4eb229c126297039907f
Created March 28, 2018 15:28
Postgres - Kill connections
SELECT pg_terminate_backend(pid) FROM pg_stat_activity
WHERE pid <> pg_backend_pid() AND datname = current_database();