Skip to content

Instantly share code, notes, and snippets.

View jerome's full-sized avatar

Jérôme Lipowicz jerome

View GitHub Profile
@jerome
jerome / *rail_static_assets_on_heroku_cedar.md
Created October 6, 2015 00:06 — forked from bensheldon/*rail_static_assets_on_heroku_cedar.md
Serving Rails Static Assets on Heroku using a CDN with gzip and cache control

Optimizing Rails Static Assets on Heroku Cedar

Serving Rails static assets is hard, especially on Heroku Cedar where Heroku forces Rails to serve static assets itself (which isn't particularly performant nor worth your dyno-dollar)---this is different than Heroku Bamboo which used Varnish and is no more. To make the best of the situation, I highly recomend:

  1. Using the Heroku-Deflater gem which will selectively gzips assets (it gzips text-based files; and excludes images or binary files, which can actually be bigger when gzipped)

  2. Configure your production environment to set cache-control headers and get out of denial about how static assets are being served on Heroku Cedar

  3. Use AWS Cloudfront (or a CDN of your choosing) to serve the assets. Cloudfront is great because you can use the same Distribution

# -- coding: utf-8
require "rubygems"
require "grill"
Grill.implant <<-GEM
source :rubygems
gem 'capybara', :require => ["capybara", "capybara/dsl"]
gem "capybara-webkit"
gem "headless"
# -- coding: utf-8
require "rubygems"
require "grill"
Grill.implant <<-GEM
source :rubygems
gem 'capybara', :require => ["capybara", "capybara/dsl"]
gem "capybara-webkit"
gem "headless"
@jerome
jerome / Gemfile
Created December 25, 2013 12:47 — forked from pcreux/Gemfile
group :production do
gem 'unicorn'
# Enable gzip compression on heroku, but don't compress images.
gem 'heroku-deflater'
# Heroku injects it if it's not in there already
gem 'rails_12factor'
end

Ruby, RVM and Mountain Lion

Key problems

Mountain Lion (10.8) has three main difference compared to Lion (10.7):

  • XCode 4.4 does not install Command Line Tools by default
  • X11 isn't available anymore
  • The installed version of OpenSSL has some bugs

How to work around

@jerome
jerome / _menu.html.erb
Created October 20, 2012 22:20 — forked from daz/_menu.html.erb
Bootstrap dropdown menu with Rails and Ancestry
<% if article.is_childless? %>
<li><%= link_to article.title, article_path(article) %></li>
<% else %>
<li class="dropdown">
<%= link_to '#', class: 'dropdown-toggle', data: { toggle: 'dropdown'} do %>
<%= article.title %>
<b class="caret"></b>
<% end %>
<ul class="dropdown-menu">
<%= render partial: 'site/menu', collection: article.children, as: :article %>
@jerome
jerome / gist:3286578
Created August 7, 2012 15:52 — forked from ZenCocoon/gist:3282974
Sample Credit Card Validation with ActiveMerchant
# encoding: utf-8
#
class Account::CreditCardController < Account::BaseController
# GET /account/credit_card
def edit
@account = current_account
@credit_card = ActiveMerchant::Billing::CreditCard.new
end
# PUT /account/credit_card

RailsAdmin and Globalize3

I have a project where I need translated content. Therefore I use globalize3, wich stores its translated attributes in a seperate table that belongs to the original model. And I use RailsAdmin for painless record management.

It took me some time to figure out how to get those working together, but eventually I found a solution that is non invasive and still ok to work with.

The translated model

In my case there is a Snippet class. It holds content for static pages or text passages on the website. There is a good README for globalize3 for installation instructions and documentation.

@jerome
jerome / hack.sh
Created March 31, 2012 21:07 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@jerome
jerome / gist:1781428
Created February 9, 2012 17:30
participants-database diff for twitter bootstrap
diff --git a/wp-content/plugins/participants-database/classes/FormElement.class.php b/wp-content/plugins/participants-database/classes/FormElement.class.php
index 1d0ff6a..d83bf29 100644
--- a/wp-content/plugins/participants-database/classes/FormElement.class.php
+++ b/wp-content/plugins/participants-database/classes/FormElement.class.php
@@ -614,7 +614,7 @@ class FormElement {
*/
private function _submit_button() {
- $this->_addline( $this->_input_tag( 'submit' ) );
+ $this->_addline( '<button type="submit" class="btn btn-primary" id="'.$this->name.'">'.$this->value.'</button>' );