Skip to content

Instantly share code, notes, and snippets.

View minimul's full-sized avatar
🎯
Focusing

Christian Pelczarski minimul

🎯
Focusing
View GitHub Profile
@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 August 28, 2024 00:31
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 %>
@bnjamin
bnjamin / bare_transitions.js
Created June 23, 2020 10:28
Transitions stolen from alpine.js
export function transitionIn (el, show = () => {}) {
const attrs = getXAttrs(el, 'transition')
// If any transition attrs.
if (attrs.filter(attr => ['enter', 'enter-start', 'enter-end'].includes(attr.value)).length > 0) {
transitionClassesIn(el, attrs, show)
} else {
// If not, just show that damn thing.
show()
}
@leastbad
leastbad / README.md
Created April 16, 2020 08:08
Choices.js Stimulus wrapper preview

Choices.js Stimulus wrapper

https://joshuajohnson.co.uk/Choices/

Soon, this will be published as an NPM package, but there's an absence of documentation right now. It supports almost all functions from the original library; soon it will support 100% of them.

This wrapper adds Ajax pre-fetch search. Happens if controller has a data-search-path attribute.

Stimulus controller targets use new v2 syntax. Controller attaches a reference to itself on the element so that you can access the internal state from external scripts.

Loading variables from .env files in Ansible

Ansible has various ways of looking up data from outside sources, including plain text password files, CSV files and INI files. But it doesn't seem to have a lookup for .env files, as used in Laravel projects, also available for PHP, Ruby, Node.js, Python and others.

One option is to launch Ansible with the Ruby dotenv command line script... But that requires Ruby, which seems like overkill to me.

So here is a simpler solution that I use. It consists of:

  1. The .env file itself
  2. A small shell script that loads the .env file into environment variables - ansible-playbook.sh
@glv
glv / regexp_syntax.md
Last active November 1, 2024 18:55
Ruby and PostgreSQL Regular Expressions

Ruby and Postgres Regular Expression Syntaxes

Ruby's regular expressions are unusually powerful. Postgres' regular expressions are not as powerful, but they come close; close enough that it's possible to do many pattern-based queries and string transformations entirely in a query.

And sometimes, it's very useful to have a single regular expression that works

@roooodcastro
roooodcastro / preserve_on_blur.js
Created March 22, 2017 16:05
Selectize plugin - Select or preserve onBlur
/**
* Plugin: "preserve_on_blur" (selectize.js)
* Copyright (c) 2016 Eric M. Klingensmith
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
@c4nc
c4nc / 0-downtime-deploy-Unicorn-Systemd.md
Last active September 28, 2023 08:14
0-downtime deploy Unicorn Systemd

##Working configuration to accomplish 0-downtime deploy with unicorn 5.x and systemd on centos 7

The scope is to accomplish a 0-downtime reload of a unicorn service managed by Systemd on a Centos 7 distro.

The examples and assumptions that i found on the bogomips's unicorn repo seems not working for centos 7.

Below a working configuration tested on Centos 7 and unicorn 5.1

Any advice/remark will be appreciated

@nateberkopec
nateberkopec / 0.result.md
Last active January 18, 2024 11:20 — forked from tomfuertes/0.result.md
De-'Async Inject'ing Universal Analytics

De-'Async Inject' Universal Analytics

This gist applies the theory from Ilya Grigorik's Script-injected "async scripts" considered harmful on the default Universal Analytics snippet. TLDR place this above the CSS in the <head> of your document

<!-- Google Analytics Part 1: Creates window.ga, sets account, and queues pageview-->
<script>
  !function(n,t){n.GoogleAnalyticsObject=t,n[t]=n[t]||function(){(n[t].q=n[t].q||[]).push(arguments)},n[t].l=1*new Date}(window,"ga");
  ga('create', 'UA-XXXX-Y', 'auto'); // REPLACE UA-XXXX-Y w/ YOUR ACCOUNT
 ga('send', 'pageview');
@bhelx
bhelx / test.php
Last active September 16, 2017 12:29
TLS Low Level Testing. You should expect to see it print TLS version 1.2.
<?php
// This example is for testing php with libcurl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.howsmyssl.com/a/check");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);