Skip to content

Instantly share code, notes, and snippets.

View orafaelfragoso's full-sized avatar
:octocat:
Working from home

Rafael Fragoso orafaelfragoso

:octocat:
Working from home
View GitHub Profile
@orafaelfragoso
orafaelfragoso / ArrayHelper.rb
Created January 10, 2017 03:09
Flatten an Array without using Array.flatten()
module ArrayHelper
def flatten(arr)
arr.each_with_object([]) do |el, flat|
flat.push *(el.is_a?(Array) ? self.flatten(el) : el)
end
end
" Creating a module function to the flatten method
So it can be called without being instantiated."
@orafaelfragoso
orafaelfragoso / apple-event.sh
Created October 27, 2016 16:51
Watch the October 2016 Apple Event on Ubuntu
vlc --ffmpeg-threads=1 'http://p.events-delivery.apple.com.edgesuite.net/16oibfvohbfvoihbdfvoihbefv10/m3u8/hls_mvp.m3u8'
@orafaelfragoso
orafaelfragoso / gnome-shell-xoria256-colors.sh
Created September 22, 2016 20:30
Gnome Shell Xoria256 Colors
#!/bin/sh
#
# Shell script that configures gnome-terminal to use xoria256 theme
# colors. Written for Debian Wheezy.
#
# AUTHOR: Igor Kalnitsky <[email protected]>
# LICENSE: GNU GPL v3
PALETTE="#121212121212:#D7D787878787:#AFAFD7D78787:#F7F7F7F7AFAF:#8787AFAFD7D7:#D7D7AFAFD7D7:#AFAFD7D7D7D7:#E6E6E6E6E6E6:#121212121212:#D7D787878787:#AFAFD7D78787:#F7F7F7F7AFAF:#8787AFAFD7D7:#D7D7AFAFD7D7:#AFAFD7D7D7D7:#E6E6E6E6E6E6"
BG_COLOR="#1C1C1C1C1C1C"
@orafaelfragoso
orafaelfragoso / compareArrays.js
Last active October 15, 2015 22:35
A function to compare two Arrays
let compareArrays = (arr1, arr2) => {
if (!arr1 || !arr2)
return false;
if (arr1.length !== arr2.length)
return false;
for(let i=0; i<arr1.length; i++) {
if (arr1[i] instanceof Array && arr2[i] instanceof Array) {
if (compareArrays(arr1[i], arr2[i]))
@orafaelfragoso
orafaelfragoso / NoScopeSoup.js
Last active February 10, 2018 18:44
An Angular 1.X controller example using objects and prototype to prevent $scope soup
'use strict';
var NoScopeSoup = function($scope) {
var _this = this;
_this.myDataString = 'My Data';
};
NoScopeSoup.prototype.getMyData = function() {
return this.myDataString;
@orafaelfragoso
orafaelfragoso / _flash_messages.html.erb
Created August 9, 2014 00:25
Alert message helpers for Rails
<% flash.each do |type, message| %>
<div class="alert <%= alert_class_for(type) %> fade in">
<button class="close" data-dismiss="alert">×</button>
<%= message %>
</div>
<% end %>
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@orafaelfragoso
orafaelfragoso / home_controller_spec.rb
Created August 8, 2014 19:06
Testing a root route with Rspec
require 'rails_helper'
RSpec.describe HomeController, :type => :controller do
describe "GET index" do
it "renders the :index template" do
expect(get: root_url(subdomain: nil)).to route_to(
controller: "home",
action: "index")
@orafaelfragoso
orafaelfragoso / unicorn
Created August 5, 2014 16:37
Unicorn upstart
#!/bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Manage unicorn server
# Description: Start, stop, restart unicorn server for a specific application.
### END INIT INFO
@orafaelfragoso
orafaelfragoso / schema.rb
Created August 1, 2014 03:48
Schema for Omniauth and Devise
create_table "identities", force: true do |t|
t.integer "member_id"
t.string "uid"
t.string "provider"
t.string "oauth_token"
t.string "oauth_secret"
t.datetime "oauth_expires_at"
end
add_index "identities", ["member_id"], name: "index_identities_on_member_id", using: :btree