Skip to content

Instantly share code, notes, and snippets.

View fernandes's full-sized avatar
🤓
Programming

Celso Fernandes fernandes

🤓
Programming
View GitHub Profile
@fernandes
fernandes / .solargraph.yml
Created August 22, 2023 00:54
Solargraph Configuration
include:
- "lib/**/*.rb"
- "app/**/*.rb"
- definitions.rb
exclude:
- spec/**/*
- test/**/*
- vendor/**/*
- ".bundle/**/*"
- fixtures/**/*
require "test_helper"
class Splasher
attr_reader :total, :range, :per, :mod, :unit, :unit_total, :start_at
def initialize(total:, range:, unit: :hour, per: :hour, start_at: DateTime.now)
@total = total
@range = range
@unit = unit
@per = per
@fernandes
fernandes / PKCS7_decrypt.cr
Created August 31, 2021 12:55
How to decrypt a PKCS7 in Crystal using OpenSSL
# shard.yml
# dependencies:
# openssl_ext:
# github: spider-gazelle/openssl_ext
# version: ~> 2.0
require "openssl"
require "openssl_ext"
ciphertext = "-----BEGIN CERTIFICATE-----
MIIBiQYJKoZIhvcNAQcDoIIBejCCAXYCAQAxggEhMIIBHQIBAD
@fernandes
fernandes / sign_out.cr
Created November 5, 2020 17:03
Hovering an element using Lucky Flow
def sign_out
visit ThatPageYouWant
hover_el = el("@your-hover-element")
# Calculate where we should move the mouse to on the page
# here we are using the x coordinate + half of the width of the element to be hovered
# and the same logic for the y position
hover_el_rect = hover_el.rect
@fernandes
fernandes / in_memory.rb
Created July 23, 2020 00:00
AR in memory
require "active_record"
require "sqlite3"
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:host => "localhost",
:database => ':memory:'
)
ActiveRecord::Schema.define do
@fernandes
fernandes / Dockerfile
Last active June 20, 2020 06:16
Docker multi stage build for Lucky Framework app
FROM crystallang/crystal:0.34.0-alpine-build AS build-env
ARG LUCKY_ROOT=/app
ARG DEV_PACKAGES="nodejs yarn"
ENV LUCKY_ENV=production
ENV NODE_ENV=production
WORKDIR $LUCKY_ROOT
# install packages
RUN apk update \
@fernandes
fernandes / 00_shard.yml
Last active November 21, 2021 22:00
[Crystal Lang] Lucky Framework + Shrine File Uploader
crystal: 0.34.0
dependencies:
lucky:
github: luckyframework/lucky
version: ~> 0.21
shrine:
github: jetrockets/shrine.cr
version: ~> 0.8
@fernandes
fernandes / auto_test.rb
Created February 21, 2020 13:32
Example for "Interface" and "Concrete" class in Ruby
require 'test_helper'
# Add the `described_class` so it can be used in the AutoInterfaceTest
class ActiveSupport::TestCase
def described_class
self.class.to_s.gsub(/Test$/, '').constantize
end
end
# In the interface, the example Auto - Car is dummy, because it should be
@fernandes
fernandes / postgresql_config.sh
Last active November 6, 2019 20:10
Shell Script function to change postgresql values
# Error Codes
# 1: No variable name specified
# 2: No value found for variable
# If wanna save name = 'value' (between quotes), use: postgresql_config 12 foo \'bar\' (escaped)
postgresql_config() {
VERSION=$1
NAME=$2
VALUE=$3
MATCHED=0
@fernandes
fernandes / operation.cr
Created July 13, 2019 16:11
Trailcrazer
class Dummy3 < Trailcrazer::Operation
step :one
step :two, StepTwo
# can be a block (pay attention to use {} and not do/end)
define_step :one, ->(ctx : Trailcrazer::Context, params : OperationType) {
ctx[:sum] = params[:initial] + 4
true
}