This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~ Dispatch jQuery events as regular DOM events ~ | |
# | |
# Delegated events are given a new name in the format `jquery:<original event name>`. | |
# If you delegate `ajax:send` you will be able to listen for `jquery:ajax:send` | |
# on native event listeners such as Stimulus actions and `EventTarget.addEventListener`. | |
# | |
# Notes: | |
# * The first parameter must be called "event". | |
# * The parameters can be accessed as members on the `event.detail` object. | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
pid, | |
now() - pg_stat_activity.query_start AS duration, | |
query, | |
state | |
FROM pg_stat_activity | |
WHERE (now() - pg_stat_activity.query_start) > interval '1 minutes' and state<>'idle' | |
order by pg_stat_activity.query_start desc; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Remove orphaned items (documents without an equivalent database record) from elasticsearch/opensearch index | |
index = AccountsIndex # Target index | |
index.search(query: { match_all: {} }, _source: false).scroll_hits do |hits| | |
print(".") | |
es_ids = hits.map { |hit| hit.fetch("_id").to_i } | |
db_ids = index.repo.dataset.except(:includes, :preload).where(id: es_ids).pluck(:id) | |
prune_ids = es_ids - db_ids | |
next if prune_ids.none? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker-compose run --rm -v $(readlink -f $SSH_AUTH_SOCK):/ssh-agent -e SSH_AUTH_SOCK=/ssh-agent -e BRANCH=master app bundle exec cap staging deploy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git diff --name-only HEAD..staging | grep -E -i 'rake|*.rb|*.erb' | perl -ne 'chomp(); if (-e $_) {print "$_\n"}' | xargs rubocop -A |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module AdapterOne | |
def instance_method | |
':one instance method' | |
end | |
alias one instance_method | |
end | |
module AdapterTwo | |
def instance_method | |
':two instance method' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generate keys | |
# $ openssl genrsa -des3 -out private.pem 2048 | |
# $ openssl rsa -in private.pem -outform PEM -pubout -out public.pem | |
# $ irb | |
require 'openssl' | |
require 'base64' | |
# Encrypt | |
public_key = OpenSSL::PKey::RSA.new(File.read('public.pem')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> authenticate?(3, 'one') | |
=> false | |
>> authenticate?(1, 'one1') | |
=> false | |
>> authenticate?(1, 'one') | |
=> true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'openssl' | |
key = OpenSSL::PKey::RSA.new(2048) | |
p encrypted_string = key.public_encrypt('my plaintext string', OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING) | |
p decrypted_string = key.private_decrypt(encrypted_string, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# It's ODM (Object Document Mapper) to the RGB data | |
class RGB | |
COLORS = { | |
r: ->(val) { "\e[31m#{val}\e[0m" }, | |
g: ->(val) { "\e[32m#{val}\e[0m" }, | |
b: ->(val) { "\e[34m#{val}\e[0m" }, | |
}.freeze |
NewerOlder