Skip to content

Instantly share code, notes, and snippets.

View reu's full-sized avatar

Rodrigo Navarro reu

View GitHub Profile
# Ruby way fail
# Implementation of a simple method to convert seconds to time format (03:44:23)
require "benchmark"
seconds = 45020
hours = seconds / 3600
minutes = seconds / 60 % 60
Sass::Plugin.options[:template_location] = "#{Rails.root}/app/styles" => "#{Rails.root}/tmp/stylesheets"
Rails.configuration.middleware.insert_after "Sass::Plugin::Rack", "Rack::Static", :urls => ["/stylesheets"], :root => "#{Rails.root}/tmp"
@reu
reu / rm-codeplane-user.rb
Last active September 14, 2015 13:44
Removes an user from all repositories of a Codeplane account
#!/usr/bin/env ruby
require "rubygems"
require "codeplane"
require "optparse"
Codeplane.configure do |config|
ARGV.options do |opts|
opts.on("-u", "--user=username", String) { |val| config.username = val }
opts.on("-p", "--api-key=key", String) { |val| config.api_key = val }
@reu
reu / README.md
Created September 8, 2015 15:55
Scala underscore in Ruby

Scala's Undersore in Ruby

Yeah, Ruby is awesome:

# Without underscore
[1, 2, 3].map { |i| i + 1 }
[{ name: "Sasha" }, { name: "Tori" }].map { |actress| actress[:name] }

# With underscore
@reu
reu / README.md
Created September 16, 2015 17:27
Ruby Globe

Run with while true; do clear; ruby a.rb | tee b.rb; sleep 1; mv -f b.rb a.rb; done

@reu
reu / admin.rb
Created September 2, 2010 14:00
Rails application templates
gem 'devise', '~> 1.1.2'
gem 'cancan'
generate 'devise:install'
apply 'http://gist.github.com/raw/562316/1c45aa71f17491c36d74123abf7886b9a08daddf/basic_stack.rb'
apply 'http://gist.github.com/raw/562316/ed62987b05de614c9b37062f410a3a48e4e776f2/brazilian_app.rb'
apply 'http://gist.github.com/raw/562316/56326e84aa23d9ac1cc227f8aa8ae178f2d4d6b5/cleanup.rb'
apply 'http://gist.github.com/raw/562316/7406f13bf9d9b9d467f3d00a26b56a960685beeb/rspec.rb'
apply 'http://gist.github.com/raw/562316/ad35700fa4f3cf9163b0149b19beeba0407ea325/cucumber.rb'
apply 'http://gist.github.com/raw/562316/4cc84eb5ea709c2f0ea76783157548a660a374a2/w3.rb'
@reu
reu / response-to-object.js
Created September 23, 2015 14:41
Simple Angular function to convert underline case object keys to camel case
(function(angular) {
function underlineToCamelCase(string) {
return string.replace(/(\_[a-z])/g, function(match) {
return match.toUpperCase().replace("_", "");
});
}
function convertToCamelCaseObject(object) {
if (typeof object != "object") return object;
require "ostruct"
module FormsHelper
def search_form_for(object_name, options={}, &block)
options[:html] = {:method => :get}.update(options[:html] || {})
object = OpenStruct.new(params[object_name])
form_for(object_name, object, options, &block)
end
end
class CQM < ActiveRecord::Base
self.abstract_class = true
establish_connection(
:adapter => "mysql2",
:host => "localhost",
:username => "root",
:password => "root",
:database => "cqm_development"
)