Skip to content

Instantly share code, notes, and snippets.

View ErvalhouS's full-sized avatar
🔥
This is fine

Fernando H. E. Bellincanta ErvalhouS

🔥
This is fine
View GitHub Profile
#! /bin/bash
SERVER_NAME="turn:server.turn:443"
SECRET=5up3r53cr7
expiry=8400
time=$(date +%s)
username="$(( $time + $expiry )):justanusername"
password=$(echo -n $username | openssl dgst -binary -sha1 -hmac $SECRET | openssl base64)
echo "server => $SERVER_NAME"
@ErvalhouS
ErvalhouS / aws_mfa.sh
Created April 5, 2021 02:05
Easier AWS MFA on CLI
#!/bin/bash
AWS_ACCESS_KEY_ID=""
AWS_SECRET_ACCESS_KEY=""
AWS_SESSION_TOKEN=""
(
echo "Welcome to AWS CLI MFA 😎"
if [ -z "$MFA_DEVICE_ARN" ]; then
echo "Your Multi-factor authentication device has an ARN visible at: https://console.aws.amazon.com/iam/home?region=us-east-1#/security_credentials"
echo
echo "You can export your MFA device ARN as MFA_DEVICE_ARN environmental variable to avoid having to input it every time. Just add something like this to your equivalent of a ~/.bash_profile"
@ErvalhouS
ErvalhouS / wsl_hosts.sh
Last active December 28, 2020 12:43
This gist makes it possible to maintain `.test` domains working on your windows + WSL setup
#!/bin/bash
ip_address=`hostname -I`
for host_name in hubstaff.test account.hubstaff.test app.hubstaff.test tasks.hubstaff.test talent.hubstaff.test
do
matches_in_hosts="$(grep -n " $host_name" /etc/hosts | cut -f1 -d:)"
host_entry="${ip_address} ${host_name}"
if [ ! -z "$matches_in_hosts" ]
then
echo "Replacing existing record for $host_name"
while read -r line_number; do
@ErvalhouS
ErvalhouS / WindowsHosts.ps1
Last active February 4, 2021 12:45
This gist makes it possible to maintain `.test` domains working on your windows + WSL setup
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Start-Process powershell.exe "-File",('"{0}"' -f $MyInvocation.MyCommand.Path) -Verb RunAs
exit
}
$DesiredIP = ((bash.exe -c "hostname -I") | Out-String) -replace '\s',''
$domains = "hubstaff.test","account.hubstaff.test","app.hubstaff.test","tasks.hubstaff.test","talent.hubstaff.test"
$hostsFilePath = "$($Env:WinDir)\system32\Drivers\etc\hosts"
$hostsFile = Get-Content -path $hostsFilePath -raw
if ($hostsFile -notmatch "`r`n$") {
Add-Content $hostsFilePath "`r`n"
@ErvalhouS
ErvalhouS / discard_application_record.rb
Created January 25, 2019 18:11
An application record to enable some explicit method overriding to make discard behave just a little like paranoia or act_as_paranoid.
# frozen_string_literal: true
# An abstract model to allow common behavior to be inherited
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
include Discard::Model
default_scope -> { kept }
def destroy
@ErvalhouS
ErvalhouS / custom_fields.rb
Last active August 17, 2018 18:42
A way to receive and retrieve non-migrated fields using a SQL database with JSON field support. The only thing you need to do is create a JSON column called `fields` in the table and include this module into your model.
# frozen_string_literal: true
# A module to abstract a noSQL aproach into SQL records, using a `fields`
# JSON column.
module CustomFields
# Overriding `method_missing` does the magic of assigning an absent field
# into `.fields` JSON as a key-value pair, or recovering it's value if exists.
def method_missing(meth, *args, &block)
raise NoMethodError, "#{table_name} should have a `fields` JSON column" unless can_no_sqlize?
no_sqlize(meth, *args, &block)
@ErvalhouS
ErvalhouS / paperclip.rb
Last active August 24, 2018 21:05
A monkey patch to add url for each paperclip version on the records' serialized JSONs
# frozen_string_literal: true
# Paperclip's module
module Paperclip
# Module that contains methods used on Models
module ClassMethods
# Overriding this method to add all initialized fields into class variable
def has_attached_file(name, options = {})
class_eval do
@@_paperclip_attachments ||= {}
@ErvalhouS
ErvalhouS / frontend_api.rb
Last active July 10, 2018 15:19
A read-only frontend API abstraction applicable to any application.
# frozen_string_literal: true
module Api
module V1
# Controller to consume read-only data to be used on client's frontend
class FrontEndController < ActionController::API
prepend_before_action :set_root_resource
before_action :set_object, except: %i[index schema]
append_before_action :set_nested_resource, only: %i[nested_index]
append_before_action :set_records, only: %i[index nested_index]
@ErvalhouS
ErvalhouS / sitemap.rb
Created April 9, 2018 14:09
A rake task to ping main search providers with updated sitemap.xml
desc "rake 'latest:sitemap' Pings search engines with current channels sitemap addresses"
task sitemap: :environment do
def http_get(domain,path,params)
return Net::HTTP.get(domain, "#{path}?".concat(params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&'))) unless params.nil?
return Net::HTTP.get(domain, path)
end
Site.all.each do |channel|
unless channel.domain.include?("autoforce") && channel.groupables.any?
http_get "blogs.yandex.ru", "/pings/", {status: "success", url: (channel.domain + "/sitemap.xml")}
http_get "google.com", "/webmasters/tools/ping", {sitemap: (channel.domain + "/sitemap.xml")}
@ErvalhouS
ErvalhouS / experience.rb
Created April 6, 2018 14:33 — forked from mamantoha/experience.rb
Rails API Filtering and Sorting
# app/models/experience.rb
#
# == Schema Information
#
# Table name: experiences
#
# id :integer not null, primary key
# title :string
# description :text
# created_at :datetime not null