Skip to content

Instantly share code, notes, and snippets.

View diegolinhares's full-sized avatar
🎯
Focusing

Diego Linhares diegolinhares

🎯
Focusing
View GitHub Profile
@tandibar
tandibar / copy_commit_hash_to_clipboard.sh
Created November 22, 2011 13:34
Copy latest commit hash to clipboard
git log -1 | grep "commit .*" | ruby -e "print ARGF.read.split(' ')[1]" | pbcopy
@ProfAvery
ProfAvery / sum.rb
Created February 9, 2012 05:39
15 ways to sum an array in Ruby
#!/usr/bin/env ruby
require 'test/unit'
class TestSums < Test::Unit::TestCase
def setup
@a = [2, 5, 18, 27]
@sum = 0
end
@owenkellogg
owenkellogg / Gemfile
Created June 25, 2012 17:49
MiniTest Helper for Rails
group :test, :development do
gem 'minitest-rails',
:git => "[email protected]/rawongithub/minitest-rails.git",
:branch => "gemspec"
end
group :test do
gem 'minitest-rails-shoulda',
:git => "[email protected]/rawongithub/minitest-rails-shoulda.git"
gem 'capybara_minitest_spec'
end
@kerryb
kerryb / blocks.rb
Created December 10, 2013 22:28
Ruby blocks, procs, map and reduce
# A proc is just a block of code that can be called later:
say_hello = -> { 2 + 2 }
say_hello.call # => 4
# Procs can take parameters:
double = ->(x) { x * 2 }
# Goal: Allow addition of instances to a collection in a factory-built object
# when those instances require references to the parent.
# Typically occurs in Rails when one model has_many instances of another
# See more at:
# http://stackoverflow.com/questions/2937326/populating-an-association-with-children-in-factory-girl
# Usage
# Foo has_many :bar
#
@Integralist
Integralist / Ruby Lambdas.md
Last active August 8, 2023 05:10
Ruby lambdas

Lambda: standard

# Creating a lambda
l = lambda { |name| "Hi #{name}!" }

# Executing the lambda
l.call("foo") # => Hi foo!
@pmarreck
pmarreck / complex_password_validation.rb
Created May 2, 2014 16:47
Example of using regex to check a complex password validation requirement ("use at least 1 character from 3 sets of characters out of a total of 4 sets of characters")
PASSWORD_VALIDATOR = /( # Start of group
(?: # Start of nonmatching group, 4 possible solutions
(?=.*[a-z]) # Must contain one lowercase character
(?=.*[A-Z]) # Must contain one uppercase character
(?=.*\W) # Must contain one non-word character or symbol
| # or...
(?=.*\d) # Must contain one digit from 0-9
(?=.*[A-Z]) # Must contain one uppercase character
(?=.*\W) # Must contain one non-word character or symbol
| # or...
@janko
janko / 01-safe-download.rb
Last active February 18, 2025 08:40
A safe way in Ruby to download a file to disk using open-uri (with/without comments)
require "open-uri"
require "net/http"
Error = Class.new(StandardError)
DOWNLOAD_ERRORS = [
SocketError,
OpenURI::HTTPError,
RuntimeError,
URI::InvalidURIError,
@maxivak
maxivak / 00.md
Last active April 8, 2025 18:31
Sending emails with ActionMailer and Sidekiq

Sending emails with ActionMailer and Sidekiq

Send email asynchroniously using Sidekiq.

ActionMailer

Create your mailer us usual:

tmux/tmuxinator cheatsheet

tmux

As configured in my dotfiles, here and here.

Command line

$ tmux                           -> start new
$ tmux new -s myname             -> start new w/session name
$ tmux a  #  (or at, or attach)  -> attach
$ tmux a -t myname               -> attach to named