Skip to content

Instantly share code, notes, and snippets.

View kivanio's full-sized avatar
🏠
Working from home

Kivanio Barbosa kivanio

🏠
Working from home
View GitHub Profile
@badosu
badosu / batch_invalidation.js
Last active February 16, 2020 02:41
Sidekiq Batch Invalidation UI
const appendInvalidationRow = row => {
$('tbody')
.first()
.append(`<tr><th>Validation</th><td>${row}</td></tr>`);
};
const setupBatchInvalidation = (rootUrl, bid) => {
$.getJSON(`${rootUrl}api/batches/${bid}/invalidated`, data => {
if (data.invalidated) {
appendInvalidationRow('Invalid');
@robertrossmann
robertrossmann / all-indexes.sql
Last active January 26, 2024 03:00
Postgres diagnostics
-- List all existing indexes and include some useful info about them (incl. the index's definition)
SELECT
schemaname AS schemaname,
t.relname AS tablename,
ix.relname AS indexname,
regexp_replace(pg_get_indexdef(i.indexrelid), '^[^\(]*\((.*)\)$', '\1') AS columns,
regexp_replace(pg_get_indexdef(i.indexrelid), '.* USING ([^ ]*) \(.*', '\1') AS algorithm,
indisunique AS UNIQUE,
indisprimary AS PRIMARY,
# config/initializers/activestorage.rb
Rails.application.config.to_prepare do
# Provides the class-level DSL for declaring that an Active Record model has attached blobs.
ActiveStorage::Attached::Macros.module_eval do
def has_one_attached(name, dependent: :purge_later, acl: :private)
class_eval <<-CODE, __FILE__, __LINE__ + 1
def #{name}
@active_storage_attached_#{name} ||= ActiveStorage::Attached::One.new("#{name}", self, dependent: #{dependent == :purge_later ? ":purge_later" : "false"}, acl: "#{acl}")
end
@mrmartineau
mrmartineau / stimulus.md
Last active May 12, 2024 04:35
Stimulus cheatsheet
@preallocate = []
500_000.times do
@preallocate << ""
end
def process_request
allocate = rand(80_000) + 20000
req = []

Intercom user_hash

Remember that your secret key should never be exposed to the public

  • So Javascript code below should only be used for testing unless modified and used to run on a server
@orendon
orendon / authorization_code.rb
Last active March 11, 2019 15:06
Doorkeeper Oauth2 - Authorization Flows
# https://github.com/doorkeeper-gem/doorkeeper/wiki/authorization-flow
resource_owner_authenticator do
current_user || redirect_to(new_user_session_url)
end
# ----
callback = "urn:ietf:wg:oauth:2.0:oob"
app_id = "28d7adbcf95a70fdcb6101a517645762b84a16ae5077b5e0b7a678f2f188b0d2"
secret = "0fc0c9ae38548404b001a3fdb3e9f4e90c22b78ba74df2104d7a37c1cb251687"
@toolmantim
toolmantim / sidetiq_schedule_time_zone_additions.rb
Last active November 30, 2016 18:59
An addition to Sidetiq to make it easier to declare the worker's schedule's timezone. Assumes ActiveRecord::TimeZone is available.
# Timezone extension to Sidetiq
Sidetiq::Schedulable::ClassMethods.class_eval do
# Sets the time zone for the recurrence rules.
#
# Example:
#
# class MyWorker
# include Sidekiq::Worker
# include Sidetiq::Schedulable
#
# config/routes
Lsa::Application.routes.draw do
# Administrator
constraints :subdomain => "admin" do
ActiveAdmin.routes(self)
devise_for :admin_users, ActiveAdmin::Devise.config
end
end
@virtualstaticvoid
virtualstaticvoid / default_values.rb
Created March 19, 2014 16:04
Rails 4 Concern for Default Attribute Values
#
#
# Rails 4 concern for specifying default attribute values on models
#
# E.g. The following user has defaults defined for `active` and `manager` attributes
#
# class User < ActiveRecord::Base
# include Concerns::DefaultValues
#
# default_value :active, true