Skip to content

Instantly share code, notes, and snippets.

View deemytch's full-sized avatar

Димыч deemytch

  • Одесса
View GitHub Profile
@deemytch
deemytch / refresh-collaction-ver.rb
Created August 17, 2024 22:22
sometimes postgres wants refresh collation version in databases
#!/usr/bin/ruby
`psql -U postgres -t -l`.
split(/\n+/).
collect{|l| l.split(/\s+\|\s+/)[0].chomp().strip() }.
filter{|l| (! l.nil?) && l !~ /^\s*$/ }.
each{|db| `psql -U postgres -c 'ALTER DATABASE "#{db}" REFRESH COLLATION VERSION;'` }
@deemytch
deemytch / http-take.rb
Created July 28, 2024 08:07
One-shot http server
#!/usr/bin/ruby
require 'socket'
(listen_addr, listen_port, single_file) = ARGV;
server = TCPServer.new(listen_addr, listen_port)
client = server.accept
req_file = client.gets.split(" ")[1]
if single_file == req_file
client.puts <<~ERESP
HTTP/1.0 200 OK\r
connection: close\r
@deemytch
deemytch / http-take.pl
Last active July 25, 2024 12:01
One-shot http server
#!/usr/bin/perl
# taken here: https://github.com/elimirks/simpleHTTP
use IO::Socket;
# Command-line args IP PORT FULL-FILE-PATH
# request must be as http://localhost:8181/FULL-FILE-PATH
($listen_addr, $listen_port, $singlefile) = @ARGV;
(-r $singlefile) || die "File '$singlefile' not found.";
my $sock = new IO::Socket::INET(
@deemytch
deemytch / remote-sync.sh
Created July 5, 2024 10:57
autoupdate remote code when doing remote debug
# BASE={$BASEDIR:-/home/ikben/eenproject} ## root folder for project
fsnotifywait -qPmr -e 'moved_to,create' --format '%w%f%0' --no-newline ${BASE} | while IFS= read -r -d '' file
do
# here goes any code you want
host="developpeur@127.1.1.100"
rsync -uavz --del lib mix.* "${host}:eenproject/"
done
@deemytch
deemytch / share_pid.ex
Created April 9, 2024 18:53
share PID from one node's shell to another, from iex to iex
# node0@ip1
defmodule Pong do
def pong() do
receive do
msg ->
IO.inspect(msg, label: "сообщение")
pong()
after 900000 -> IO.puts "timeout"
end
end
@deemytch
deemytch / timeserver.rb
Last active October 6, 2023 02:40
Simplest http server on ruby
# https://www.mikeperham.com/2023/09/11/ruby-http-server-from-scratch/
# №1
class TimeServer < GServer
def initialize(port=10001, *args)
super(port, *args)
end
def serve(io)
io.puts(Time.now.to_i)
end
@deemytch
deemytch / archlinux keyring reinit.sh
Created September 24, 2023 19:20
archlinux ... is unknown trust ...
rm -r /etc/pacman.d/gnupg
pacman-key --init
# pacman-key --populate archlinux
pacman-key --populate archlinuxarm manjaro-arm
pacman -S archlinux-keyring
@deemytch
deemytch / update_collation.sh
Last active August 15, 2023 20:41
несовпадение версии для правила сортировки в базе данных "postgres"; ALTER DATABASE postgres REFRESH COLLATION VERSION
psql -U postgres -c 'SELECT d.datname as "Name" FROM pg_catalog.pg_database d order by 1;' | \
ruby -nawe 'next if /^\s*$|^\s*Name|^\s*-{3,}|строки/; puts "ALTER DATABASE \"#{$_.chomp.strip}\" REFRESH COLLATION VERSION;"' | \
psql -U postgres
@deemytch
deemytch / jason_implementations.ex
Created July 19, 2023 10:40
Jason implementation for tuple encoding
defimpl Jason.Encoder, for: [Tuple] do
def encode({k, v}, opts), do: Jason.Encode.map(%{k => v}, opts)
def encode(tuple, opts) do
[k|v] = :erlang.tuple_to_list(tuple)
encode({k, v}, opts)
end
end
@deemytch
deemytch / config.yaml
Last active April 20, 2023 14:02
GitLab to Gitea an pair hunderds projects moving
gitea:
username: username
token: usertoken
domain: gitea.your.domain
repo_owner: Organisation or your username
gitlab:
domain: gitlab.com
token: usertoken
group_id: an number
# here go the list of repo names, which are already here