Skip to content

Instantly share code, notes, and snippets.

View thadeu's full-sized avatar
🏠
Working from home

thadeu thadeu

🏠
Working from home
View GitHub Profile
@thadeu
thadeu / rspec_model_testing_template.rb
Created April 3, 2020 13:33 — forked from PWSdelta/rspec_model_testing_template.rb
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@thadeu
thadeu / csv.js
Created March 16, 2020 12:55
Generate CSV with JS Native
export default function Csv() {}
Csv.parse = function(data) {}
Csv.compose = function(data) {
let values = []
let header = Object.keys(data[0])
let csv = header.join(',')
// each object values
@thadeu
thadeu / README.md
Last active February 6, 2020 18:43
tcpdump 5060 sip messages

method 1

tcpdump -nqt -s 0 -A -i eth0 port 5060 -w /tmp/dump.pcap

tcpdump -qns 0 -A -r /tmp/dump.pcap

method 2

apt-get install ngrep sipgrep sngrep.

@thadeu
thadeu / update-datetime-debian.md
Last active February 5, 2020 21:55
Check and Update date to debian

Check and Update date to debian

List timezones easily

  $ timedatectl list-timezones

Set timezone to America/Sao_Paulo

on run {input, parameters}
set paths to ""
repeat with i from 1 to length of input
set cur to item i of input
set paths to paths & " " & quote & POSIX path of cur & quote
end repeat
set cmd to "vim -p" & paths
tell application "iTerm"
set created to false
if not (exists current window) then
@thadeu
thadeu / named_route.rb
Created October 16, 2019 14:48
Named Route Rails 5+
# Return a named route to current url requested
def route_name
Rails.application.routes.router.recognize(request) do |route, _|
return route.name.to_sym
end
end
@thadeu
thadeu / README.md
Created September 25, 2019 21:50
Active Storage Remove Attachments

ActiveStorageRemove

Do you need remove files in the active_storage rails?

Use this files :)

@thadeu
thadeu / readme.md
Created August 15, 2019 15:59
Elastic Beanstalk Rails

Iniciar um configuracao EB

eb init --profile thadeu

Criar um Environment pra aplicação

eb create fielservicos-production --profile thadeu

Criar um SECRET_KEY_BASE

eb setenv SECRET_KEY_BASE=(rails secret)

Criar um RDS para aplicação e colocar as variaveis no database.yml

@thadeu
thadeu / promise-race.md
Last active June 28, 2019 18:04
Timeout Promise with race promises
const race = (milliseconds, ...promises) => {
  const timeout = new Promise((resolve, reject) => {
    setTimeout(() => reject(`Limit operation excedded (limit: ${milliseconds} ms)`), milliseconds)
  })

  return Promise.race([timeout, ...promises])
}
@thadeu
thadeu / pick.md
Last active June 26, 2019 15:51
Nested Pick Object

Patch

export function pick(o, ...keys) {
  return keys.reduce((acc, k) => (Boolean(acc[k]) ? acc[k] : ''), o)
}

Example Use