Skip to content

Instantly share code, notes, and snippets.

View kidpollo's full-sized avatar
💁‍♂️
Potato farming

Paco Viramontes kidpollo

💁‍♂️
Potato farming
  • San Francisco, CA
View GitHub Profile
Service::Application.routes.draw do
namespace :v1 do
resources :posts, only: [:index, :show, :update]
end
end
BCX::Application.routes.draw do
concern :commentable do
resources :comments
end
resources :messages, :forwards, :uploads, :documents, :todos, concerns: :commentable
end
class PeopleController < ActionController::Base
# This will raise an ActiveModel::ForbiddenAttributes exception because it's using mass assignment
# without an explicit permit step.
def create
Person.create(params[:person])
end
# This will pass with flying colors as long as there's a person key in the parameters, otherwise
# it'll raise a ActionController::MissingParameter exception, which will get caught by
# ActionController::Base and turned into that 400 Bad Request reply.
@kidpollo
kidpollo / greedy.scss
Created December 31, 2012 00:41
Greedy css minimalist css grid system in scss
$columns: 16;
$gutter: 25px;
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
@mixin clearfix {
@kidpollo
kidpollo / Instrument Anything in Rails 3.md
Created September 14, 2012 21:39 — forked from mnutt/Instrument Anything in Rails 3.md
How to use Rails 3.0's new notification system to inject custom log events

Instrument Anything in Rails 3

With Rails 3.0 released a few weeks ago I've migrated a few apps and I'm constantly finding useful new improvements. One such improvement is the ability to log anything in the same way that Rails internally logs ActiveRecord and ActionView. By default Rails 3 logs look slightly spiffier than those produced by Rails 2.3: (notice the second line has been cleaned up)

Started GET "/" for 127.0.0.1 at Mon Sep 06 01:07:11 -0400 2010
  Processing by HomeController#index as HTML
  User Load (0.2ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1
  CACHE (0.0ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1

Rendered layouts/_nav.html.erb (363.4ms)

@kidpollo
kidpollo / application.rb
Created August 23, 2012 21:48 — forked from AMEE/application.rb
Make Rails 3.1 use symbols in sessions so it can share Rails 2 sessions.
#...
module MyApp
class Application < Rails::Application
#...
config.after_initialize do
require 'session_patch'
end
@kidpollo
kidpollo / script.rb
Created August 1, 2012 22:18
Generic pattern for handling account trial states and notifications
tn = TrialNotification.new(@account, Notifier)
tn.assm_current_state
# :trial
tn.send_first_notification!
tn.assm_current_state
# :first_notification_sent
tn.send_second_notification!
tn.assm_current_state
# :second_notification_sent
tn.send_third_notification!
@kidpollo
kidpollo / uri.js
Created April 21, 2012 04:04 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.host; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
@kidpollo
kidpollo / cached_dates.js
Created February 2, 2012 00:28
proper syntax for cached dates
function localizable_time_ago_in_words(from, locale){
"use strict";
return distance_of_time_in_words(new Date(), new Date(from));
}
function distance_of_time_in_words(to, from) {
"use strict";
var seconds_ago = ((to - from) / 1000);
var minutes_ago = Math.floor(seconds_ago / 60);
/*!<sl:translate>*/
@kidpollo
kidpollo / gist:1320385
Created October 27, 2011 18:29
VIM suffs
To change two vertically split windows to horizonally split
^Wt^WK
Horizontally to vertically:
^Wt^WH
where ^W means "hit Ctrl-W". Explanations:
^Wt makes the first (topleft) window current
^WK moves the current window to full-width at the very top