Skip to content

Instantly share code, notes, and snippets.

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

Oleksandr Kirpachov kirpachov

🏠
Working from home
View GitHub Profile
# frozen_string_literal: true
require 'sidekiq/web'
require 'sidekiq/cron/web'
require 'sidekiq-status/web'
Rails.application.routes.draw do # rubocop:disable Metrics/BlockLength
mount RoutesBasicAuth.call(
Sidekiq::Web,
username: ENV["BASIC_AUTH_USERNAME"],
require "rails_helper"
RSpec.describe Something do
# ...
around do |example|
ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
example.run
ActiveJob::Base.queue_adapter.perform_enqueued_jobs = false
end
end
@kirpachov
kirpachov / Copy locally production database.md
Last active May 9, 2025 17:12
Scripts to setup postgresql with pitr on s3 + disaster recovery

Production database must be a postgresql configured with wal-g and s3.

Copy locally a production database

In questo esempio specifico riproduciamo il database di lime3 (q.opinioni.net) in locale.

0. Generic requirements configuration

  • local postgresql installation
  • wal-g configured. Verify wal-g configuration with wal-g backup-list
  • aws iam user with s3 read permissions
# Add Docker's official GPG key: 1
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \

Active storage

  • Does not save files to disk until commit.
Post.transaction do
  # This one is ok. Returns true.
  @post.attachments.attach(io: StringIO.new("something...."), filename: "new-post.txt", content_type: "plain/text")
  
  # This would raise ActiveStorage::FileNotFound error.
  # Plus, you won't find any new file in the filesystem until commit.
 # @post.attachments.last.download
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at

Try this in your rails console with rails c:

Sidekiq.redis{|r| r.get("stat:processed") }

some_data = Sidekiq.redis { |conn|
    conn.pipelined do
    conn.get("stat:processed")
    conn.get("stat:failed")
 conn.zcard("schedule")
@kirpachov
kirpachov / rxjs snippets.ts
Created September 21, 2023 15:32
Snippets of things I've done once but I'll probably need again
/**
* Emit each element of array as single event.
*/
const array$: Subject<string[]> = new Subject<string[]>();
const each$: Observable<string> = array$.pipe(
tap((v: string[]) => console.log('array', v)),
switchMap((array: string[]) => merge(...(array.map((item: string) => of(item))))),
tap((v: string) => console.log('each', v)),
);
@kirpachov
kirpachov / remove_html_columns.sh
Created April 20, 2023 10:26
Remove html columns in bash
function get_html(){
echo $(cat $filename | sed 's/<!--.*-->//g' | sed 's/\/*.*\*\///g' | sed 's/\/\/.*$//gm')
}

Tunneling http with caddy

You can expose a http port from a private network using caddy and ssh

Getting started

  1. Set up the server
  2. Set up the client
  3. Navigate to your host.

Server

Server must be a pc or a server with a static public ip and a nameserver.