Skip to content

Instantly share code, notes, and snippets.

View roalcantara's full-sized avatar
🤖
Don't Panic!

Rogério Rodrigues de Alcântara roalcantara

🤖
Don't Panic!
View GitHub Profile
@roalcantara
roalcantara / query.sql
Created January 19, 2017 14:30
Selecting total of logins, total of logins by week, total of logins by month from users grouped by type
SELECT u.type,
sum(u.total_of_logins) as total,
sum(week1.total_of_logins) as week_1,
sum(january.total_of_logins) as january
FROM users u
LEFT JOIN users week1
ON week1.id = u.id
AND (week1.created_at >= '2017-01-01' AND week1.created_at <= '2017-01-07')
@roalcantara
roalcantara / selector.js
Created January 12, 2017 11:01
JQuery > Selector: Selects the N sibling element starting from the element containing the text `Y`
//selects the 3rd .screen_color_PHN from the .screen_color_PHN that contains the text `1`
$("pre .screen_color_PHN:contains('1') ~ .screen_color_PHN:nth-of-type(3)")
@roalcantara
roalcantara / 1_user.rb
Last active February 25, 2022 19:08
Rails5 - Rspec, factory_girl, ffaker, enums, shoulda-matchers and i18n example
# /app/models/user.rb
class User < ApplicationRecord
enum kind: [:customer, :admin]
belongs_to :status
delegate :type, to: :status
validates :name, :user_type, presence: true
end
@roalcantara
roalcantara / 1_remove_task.rake
Last active April 29, 2019 08:58
[Rails 5] Overriding `db:schema:load` rake in order to load legacy schema before running the default `db:schema:load` task
#lib/tasks/remove_task.rake
Rake::TaskManager.class_eval do
def remove_task(task_name)
@tasks.delete(task_name.to_s)
end
end
def remove_task(name)
Rake.application.remove_task(name)
@roalcantara
roalcantara / 1_post-receive
Last active December 21, 2016 05:02
Git Deployment (Rails)
# touch /var/repo/app-staging.git/hooks/post-receive
# chmod +x /var/repo/app-staging.git/hooks/post-receive
#!/bin/bash -l
APP_NAME=app-staging
APP_ENV=staging
APP_DB=app-database-name
REPO_DIR="/var/repo/$APP_NAME.git"
@roalcantara
roalcantara / brackets.java
Created November 22, 2016 10:44
Java brackets algorithm
import java.util.Map;
import java.util.HashMap;
class Main {
public static final Map BRACKETS = new HashMap<String, String>() {{
put("[", "]");
put("{", "}");
put("(", ")");
put("<", ">");
}};
@roalcantara
roalcantara / google_spreadsheet_double_quotes_formula.txt
Created November 11, 2016 12:11
Google Spreadsheet Double Quotes Formula
First, why don't you just export your spreadsheet as csv? Google has that feature built-in. It's under the menu File > Download as > CSV
But, answering your question, it's pretty easy to wrap all values in doubles quotes. Let's say the desired values are on Sheet1 columns A to D. On Sheet2, cell A1, just place this formula:
=ArrayFormula(""""&Sheet1!A:D&"""")
The issue with the issue with the double quotes is that they're used as string delimiters, so to have them inside a string you have to type two consecutive. So, one " to open, two to have one "" and one " to close :)
source: http://stackoverflow.com/questions/3315636/how-to-enclose-every-cell-with-double-quotes-in-google-docs-spreadsheet
@roalcantara
roalcantara / bundle_install_thrift.sh
Last active December 29, 2016 02:39
Bundler: installing thrift gem on OSX Sierra
```
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
An error occurred while installing thrift (0.9.2.0), and Bundler cannot continue.
Make sure that `gem install thrift -v '0.9.2.0'` succeeds before bundling.
```
#add to ~/.bundle/config
BUNDLE_BUILD__THRIFT: --with-cppflags="-D_FORTIFY_SOURCE=0 -Wno-shift-negative-value"
@roalcantara
roalcantara / forked_repo_rebase.sh
Last active November 9, 2023 20:41
Git: Rebasing a Forked Repository Branch
# Disclosure:
# Forked Repo: the original repository
# Fork Repo: your repository
# -- clone your fork
$ git clone https://github.com/roalcantara/equalize.git
# -- enters some branch
$ cd equalize
$ git checkout master
@roalcantara
roalcantara / .gitignore
Last active May 19, 2016 01:47
Angular2 + Protractor + CucumberJS
# See http://help.github.com/ignore-files/ for more about ignoring files.
# compiled output
/dist
/tmp
# dependencies
/node_modules
/bower_components