Skip to content

Instantly share code, notes, and snippets.

View Joseworks's full-sized avatar

Jose C Fernandez Joseworks

View GitHub Profile
@Joseworks
Joseworks / web-fonts-asset-pipeline.md
Created February 10, 2017 03:11 — forked from anotheruiguy/web-fonts-asset-pipeline.md
Custom Web Fonts and the Rails Asset Pipeline

Web fonts are pretty much all the rage. Using a CDN for font libraries, like TypeKit or Google Fonts, will be a great solution for many projects. For others, this is not an option. Especially when you are creating a custom icon library for your project.

Rails and the asset pipeline are great tools, but Rails has yet to get caught up in the custom web font craze.

As with all things Rails, there is more then one way to skin this cat. There is the recommended way, and then there are the other ways.

The recommended way

Here I will show how to update your Rails project so that you can use the asset pipeline appropriately and resource your files using the common Rails convention.

@Joseworks
Joseworks / progress_bar.rb
Created February 20, 2017 19:48 — forked from kuntoaji/progress_bar.rb
Simple progress bar script without Gem using Ruby.
#!/usr/bin/env ruby
progress = 'Progress ['
1000.times do |i|
# i is number from 0-999
j = i + 1
# add 1 percent every 10 times
if j % 10 == 0
@Joseworks
Joseworks / progress_bar.rb
Created February 20, 2017 19:48 — forked from kuntoaji/progress_bar.rb
Simple progress bar script without Gem using Ruby.
#!/usr/bin/env ruby
progress = 'Progress ['
1000.times do |i|
# i is number from 0-999
j = i + 1
# add 1 percent every 10 times
if j % 10 == 0
@Joseworks
Joseworks / config.ru
Created April 14, 2017 15:13 — forked from pmkhoa/config.ru
Middleman Authentication via Rack
require 'rubygems'
require 'middleman/rack'
protected_middleman = Rack::Auth::Basic.new(Middleman.server) do |username, password|
[username, password] == ['theuser', 'thepassword']
end
run protected_middleman
@Joseworks
Joseworks / gist:e37b8cef884105da2933c78d1c45fccd
Created April 14, 2017 15:13 — forked from vcabansag/gist:7308a3d79ca57ede4e73
Adding HTTP Authentication to a Middleman app using Heroku environment variables
require "rubygems"
require "rack"
require "middleman/rack"
require "rack/contrib/try_static"
protected_middleman = Rack::Auth::Basic.new(Middleman.server) do |username, password|
[username, password] == [ENV['HTTP_USERNAME'], ENV['HTTP_PASSWORD']]
# Enable proper HEAD responses
use Rack::Head
@Joseworks
Joseworks / routes.md
Created April 17, 2017 22:13 — forked from dideler/routes.md
Rails Routes

A summary of the Rails Guides on Routes, plus other tips.

The Rails router recognizes URLs and dispatches them to a controller's action. It can also generate paths and URLs, avoiding the need to hardcode strings in your views.

Examples

# Redirects /orders/report to orders#report.
get 'orders/report', to: 'orders#report'
@Joseworks
Joseworks / gist:f48ebd5a10bf5eb39386a601cd84fa39
Created May 10, 2017 19:24 — forked from giannisp/gist:b53a76047b07751ed3ade3c1db1d2c51
Upgrade PostgreSQL 9.5.5 to 9.6.1 using Homebrew (macOS)
After automatically updating Postgres to 9.6.1 via Homebrew, the pg_ctl start command didn't work.
The error was something like "database files are incompatible with server".
Database files have to be updated before starting the server, here are the steps that had to be followed:
# need to have both 9.6.1 and latest 9.5.x installed, and keep 9.6.1 as default
brew unlink postgresql
brew install postgresql95
brew unlink postgresql95
brew link postgresql
@Joseworks
Joseworks / casting_types.rb
Created May 11, 2017 18:40 — forked from otobrglez/casting_types.rb
unknown OID 705: failed to recognize type of '<field>'. It will be treated as String.
#!/usr/bin/env ruby
# If you get "unknown OID 705: failed to recognize type of '<field>'. It will be treated as String."
# it probably means that type of column could not be identified when retriving records
# Example
User.where("'something' as something")
# Will results in unknown OID. However doing this:
@Joseworks
Joseworks / pg_stat_statements
Created May 11, 2017 20:45 — forked from troyk/pg_stat_statements
enable postgres pg_stat_statements
1) see re: increasing shmmax http://stackoverflow.com/a/10629164/1283020
2) add to postgresql.conf:
shared_preload_libraries = 'pg_stat_statements' # (change requires restart)
136 pg_stat_statements.max = 1000
137 pg_stat_statements.track = all
3) restart postgres
4) check it out in psql
@Joseworks
Joseworks / render_and_redirect.markdown
Created June 15, 2017 16:25 — forked from jcasimir/render_and_redirect.markdown
Render and Redirect in Rails 3

Render and Redirect

The normal controller/view flow is to display a view template corresponding to the current controller action, but sometimes we want to change that. We use render in a controller when we want to respond within the current request, and redirect_to when we want to spawn a new request.

Render

The render method is very overloaded in Rails. Most developers encounter it within the view template, using render :partial => 'form' or render @post.comments, but here we'll focus on usage within the controller.

:action