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

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.

Svg to ico with ubuntu bash

1. Install

NOTE: Some of this may be unecessary, idk sudo apt install inkscape imagemagick libcanberra-gtk-module libcanberra-gtk3-module canberra-gtk-module

2. Insert into ~/.bashrc

# This function will generate a '.ico' from a '.svg' and it will mov to the requested path

Rails notifications with websockets and ActionCable

Backend

  1. Create file connection.rb, notification_channel.rb, channel.rb
  2. Install redis

Frontend (angular)

  1. Install deps with
  • npm i --save actioncable
  • npm i --save-dev @types/actioncable