Skip to content

Instantly share code, notes, and snippets.

View joaopfsilva's full-sized avatar
🏠
Coding from Amsterdam

João Silva joaopfsilva

🏠
Coding from Amsterdam
View GitHub Profile
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: $0 <option>"
exit 1
fi
option=$1
case "$option" in
@joaopfsilva
joaopfsilva / gcloud_ssh.sh
Last active March 28, 2023 16:52
Bash script to enter with SSH on app engine instance and disable instance.
#!/bin/bash
# 1. `./main.sh staging` -> enter staging ssh
# 2. `./main.sh production` -> enter production ssh
# 3. `./main.sh staging disable` -> disable staging debug
# 4. `./main.sh production disable` -> disable staging debug
# get the service name and optional disable argument from command-line arguments
service_name=$1
disable=$2
# require gem wicked-pdf
# create a pdf from a string
pdf = WickedPdf.new.pdf_from_string('<hI>Hi Ruby! I am WickedPdf</h1>')
# save the pdf file
File. open(save_path, 'w') do |file| file << pdf end
# if you want to return a pdf from controller
pdf = WickedPdf.new.pdf_from_string('<h1>Hi Ruby! I am WickedPdf Gem</h1>')
@joaopfsilva
joaopfsilva / README.md
Created February 17, 2021 13:55 — forked from timcheadle/README.md
Make /robots.txt aware of the Rails environment

Make /robots.txt aware of the Rails environment

You probably don't want Google crawling your development staging app. Here's how to fix that.

$ mv public/robots.txt config/robots.production.txt
$ cp config/robots.production.txt config/robots.development.txt

Now edit config/routes.rb to add a route for /robots.txt, and add the controller code.

@joaopfsilva
joaopfsilva / Q1_reverse_string.rb
Created February 12, 2020 18:20
Pexels - challenge
def reverse_string(input)
return '' if input.nil? || input.size == 0
rev_string = []
input.split('').each_with_index{|w,i| rev_string.unshift(w) }
rev_string.join
end
@joaopfsilva
joaopfsilva / toolkit
Last active March 3, 2023 08:08
Issues on Mojave
# Make sure openssl is installed on Mac via Homebrew.
# use ssh-agent to prevent inserting always the passphrase.
https://docs.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
brew install openssl
# MySQL installation
# ISSUE: mysql8 (default) has a different default authentication
@joaopfsilva
joaopfsilva / iban.js
Created September 27, 2019 07:40
IBAN validator
// https://github.com/arhs/iban.js
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['exports'], factory);
} else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') {
// CommonJS
factory(exports);
} else {
// Browser globals
@joaopfsilva
joaopfsilva / check-routes.rb
Created September 20, 2019 06:48
Check unused routes
# Download this into the root folder of your Rails project & run it with "ruby check-routes.rb"
# Originaly created by https://gist.githubusercontent.com/matugm/c298767ad1d97a52f76630bfc03008a1/raw/d1bfa23a0bf4ab24cf295eea030f4e3dccf653d7/check-routes.rb
require_relative "config/environment"
Rails.application.eager_load!
results =
Rails.application.routes.routes.map(&:requirements).reject(&:empty?).map do |r|
name = r[:controller].camelcase
{"lastUpload":"2019-10-01T06:09:22.682Z","extensionVersion":"v3.4.3"}