Skip to content

Instantly share code, notes, and snippets.

View mrstif's full-sized avatar

André Andrade mrstif

  • Hole19
  • Lisbon, Portugal
View GitHub Profile
@dhh
dhh / Gemfile
Created June 24, 2020 22:23
HEY's Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
@adammagana
adammagana / SkuDetails.PricePerMonth.kt
Last active March 15, 2021 22:21
An Android SkuDetails property extension that calculates price-per-month.
import com.android.billingclient.api.SkuDetails
import java.lang.Exception
import java.text.NumberFormat
import java.util.*
/**
* Currency code for the U.S. dollar
*/
private const val USD = "USD"
@wildjcrt
wildjcrt / verify_and_decrypt_session_cookie60beta1.rb
Last active September 10, 2024 14:51 — forked from inopinatus/verify_and_decrypt_session_cookie52.rb
Decrypt Rails 6.0 beta session cookies
require 'cgi'
require 'active_support'
def verify_and_decrypt_session_cookie(cookie, secret_key_base = Rails.application.secret_key_base)
config = Rails.application.config
cookie = CGI::unescape(cookie)
salt = config.action_dispatch.authenticated_encrypted_cookie_salt
encrypted_cookie_cipher = config.action_dispatch.encrypted_cookie_cipher || 'aes-256-gcm'
# serializer = ActiveSupport::MessageEncryptor::NullSerializer # use this line if you don't know your serializer
serializer = ActionDispatch::Cookies::JsonSerializer
#!/usr/bin/env ruby
require "yaml"
CONFIG = "~/database.yml"
CONFIG_PARAMS = %w(protocol host port database username password).map(&:to_sym)
def say(channel=:info, msg)
puts "[#{channel.to_s.upcase}] #{msg}"
end

Validate JSON schema in Rails

Topics

  1. What/Why JSON schema
  2. Apply to rails model validation
  3. Test your API endpoint with schema matcher
  4. Homework for a curious reader
  5. References
@miguelmota
miguelmota / setup.config
Last active July 26, 2021 15:42
Elastic Beanstalk NGINX rewrite http to https using .ebextensions
files:
"/etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf":
mode: "000755"
owner: root
group: root
content: |
server {
listen 80;
gzip on;
@winebarrel
winebarrel / pg_show_grants.sql
Last active July 12, 2022 00:28
show grants for PostgreSQL
select
pg_user.usename,
t1.nspname,
t1.relname,
relacl.privilege_type,
relacl.is_grantable
from (
select
pg_namespace.nspname,
pg_class.relname,
@igorescobar
igorescobar / jenkins-build-pipeline-to-markdown-table.js
Last active January 19, 2017 02:25
Small script to convert an Build Pipeline View to a Markdown table
/*
Instructions:
1 - Open the Jenkins Pipeline View with your browser
2 - Open the console and execute the following code
3 - Copy the output and paste into your README.md
Your github README.md will never be the same ;o)
Example:
| CI | Build Pipeline: Project Name |
|-------------|:------------------------------:|
@igorescobar
igorescobar / docker-tips.sh
Last active May 3, 2018 10:15
Docker useful commands
# Clean unused images
docker image prune
# Clean up dangling volumes
docker volume rm $(docker volume ls -qf dangling=true)
# Stop all containers
docker stop $(docker ps -a -q)
@aanari
aanari / batch_at_will_commander.sql
Last active August 8, 2020 15:31
7 PostgreSQL data migration hacks you should be using (but aren't)
CREATE FUNCTION batch_at_will() RETURNS INTEGER LANGUAGE plpgsql AS $$
DECLARE batched_count INTEGER = 1;
BEGIN
WITH selected_users AS (
SELECT id
FROM users
WHERE role = 'moderator'
AND registration_date < CURRENT_DATE - INTERVAL '4' YEAR
LIMIT 1000
FOR UPDATE NOWAIT