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 'shrine' | |
require 'shrine/storage/s3' | |
S3_OPTIONS = { | |
access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'), | |
secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'), | |
region: 'eu-central-1', | |
bucket: ENV.fetch('AWS_BUCKET') | |
}.freeze |
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 'roda' | |
require 'shrine' | |
require 'shrine/storage/s3' | |
S3_OPTIONS = { | |
access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'), | |
secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'), | |
region: 'eu-central-1', | |
bucket: ENV.fetch('AWS_BUCKET') | |
}.freeze |
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
# uploads folder must exist. | |
require 'roda' | |
class App < Roda | |
route do |r| | |
r.root do | |
<<-HEREDOC | |
<html> | |
<body> |
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 'roda' | |
require 'shrine' | |
require 'shrine/storage/s3' | |
S3_OPTIONS = { | |
access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'), | |
secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'), | |
region: ENV.fetch('AWS_REGION'), | |
bucket: ENV.fetch('AWS_BUCKET') | |
}.freeze |
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
# PubSub with a microservice: send a message to a fleet of workers, | |
# let one of workers pick the task and send the result message directly to the requester. | |
# the manager | |
# pub.rb | |
require 'redis' | |
trap(:INT) { puts 'Bye!'; exit } | |
r = Redis.new |
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 App | |
def self.call env | |
new(env).call | |
end | |
def initialize env | |
@request = Rack::Request.new env | |
@response = Rack::Response.new | |
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
# A way to quickly start bedrock-flavored (see roots.io) WordPress site in Docker | |
# Here are the steps: | |
# - Add `127.0.0.1 your-site.com` to /etc/hosts files with `sudo nano /etc/hosts` | |
# - Save this file as docker-compose.yml in the root of your project (along with composer.json) | |
# - Put your database to db.sql in the root of the project, if any | |
# - Execute `docker-compose up -d` | |
# - Wait for approximately 10-100 seconds | |
# - Navigate to `localhost` | |
version: "3" |
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
# Usage: export_volume volume_name | |
# export_volume volume_name > file.tar | |
# | |
# prints to STDOUT a volume in .tar format | |
export_volume() { | |
# Quit if volume name is not specified | |
vol=${1:?} | |
# If there is no such container, a new container will be created, we don't need that | |
docker volume inspect $vol > /dev/null || (echo "Container specified for export doesn't exist" && return 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
// wait in milliseconds | |
function throttle(fn, wait) { | |
// unix timestamp | |
let lastTimeExecuted; | |
return function (args) { | |
const currentTime = new Date(); | |
// this condition is satisfied only the very first time | |
if (!lastTimeExecuted) { |
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 nullNode = null; | |
const node1 = { | |
left: nullNode, | |
right: nullNode, | |
value: 1 | |
}; | |
const node3 = { | |
left: nullNode, |
OlderNewer