Skip to content

Instantly share code, notes, and snippets.

View grosser's full-sized avatar
🎯
Focusing

Michael Grosser grosser

🎯
Focusing
View GitHub Profile
@grosser
grosser / Gemfile
Created March 15, 2015 18:12
Rubymine ex with bundle
source "https://rubygems.org"
gem "parallel"
@grosser
grosser / Post.md
Last active August 29, 2015 14:20
Updating rails versions while keeping the business running

Updating rails versions on big apps can be dangerous and time consuming. This is the workflow we use to deploy and test our Rails upgrades in isolation, before releasing them to everybody and without blocking other changes.

Gemfile

ln -s Gemfile Gemfile.rails4 and use BUNDLE_GEMFILE=Gemfile.rails4 bundle exec rails c to run rails 4.

if ENV['BUNDLE_GEMFILE'].to_s.include?('rails4')
 gem "rails", "4.0.13"
@grosser
grosser / travis_failures.rb
Last active August 29, 2015 14:21
Analyze travis failures from forking_test_runner across all jobs in the build
#!/usr/bin/env ruby
#
# show travis build failures for given build id/url, branch or current branch
# streams logs and shows errors as they happen
#
def usage
puts <<-TEXT.gsub(/^ /, "")
Setup
-----
ActionController::Routing::Routes.draw do |map|
map.root :controller => 'homepage',:action=>'start'
map.signup '/signup', :controller => "users", :action => "new"
map.login '/login', :controller => "sessions", :action => "new"
map.logout '/logout', :controller => "sessions", :action => "destroy"
map.feedback '/feedback', :controller => "messages", :action => "feedback"
#user special
map.change_password '/change_password/:email_token', :controller => "users", :action => "change_password", :email_token => nil
class TasksController < ApplicationController
make_resourceful do
actions :all
response_for :create_failed do |format|
format.html { redirect_to project_url(@task.project)}
end
end
protected
config.after_initialize do
#CACHE
MEMCACHE_SERVER = case RAILS_ENV
when 'development' then 'localhost:11211'
when 'staging' then '127.0.0.1:11211'
when 'production' then '192.168.2.26:11211'
when 'test' then nil
else raise
end
Controller:
before_filter :can_create, :only=>%w[new create]
before_filter :can_write, :only=>%w[edit update destroy]
before_filter :can_read, :only=>%w[show]
protected
def can_create
can_do(:create)
end

Ever wondered how much who adds/removes, its time to find out :D (those are real stats, i just obfuscated the names )

###Results

Git scores (in LOC):
mr-add              :  +482273       -9466
justu               :  +286250       -159905
grosser             :  +152384       -323344

another : +121257 -82116

#! /bin/sh
# start / stop script for mongodb
### BEGIN INIT INFO
# Provides: mongod
# Required-Start: \$remote_fs \$syslog
# Required-Stop: \$remote_fs \$syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Tag.find_values(:select => :user_id, :limit => 30) --> ["1", "3", "6"]
# Tag.find_values(:select => 'user_id, foobar', :limit => 30, :all=>true) --> [["1","A"], ["3","B"], ["6","C"]]
class ActiveRecord::Base
def self.find_values(options)
sql = self.send(:construct_finder_sql, options.except(:all))
result = connection.select_rows(sql, name)
if options[:all]
result
else
result.map{|v| v[0] }