Skip to content

Instantly share code, notes, and snippets.

View Joseworks's full-sized avatar

Jose C Fernandez Joseworks

View GitHub Profile
@Joseworks
Joseworks / .gitconfig
Created January 25, 2017 15:54 — forked from robmiller/.gitconfig
Some useful Git aliases that I use every day
#
# Working with branches
#
# Get the current branch name (not so useful in itself, but used in
# other aliases)
branch-name = "!git rev-parse --abbrev-ref HEAD"
# Push the current branch to the remote "origin", and set it to track
# the upstream branch
publish = "!git push -u origin $(git branch-name)"
@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 / contact_batch_email.html.erb
Created April 10, 2015 03:19
Send batch emails on ActiveAdmin Rails 4.2.0
<!-- Contact batch email -->
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<div>Name: <%= @name %></div>
<br>
<div>Subject: <%= @subject %></div>
@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: