Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View rondy's full-sized avatar

Rondy Sousa rondy

  • Plataformatec
  • São Paulo, SP
View GitHub Profile
@rondy
rondy / README.txt
Created April 14, 2012 14:39
Rails Assert pipeline changes for controller-specific assets
By default, Rails 3.2 loads everything in app/javascripts and everything in app/stylesheets on
every page, despite controller-specific file naming. If you want to load controller-specific
files only on views from their respective controllers, you need to change the manifests and the
layout. The basic idea is to NOT require the entire trees, but only specific subfolders, in the
manifests, and then load the controller-specific files separately in the layout.
Any file you DO want loaded on every page should be placed in app/assets/javascripts/general or
app/assets/stylesheets/general.
For this to work in production, you also need to ensure that the individual files are precompiled by modifying your production.rb file, listing all of the controller-specific files.
@rondy
rondy / 01_usage.markdown
Created April 21, 2012 20:50
Michealis Dictionary
$ michaelis ruby
Michealis Dictionary
Translate: ruby (ingles-portugues)

ruby
ru.by
 n 1 Min rubi, rubim. 2 cor do rubi. 3 algo semelhante ao rubi em cor como: vinho tinto, carbúnculo, sangue. 4 Typogr tipo de corpo 5 1/2. • vt ruborizar. • adj da cor do rubi, vermelho-vivo.
---
@rondy
rondy / credential.rb
Created April 26, 2012 20:46 — forked from RStankov/credential.rb
Sample code from my Using OO to Manage Control Flow post
class Credential
include ActiveModel::Validations
attr_accessor :screen_name, :oauth_token, :oauth_secret, :token, :description
validates_presence_of :screen_name, :oauth_token, :oauth_secret, :message => 'required'
validate :user_exists, :unless => :errors?
def initialize(attributes = {})
attributes.each { |k, v| set_recognized_attribute(k, v) }
@rondy
rondy / gist:2819263
Created May 28, 2012 13:42 — forked from cassiomarques/gist:2819167
Display your routes right at Rails Console, instead of waiting for rake to load your app
# This is part of my .pryrc.
# I put this at the section where I load Rails stuff, so I can use Pry instead of IRB
# for my Rails Console sessions
# Once this is loaded, just run the display_routes method from the console to see the same output that rake routes displays.
# I think it's better because I always leave a Rails console session running :)
require 'rails/application/route_inspector'
@rondy
rondy / gist:3130990
Created July 17, 2012 18:14
Verify network connection
- (BOOL) isConnectedToNetwork
{
Reachability *hostReachable = [Reachability reachabilityWithHostName:@"www.google.com"];
NetworkStatus internetStatus = [hostReachable currentReachabilityStatus];
return ((internetStatus == ReachableViaWiFi) || (internetStatus == ReachableViaWWAN));
}
- (void) getDataFromLocalJSON
{
NSString *jsonPath = @"response.json";
NSFileHandle *file;
NSData *databuffer;
file = [NSFileHandle fileHandleForReadingAtPath: jsonPath];
if (file) {
databuffer = [file readDataToEndOfFile];
[file closeFile];
}
  1. Add debugger to Gemfile

  2. Run bundle

  3. Require debugger on config/application.rb

  4. Run git stash save 'debugger'

  5. Add the following aliases to .gitconfig:

     debugger = stash apply stash^{/debugger}
     dropdebugger = checkout Gemfile Gemfile.lock config/application.rb
    
@rondy
rondy / vitrine.rb
Last active December 15, 2015 17:29
class ProductsController < ApplicationController
def index
@products = Product.vitrine(34)
respond_with @products
end
end
class Product < ActiveRecord::Base
def self.vitrine(limit)
with_state(:published).limit(limit)
@rondy
rondy / gist:7372736
Last active December 27, 2015 18:49
# This initializer adds a method, show_mongo, when running a rails console. When active, all
# moped commands (moped is mongoid's mongodb driver) will be logged inline in the console output.
# If called again, logging will be restored to normal (written to log files, not shown inline).
# Usage:
# > show_mongo
if defined?(Rails::Console)
def show_mongo
if Moped.logger == Rails.logger
Moped.logger = Logger.new($stdout)
{
"auto_match_enabled": true,
"bold_folder_labels": true,
"caret_style": "phase",
"color_scheme": "Packages/User/Xcode_default.tmTheme",
"draw_white_space": "false",
"ensure_newline_at_eof_on_save": true,
"font_face": "Monaco",
"font_size": 15.0,
"highlight_line": true,