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``
@tabishiqbal
tabishiqbal / _form.html.erb
Last active May 2, 2024 13:30
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>
@adrienpoly
adrienpoly / application.html.erb
Last active March 22, 2024 08: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 December 28, 2021 05:10
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"
@dwilkie
dwilkie / migrate_from_refile_to_activestorage.rb
Last active May 17, 2023 20:26
Migrate from Refile to ActiveStorage
CallDataRecord.find_each do |cdr|
next if cdr.file.attached?
cdr_url = "https://s3-ap-southeast-1.amazonaws.com/cdr.somleng.org/store/#{cdr.file_id}"
cdr.file.attach(
io: open(cdr_url),
filename: cdr.file_filename,
content_type: cdr.file_content_type
)
end
@amicojeko
amicojeko / nested_form_controller.js
Last active January 5, 2024 04:35
Stimulus nested form (cocoon alternative)
// Visit The Stimulus Handbook for more details
// https://stimulusjs.org/handbook/introduction
//
// This example controller works with specially annotated HTML like:
//
// <h4>Tasks</h4>
// <div data-controller="nested-form">
// <template data-target="nested-form.template">
// <%= form.fields_for :tasks, Task.new, child_index: 'NEW_RECORD' do |task| %>
// <%= render "task_fields", form: task %>