Skip to content

Instantly share code, notes, and snippets.

View piclez's full-sized avatar

Peter WD piclez

View GitHub Profile
@piclez
piclez / handler.test.js
Created June 12, 2024 19:57
Lambda Handler Test
const { handler } = require('./handler');
jest.mock("@sentry/node", () => ({
init: () => jest.fn(),
wrapHandler: () => jest.fn(),
}));
describe('handler', () => {
it('should return the correct response', async () => {
const event = {
@piclez
piclez / handler.js
Created June 12, 2024 19:52
Lambda Sentry Error
const Sentry = require("@sentry/node");
const { nodeProfilingIntegration } = require("@sentry/profiling-node");
Sentry.init({
dsn: "",
integrations: [
nodeProfilingIntegration(),
],
tracesSampleRate: 1.0,
profilesSampleRate: 1.0,
# Generate the models Estado and Cidade:
# rails generate Estado sigla:string nome:string
# rails generate Cidade estado:references nome: string
# rails db:migrate
# Put this code on your db/seeds.rb of your Ruby On Rails application
# rails db:seed
Estado.destroy_all
{
:AC=>"Acre",
:AL=>"Alagoas",
:AP=>"Amapá",
:AM=>"Amazonas",
:BA=>"Bahia", :CE=>"Ceará",
:DF=>"Distrito Federal",
:ES=>"Espírito Santo",
:GO=>"Goiás",
:MA=>"Maranhão",
@piclez
piclez / listings_controller.rb
Created March 30, 2023 01:36 — forked from dajulia3/listings_controller.rb
Service locator with Rails Initializer for rails service loader that loads the services from a config file.
class ListingsController < ApplicationController
def index
movie_listing_service = ServiceLocator.get_service_instance(:MovieListing)
@available_movies = movie_listing_service.available_movies
render nothing: true #this is just an example don't get hung up on it :)
end
@piclez
piclez / bulk_merge.rb
Created February 16, 2023 02:45 — forked from amichal/bulk_merge.rb
csv export and bulk load any rails scope
# Bulk merge a bunch of records
#
# we expect most of the records to import to represent updates
# so this method tries to be efficent with database queries
# by using a single query to find any existing records matching the key_attributes
# updating those records and finally inserting each remaining record
#
# It DOEST NOT use a transaction or lock. callers responsibilty to
# add that if desired
#
@piclez
piclez / resize_nocrop_noscale
Created January 8, 2023 03:44 — forked from maxivak/resize_nocrop_noscale
Crop and resize an image using MiniMagick in Ruby on Rails. Two approaches.
def resize_nocrop_noscale(image, w,h)
w_original = image[:width].to_f
h_original = image[:height].to_f
if w_original < w && h_original < h
return image
end
# resize
image.resize("#{w}x#{h}")
@piclez
piclez / nginx.conf
Last active January 7, 2021 19:26
nGinx & Passenger
load_module /usr/local/opt/passenger/libexec/modules/ngx_http_passenger_module.so;
#user nobody;
worker_processes 2;
# worker_rlimit_nofile 30000;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
Warning: require(/var/www/public/../vendor/autoload.php): failed to open stream: No such file or directory in /var/www/public/index.php on line 24
Fatal error: require(): Failed opening required '/var/www/public/../vendor/autoload.php' (include_path='.:/usr/local/lib/php') in /var/www/public/index.php on line 24