Skip to content

Instantly share code, notes, and snippets.

View minimul's full-sized avatar
🎯
Focusing

Christian Pelczarski minimul

🎯
Focusing
View GitHub Profile
@kaushik94
kaushik94 / insert_user_id.sql
Created August 10, 2023 21:34
SQL Trigger to pre-insert user_id into message
CREATE FUNCTION insert_user_id()
RETURNS trigger AS $BODY$
BEGIN
SELECT id INTO NEW.to_id FROM users WHERE email = NEW.to_email;
RETURN NEW;
END;
$BODY$ LANGUAGE plpgsql;
CREATE TRIGGER insert_article BEFORE INSERT OR UPDATE ON messages FOR EACH ROW EXECUTE PROCEDURE insert_user_id();
- Check out
- install modern terraform version
- ``terraform init``
- get a Hetzner key,
- set it before run: ``` export TF_VAR_hcloud_token=...```
- ``terraform plan``
- ``terraform apply``
@mabenson00
mabenson00 / cheatsheet.rb
Last active April 18, 2025 17:46
Rails Postgres ActiveRecord JSON cheatsheet
# Basic key operators to query the JSON objects :
# #> : Get the JSON object at that path (if you need to do something fancy)
# -> : Get the JSON object at that path (if you don't)
# ->> : Get the JSON object at that path as text
# {obj, n} : Get the nth item in that object
# https://www.postgresql.org/docs/9.4/functions-json.html#FUNCTIONS-JSONB-OP-TABLE
# Date
# date before today
@tabishiqbal
tabishiqbal / _form.html.erb
Last active January 15, 2025 21:39
Ruby on Rails Tom-Select Example with Stimulus controller
<%= form_with(model: team) do |form| %>
<div>
<%= form.label :name %>
<%= form.text_field :name, class: "input" %>
</div>
<div>
<%= f.select :user_id, {}, {placeholder: "Select user"}, {class: "w-full", data: { controller: "select", select_url_value: users_path }} %>
</div>
@brenogazzola
brenogazzola / migrate_im_to_vips.md
Last active February 17, 2025 08:35
Steps to migrate ImageMagick to Libvips

For apps built before the image_processing gem became the default, the migration will involve two steps:

  1. Migrating to the image processing syntax while still using ImageMagick;
  2. Switching to Vips and updating the compression options;

Migrate to the image processing syntax

Before changing from ImageMagick to Vips, it's better to first test the new syntax and ensure everything is still working.

1. Move everything that has to do with compression to a saver hash:

variant(format: :jpg, strip: true, quality: 80)
@adrienpoly
adrienpoly / application.html.erb
Last active November 3, 2024 13:14
Capybara / Stimulus test helper to ensure JS is ready when test starts
<!DOCTYPE html>
<html>
<head>
...
</head>
<body data-controller="js">
<%= yield %>
</body>
</html>
@fractaledmind
fractaledmind / jobbable_concern.rb
Created March 1, 2021 09:09
This concern allows model instances to run async jobs that depend on them. Calling #async_method_name will trigger the MethodNameJob
module Jobbable
extend ActiveSupport::Concern
# This concern allows model instances to run async jobs that depend on them.
# Calling #async_method_name will trigger the MethodNameJob
PREFIX = "async_"
included do
def method_missing(method_name)
@rickychilcott
rickychilcott / slim_select_controller.js
Last active February 28, 2025 12:43
Slim-select stimulus controller
import { Controller } from "stimulus"
import SlimSelect from "slim-select"
import "slim-select/dist/slimselect.min.css"
import "../style/slimselect-customized.css"
export default class extends Controller {
connect() {
const limit = this.data.get("limit")
const placeholder = this.data.get("placeholder")
const searchText = this.data.get("no-results")
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", "6.0.0"