This file contains hidden or 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
def get_helper_modules(subtree = []) | |
helper_directory = Rails.root.join('app').join('helpers') | |
subtree.each do |folder| | |
helper_directory = helper_directory.join(folder) | |
end | |
entries = Dir.entries(helper_directory) - %w(. ..) | |
files = entries.select { |e| e.include?('.rb') } | |
modules = files.map do |file| | |
module_name = subtree.map(&:camelcase).join('::') | |
if module_name.present? |
This file contains hidden or 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
class PersistentHttpClient | |
def self.get(url) | |
uri = url.is_a?(URI) ? url : URI(url) | |
connection_manager.get_connection(uri) | |
end | |
def self.connection_manager | |
Thread.current[:persistent_http_connection_manager] ||= new_manager | |
end |
This file contains hidden or 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
Whenever::Output::Cron.new(:monday, nil, '3:01 am', {}).time_in_cron_syntax | |
# => "1 3 * * 1" |
This file contains hidden or 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
export default function MapsStaticApiExample({ | |
markers, | |
height, | |
width, | |
center, | |
zoom, | |
}: Props) { | |
return ( | |
<img | |
alt="Map Preview" |
This file contains hidden or 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
class TextEncryptor | |
class << self | |
def encrypt(text) | |
text = text.to_s unless text.is_a? String | |
len = ActiveSupport::MessageEncryptor.key_len | |
salt = SecureRandom.hex len | |
key = ActiveSupport::KeyGenerator.new(secret).generate_key salt, len | |
crypt = ActiveSupport::MessageEncryptor.new key | |
encrypted_data = crypt.encrypt_and_sign text |
This file contains hidden or 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
class PhoneVerification | |
class << self | |
# time that user has before a code expires | |
EXPIRATION = 5.minutes | |
# an SMS can't be sent more frequently than that | |
TIME_BEFORE_RESEND = 30.seconds | |
# how many times can a user enter an invalid code | |
MAX_ATTEMPTS = 5 |
This file contains hidden or 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
const ProfilePage: NextPage = () => { | |
return ( | |
<PageLayout> | |
{/* PAGE BODY */} | |
</PageLayout> | |
) | |
} | |
// THE ACTUAL USAGE | |
requireAuth(ProfilePage) |
This file contains hidden or 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 'benchmark' | |
n = 100 | |
def random_uri | |
URI("https://rickandmortyapi.com/api/character/#{rand(399) + 1}") | |
end | |
Benchmark.bm do |x| | |
x.report do |
This file contains hidden or 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
class ApplicationMailer < ActionMailer::Base | |
def new_blog_post(blog_post, subscriber) | |
# by calling "store_message" we are saying that this | |
# emails need to be saved in our database | |
# for further tracking | |
store_message( | |
email_name: 'new_blog_post', | |
entity: blog_post, | |
user: subscriber | |
) |
This file contains hidden or 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
buttons=[] | |
document.querySelectorAll('ytd-playlist-video-renderer ytd-menu-renderer #button.style-scope.yt-icon-button').forEach(b => buttons.push(b)) | |
while(bs.length > 0) { | |
let button = buttons.pop() | |
button.click() | |
await (new Promise(resolve => setTimeout(resolve, 500))) | |
let dropdownItems = []; | |
document.querySelectorAll('tp-yt-paper-listbox tp-yt-paper-item').forEach(n => dropdownItems.push(n)); | |
dropdownItems.find(e => e.textContent.includes('Remove from Watch later')).click() | |
await (new Promise(resolve => setTimeout(resolve, 3000))) |