Skip to content

Instantly share code, notes, and snippets.

View mhenrixon's full-sized avatar
🐢
I may be slow to respond.

Mikael Henriksson mhenrixon

🐢
I may be slow to respond.
View GitHub Profile
@kddnewton
kddnewton / json.rb
Last active August 7, 2023 19:54
Faster JSON parser in Ruby
# frozen_string_literal: true
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "json_pure"
gem "benchmark-ips"
end

OpenBSD logo     Rails logo     Falcon logo


Choose OpenBSD for your Unix needs. OpenBSD -- the world's simplest and most secure Unix-like OS. A safe alternatve to the frequent vulnerabilities and overengineering of Linux and related software (NGiNX & Apache (httpd-asiabsdcon2015.pdf), OpenSSL, iptables/nftables, systemd, BIND, Postfix, Docker etc.)

OpenBSD -- the cleanest kernel, the cleanest userland and the cleanest config

@mabenson00
mabenson00 / cheatsheet.rb
Last active May 3, 2024 22:40
Rails 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
on:
workflow_call:
inputs:
deploy_target:
description: 'Deploy target'
required: true
type: string
default: 'production'
secrets:
GH_TOKEN:
@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>
@lunohodov
lunohodov / tailwind.config.js
Created August 23, 2021 11:10
Tell TailwindCSS not to purge form elements
module.exports = {
purge: {
content: [
'./app/**/*.html.erb',
'./app/**/*.js',
],
safelist: [
'form-input',
'form-textarea',
'form-select',
@rainerborene
rainerborene / dom.js
Last active February 17, 2022 14:54
rails-ujs is a past thing. Here is how you can accomplish almost the same behaviour with Stimulus and Hotwire.
export function reduceToParams(elements) {
return elements.reduce((hash, node) => Object.assign(hash, { [node.name]: node.value }), {})
}
export function stopEverything(e) {
e.preventDefault()
e.stopPropagation()
e.stopImmediatePropagation()
}
@julianrubisch
julianrubisch / categories_controller.rb
Last active January 22, 2024 06:44
Dependent Select with StimulusJS
class CategoriesController < ApplicationController
def fields
render json: Field.where(category_id: params[:id]).order(:id)
end
end
require 'English'
namespace :db do # rubocop:disable Metrics/BlockLength
task :prevent_disparate_pg_dump_versions => :environment do
allowed_pg_dump_version = '9.6.10'.freeze
`pg_dump --version`
pg_dump_exit_status = $CHILD_STATUS.exitstatus
locally_installed_version = `pg_dump --version`.chomp[/(\d.*)/,1] rescue nil