This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Base64 | |
/^[0-9a-zA-Z+\/]+[=]{0,2}$/.match("SGVsbG8gV29ybGQh") | |
=> #<MatchData "SGVsbG8gV29ybGQh"> | |
# R.F.C. (Méx) | |
/[A-Z]{3,4}[0-9]{6}[0-9A-Z]{3}/.match("ICS0707315S4") | |
=> #<MatchData "ICS0707315S4"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create new remote branch | |
git push origin origin:refs/heads/new_branch_name | |
# Make sure everything is updated | |
git fetch origin | |
# Check your branch has been created | |
git branch -r | |
# Track a remote branch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# = Base Template | |
# Base application template for Innetra | |
# == Requirements | |
# Requires innetra-easy_generators (http://github.com/innetra/easy_generators/tree/master) and | |
# gem to work | |
root_controller_name = 'home' | |
if yes?('Install haml and innetra-easy_generators gems (both required)?') | |
run 'gem sources -a http://gems.github.com' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= form.collection_select :company_id, Company.all + | | |
[OpenStruct.new(:id => 'new', :name => 'New Company')], :id, :name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find text in files | |
find | xargs grep 'text to find' -l | |
# Find and exec command | |
find -name '*.bak' -exec rm {} \; | |
# Find only dirs | |
find -type d | |
# Find only files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Undo commit | |
git reset --soft HEAD^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
before_filter :set_current_account | |
private | |
def set_current_account | |
@current_account = | |
Account.find_by_subdomain(request.subdomains.last) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gsub_file(relative_destination, regexp, *args, &block) | |
path = destination_path(relative_destination) | |
content = File.read(path).gsub(regexp, *args, &block) | |
File.open(path, 'wb') { |file| file.write(content) } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# = Mixin Template | |
# == Usage | |
# ActionController::Base.send :include, MixinModuleName | |
module MixinModuleName | |
def self.included(recipient) | |
recipient.extend(ClassMethods) | |
recipient.class_eval do | |
include InstanceMethods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
puts Benchmark.measure { "a"*1_000_000 } | |
0.060000 0.000000 0.060000 ( 0.067556) | |
=> nil | |
n = 50000 | |
Benchmark.bm do |x| | |
x.report { for i in 1..n; a = "1"; end } | |
x.report { n.times do ; a = "1"; end } |
OlderNewer