Skip to content

Instantly share code, notes, and snippets.

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
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
@mvasin
mvasin / config.ru
Created November 5, 2017 10:56
The simplest code possible to upload a file to a server
# uploads folder must exist.
require 'roda'
class App < Roda
route do |r|
r.root do
<<-HEREDOC
<html>
<body>
@mvasin
mvasin / config.ru
Created November 5, 2017 14:46
The slimmest app possible for uploading files to S3 using Shrine gem
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
# 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
@mvasin
mvasin / config.ru
Created January 18, 2018 11:20
A simple rack app for educational purposes: upload a file and have it presented in the browser
class App
def self.call env
new(env).call
end
def initialize env
@request = Rack::Request.new env
@response = Rack::Response.new
end
@mvasin
mvasin / docker-compose.yml
Last active January 31, 2018 16:02
A way to start bedrock-flavoured WordPress site in Docker
# 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"
@mvasin
mvasin / export-import-volumes.sh
Last active February 22, 2018 22:09
Export a Docker volume to a .tar / Import into Docker volume from a .tar / Duplicate volumes (via tar)
# 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)
@mvasin
mvasin / throttle.js
Last active September 19, 2018 16:46
// 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) {
const nullNode = null;
const node1 = {
left: nullNode,
right: nullNode,
value: 1
};
const node3 = {
left: nullNode,