Skip to content

Instantly share code, notes, and snippets.

View dalpo's full-sized avatar
💭
I'm still learning...

Andrea Dal Ponte dalpo

💭
I'm still learning...
View GitHub Profile

In Rails 3

If you add a dir directly under app/

Do nothing. All files in this dir are eager loaded in production and lazy loaded in development by default.

If you add a dir under app/something/

(e.g. app/models/concerns/, app/models/products/)

//
// RKDNetworking.h
// restkit_demo
//
// Created by Andrea Dal Ponte on 22/10/13.
// Copyright (c) 2013 ACME Inc. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "RKDCompany.h"
@dalpo
dalpo / application_controller.rb
Created October 23, 2013 10:40
Sample Masquerades Controller
class ApplicationController < ActionController::Base
helper_method :masquerading?, :current_unit_measure
protected
def masquerading?
session[:masked_id].present?
end
# http://stackoverflow.com/questions/14972253/simpleform-default-input-class
# https://github.com/plataformatec/simple_form/issues/316
inputs = %w[
CollectionSelectInput
DateTimeInput
FileInput
GroupedCollectionSelectInput
NumericInput
PasswordInput
= simple_form_for @post, html: { class: 'form-horizontal' }, defaults: { wrapper: :horizontal_form } do |f|
= f.error_notification
.form-inputs
= f.input :first_name
= f.input :last_name
= f.input :email
.form-actions
= f.button :submit
@dalpo
dalpo / simple_form_validation.rb
Created January 20, 2014 11:29
SimpleForm validation fix
module SimpleForm
module Inputs
class Base
private
def valid_validator?(validator)
# conditional validators are no surprise to us, so just check the action:
action_validator_match?(validator)
end
@dalpo
dalpo / policy_helper.rb
Created April 2, 2014 09:52
Rails with Pundit policy helper
module PolicyHelper
def can?(action, subject)
policy(subject).try "#{action}?"
end
def policy_helper_arguments(*args, &block)
object = args[0]
if block_given?
module PdfHelper
def wicked_pdf_stylesheet_link_tag(*sources)
sources.collect { |source|
asset = Rails.application.assets.find_asset("#{source}.css")
if asset.nil?
raise "could not find asset for #{source}.css"
else
"<style type='text/css'>#{asset.body}</style>"
end
}.join("\n").gsub(/url\(['"](.+)['"]\)(.+)/,%[url("#{wicked_pdf_image_location("\1")}")\2]).html_safe
@dalpo
dalpo / blueimp-gallery-videojs.css.sass
Last active August 29, 2015 14:03
bluimp-gallery videojs integration

Javascript

  • Indent using 2 spaces
  • Use single quotes, unless you are writing JSON
  • Declare one variable per var statement
  • Variables and properties should use lower camel case capitalization
  • Class names should be capitalized using upper camel case
  • Constants should be declared as regular variables or static class properties, using all uppercase letters
  • Use the triple equality operator