Skip to content

Instantly share code, notes, and snippets.

View aablinov's full-sized avatar

Andrey Blinov aablinov

  • Uscreen.tv
  • Cyprus
View GitHub Profile
@aablinov
aablinov / redis-7-23-55-PM.patch
Created August 20, 2023 15:29
How to add custom command to Redis
diff --git forkSrcPrefix/src/server.h forkDstPrefix/src/server.h
index cb555031edf80aa48e1a601368b5bc58c086ff46..813f98be5233043e1dd7ad5d847da118bf615f90 100644
--- forkSrcPrefix/src/server.h
+++ forkDstPrefix/src/server.h
@@ -3492,6 +3492,7 @@ void lrangeCommand(client *c);
void ltrimCommand(client *c);
void typeCommand(client *c);
void lsetCommand(client *c);
+void mergeSetsCommand(client *c);
void saddCommand(client *c);
@aablinov
aablinov / dropzone_controller.js
Created May 26, 2023 06:12 — forked from lazaronixon/_form.html.erb
Dropzone.js + Stimulus + Active Storage
import { Controller } from "stimulus"
import { DirectUpload } from "@rails/activestorage"
import Dropzone from "dropzone"
import { getMetaValue, findElement, removeElement, insertAfter } from "helpers"
Dropzone.autoDiscover = false
export default class extends Controller {
static targets = [ "input" ]
import * as React from "react";
import { useMousePosition } from "~/hooks/useMousePosition";
/** Component to cover the area between the mouse cursor and the sub-menu, to allow moving cursor to lower parts of sub-menu without the sub-menu disappearing. */
export function MouseSafeArea(props: { parentRef: React.RefObject<HTMLDivElement> }) {
const { x = 0, y = 0, height: h = 0, width: w = 0 } = props.parentRef.current?.getBoundingClientRect() || {};
const [mouseX, mouseY] = useMousePosition();
const positions = { x, y, h, w, mouseX, mouseY };
return (
<div
@aablinov
aablinov / reset_seq.rb
Created February 21, 2023 09:02
Reset Postgres sequences after restore from dump
seqs = ActiveRecord::Base.connection.execute("select sequence_name from information_schema.sequences;").map {|x| x['sequence_name']}
seqs.each do |s|
ActiveRecord::Base.connection.execute("SELECT SETVAL('public.#{s}', COALESCE(MAX(id), 1) ) FROM public.#{s.gsub("_id_seq", "")};")
end
@aablinov
aablinov / image.rb
Created May 10, 2021 08:38
OpenGraph image generation via libvips
# frozen_string_literal: true
require 'vips'
module Superdocs
module Opengraph
class Image
attr_reader :elements, :canvas, :borders, :canvas_color
def initialize(width, height, color: '#ffffff')
@aablinov
aablinov / lib_vips_install.sh
Last active May 10, 2021 08:16
lib_vips_install.sh
sudo apt-get install fonts-open-sans devscripts libfftw3-dev libmagickwand-dev libopenexr-dev liborc-0.4-0 gobject-introspection libgsf-1-dev libglib2.0-dev liborc-0.4-dev automake libtool swig gtk-doc-tools libpango1.0-dev -y
git clone https://github.com/libvips/libvips.git
cd libvips && ./autogen.sh && make && sudo make install
ldconfig -v
@aablinov
aablinov / opengraph_image_v1.rb
Created May 10, 2021 07:55
OpenGraph Image v1
def create_og_image_preview(path, color: '#5168ec', message: )
unless File.exist?(path)
rgb = color.match(/#(..)(..)(..)/)[1..3].map{|x| x.hex}
im = Vips::Image.black(1200, 630).ifthenelse([0,0,0], rgb)
text = Vips::Image.text message, width: im.width, dpi: 400, font: 'sans bold'
text = text.gravity :centre, im.width, im.height
overlay = (text.new_from_image [255, 255, 255]).copy interpretation: :srgb
overlay = overlay.bandjoin text
@aablinov
aablinov / remove_file.rb
Created October 26, 2020 08:21 — forked from gjtorikian/remove_file.rb
How to remove a file from a subdirectory using the GitHub API v3
#!/usr/bin/env ruby
require 'octokit'
# !!! DO NOT EVER USE HARD-CODED VALUES IN A REAL APP !!!
login = ENV['GH_LOGIN']
password = ENV['GH_LOGIN_PASSWORD']
repo = "gjtorikian/crud-test"
master = client.ref(repo, "heads/master")
# gem https://github.com/AaronLasseigne/active_interaction
module Excursion
module Services
class NewUser < ActiveInteraction::Base
string :email
def execute
user = User.create(email: email)
if user.persisted?
### DigitalOcean Ubuntu 18.04 x64 + Rails 5 + Nginx + Unicorn + PostgreSQL9.6 + Capistrano 3
SSH into Root
$ ssh [email protected]
Change Root Password
$ passwd