Skip to content

Instantly share code, notes, and snippets.

View adamgavlak's full-sized avatar

Adam Gavlák adamgavlak

View GitHub Profile
@adamgavlak
adamgavlak / signoff
Created May 9, 2024 06:32 — forked from dhh/signoff
#!/usr/bin/env bash
# Abort sign off on any error
set -e
# Start the benchmark timer
SECONDS=0
# Repository introspection
OWNER=$(gh repo view --json owner --jq .owner.login)
@adamgavlak
adamgavlak / instructions
Created February 15, 2019 18:31
How to enable HTML formatting for Embedded Elixir templates - *.html.eex in IntelliJ
Settings > Editor > File Types > In Recognized File Types find HTML and add *.html.eex to Registered Patterns
module FoodPreparer
#this can be used for an after_initialize in rails so calling cook_meal
#uses the @lookup varibale, otherwise you could just substitute the dis-
#patch_table method in its place
def build_dispatch_table
@lookup = {
turkey: -> (n) { cook_turkey n },
ham: -> (n) { cook_ham n },
module Filterable
extend ActiveSupport::Concern
module ClassMethods
def filter(filtering_params)
results = self.where(nil)
filtering_params.each do |key, value|
results = results.public_send(key, value) if value.present?
end
results
@adamgavlak
adamgavlak / dokku.sh
Created December 1, 2018 11:20
Basic dokku installation
# Create a Dokku app and addons
#------------------------------
## Go to http://SERVER_IP and add a IP address (if you don't it seems to go weird: use a junk one if needed)
dokku apps:create APP_NAME
## Add postgresql and link it to the application
dokku plugin:install https://github.com/dokku/dokku-postgres.git postgres
dokku postgres:create APP_NAME-db
dokku postgres:link APP_NAME-db APP_NAME
@adamgavlak
adamgavlak / diacritics.regex
Last active September 10, 2018 08:57
A regex that allows diacritics in matching string
^[.\ \'\p{L}]*$
@adamgavlak
adamgavlak / custom_form_builder.rb
Last active June 10, 2018 14:17
A way to extend default FormBuilder when using `form_with`
# custom_form_builder.rb
class CustomFormBuilder < ActionView::Helpers::FormBuilder
def error_tag(field, opts = {})
@template.content_tag(:span, @object.errors[field].join(", "), class: "text-danger") if [email protected][field].blank?
end
end
# _form.html.erb
<%= form_with(model: <model>, local: true, builder: CustomFormBuilder) do |form| %>
@adamgavlak
adamgavlak / do_locale_fix.sh
Created June 8, 2018 18:21
Fix Perl locale error on Ubuntu
update-locale LC_CTYPE=en_US.UTF-8
@adamgavlak
adamgavlak / readme.sh
Last active June 6, 2018 09:04
Dokku Postgres S3 bucket setup
# Create S3 bucket in any region
# Change bucket policy
{
"Version": "2018-06-06",
"Id": "Policy1528273129416",
"Statement": [
{
"Sid": "Stmt1528273125295",
"Effect": "Allow",
@adamgavlak
adamgavlak / README.sh
Created June 5, 2018 08:47 — forked from kimadactyl/README.sh
Dokku / Digital Ocean / Rails / Postgres / Let's Encrypt / persistent storage
# Creating a Digital Ocean droplet running Rails + Postgres with persistant storage and https
#--------------------------------------------------------------------------------------------
# For your ctrl-D pleasure...
# SERVER_IP
# APP_NAME
# RAILS_SECRET (generate with `rails secret`)
# ADMIN_EMAIL