Skip to content

Instantly share code, notes, and snippets.

View gist:95b537af06ed39ba9158c0c7f96822ab
### Keybase proof
I hereby claim:
* I am nunosilva800 on github.
* I am nunosilva800 (https://keybase.io/nunosilva800) on keybase.
* I have a public key ASCDtm17fxY-jO_t_Z1415ELEZZVwZKWx0y0WM7NiNcEnQo
To claim this, I am signing this object:
@nunosilva800
nunosilva800 / interleave.rb
Last active Sep 6, 2019
Interleave arrays in ruby
View interleave.rb
# Given a set of arrays with potentially infinite lengths
# 1. interleave the elements from input collections into a
# final 1-dimensional array
# 2. ensure the interleaving follows a frequency, as example:
# - 1 element from collection A (frequency: 1)
# - 2 element from collection B (frequency: 2)
# - 3 element from collection C (frequency: 3)
# - 4 element from collection D (frequency: 4)
# helper to generate infinite enumerators
@nunosilva800
nunosilva800 / service_objects.md
Created Mar 5, 2019
service objects in rails
View service_objects.md

Service Objects

Service Objects are classes or modules that have one public method, often named #call, and are designed to perform a single task or service.

Service objects are single business actions.

Example:

As a class

@nunosilva800
nunosilva800 / interfaces.rb
Created May 22, 2018
ruby interfaces example
View interfaces.rb
module APIProfile
def profile
raise NotImplementedError.new("You must implement '#{__method__}'.")
end
end
module APIAddress
def address
raise NotImplementedError.new("You must implement '#{__method__}'.")
end
@nunosilva800
nunosilva800 / equal.rb
Created Sep 30, 2016
Ruby equalities
View equal.rb
irb> 1 == 1.0
=> true # generic equality
irb> 1 === 1.0
=> true # case equality
irb> 1.eql? 1.0
=> false # equality by value
irb> 1.equal? 1.0
@nunosilva800
nunosilva800 / README.md
Last active Sep 28, 2017
A Widget on Rails
View README.md

This is an example of how to implement a "widget" with Ruby on Rails.

The widget is added to a webpage with the example on test_widget.html.erb :

<div id="my-widget"></div>
<script src="https://my-domain.com/widget.js" type="text/javascript"></script>

This will request the JS code from the server, ensuring you can change it without having to update the webpage were the widget is.

@nunosilva800
nunosilva800 / rubycritic_rating_and_score.md
Last active Jan 22, 2016
RubyCritic's Rating and Score
View rubycritic_rating_and_score.md

Rating and Score

When RubyCritic runs, each analysed class or module gets assigned a rating - a letter from A to F, A being the best. This serves as a baseline to tell you how smelly the code is. Generally A's & B's are good enough, C's serve as a warning and D's & F's are the ones you should be fixing.

Similarly, a global score that ranges from 0 to 100 is calculated, where higher values are better - less code smells detected. This provides a quick insight about the overall code quality.

RubyCritic's rating system was inspired by Code Climate's, you can [read more about how that works here][1].

View ec2_rails_nginx_puma.sh
echo "* Updating system"
sudo apt-get update
sudo apt-get -y upgrade
echo "* Installing packages"
sudo apt-get -y install build-essential libxml2-dev libxslt1-dev git-core nginx redis-server postgresql-client libpq5 libpq-dev curl nodejs htop
sudo locale-gen pt_PT.UTF-8
sudo dpkg-reconfigure locales
echo "* Installing rvm"
View git_delete_merged.sh
# To delete all branches that are already merged into the currently checked out branch:
git branch --merged | grep -v "\*" | xargs -n 1 git branch -d
@nunosilva800
nunosilva800 / fixtures.rake
Created Dec 5, 2014
Comfy Sofa export and import fixtures to S3
View fixtures.rake
namespace :fixtures do
namespace :s3 do
require 'fileutils'
def cms_export from, to
# create the fixtures files from DB
ComfortableMexicanSofa::Fixture::Exporter.new(from, to).export!
# get the bucket
bucket = AWS::S3.new.buckets[ENV['S3_BUCKET_FIXTURES']]
You can’t perform that action at this time.