Skip to content

Instantly share code, notes, and snippets.

View oprypin's full-sized avatar

Oleh Prypin oprypin

View GitHub Profile
@oprypin
oprypin / parraleln.cr
Last active March 5, 2021 02:23
Crystal parallel jobs from an array
def paralleln(items : Indexable(T), &block : T -> R) forall T, R
results = Array(R).new(items.size) { r = uninitialized R }
done = Channel(Exception?).new
items.each_with_index do |item, i|
spawn do
begin
results[i] = block.call(item)
rescue e
done.send e
#!/usr/bin/env python
import re
last_lines = lines = None
with open('/var/log/pacman.log') as log_file:
for line in log_file:
if re.search(r'\btransaction started\b', line):
lines = []
@oprypin
oprypin / instructions.md
Last active April 14, 2024 04:39
systemd user unit + timer example

Save these files as ~/.config/systemd/user/some-service-name.*

Run this now and after any modifications: systemctl --user daemon-reload

Try out the service (oneshot): systemctl --user start some-service-name

Check logs if something is wrong: journalctl -u --user-unit some-service-name

Start the timer after this user logs in: systemctl --user enable --now some-service-name.timer

diff --unified --recursive konversation-1.7.2/src/viewer/chatwindow.cpp konversation-1.7.2.new/src/viewer/chatwindow.cpp
--- konversation-1.7.2/src/viewer/chatwindow.cpp 2017-05-09 17:29:00.000000000 +0200
+++ konversation-1.7.2.new/src/viewer/chatwindow.cpp 2017-11-07 00:03:57.217338235 +0100
@@ -278,7 +278,15 @@
void ChatWindow::append(const QString& nickname, const QString& message, const QHash<QString, QString> &messageTags, const QString& label)
{
if(!textView) return;
- textView->append(nickname, message, messageTags, label);
+ QString nickname_ = nickname;
+ QString message_ = message;
@oprypin
oprypin / check_passwords.cr
Last active January 17, 2019 20:56
Check your passwords against https://haveibeenpwned.com/Passwords
# Check your passwords against https://haveibeenpwned.com/Passwords
# Usage:
# crystal check_passwords.cr -- pwned-passwords-sha1-ordered-by-hash*.txt
# Enter your passwords one per line, then press Return twice. Or pipe them in.
require "digest/sha1"
passwords = Array(String).new
until (line = gets(chomp: true) || "").empty?
passwords << line
def key
STDIN.raw do |io|
loop do
buffer = Bytes.new(3)
bytes_read = io.read(buffer)
if bytes_read > 0
return String.new(buffer[0, bytes_read])
end
end
end
@oprypin
oprypin / unity_versions.sh
Created July 18, 2017 22:05
Find out engine versions of all your Unity games on Linux
cd ~/.steam/steam/steamapps/common
for d in *; do
for f in "$d"/*; do
file "$f" | grep -q 'ELF ' &&
strings "$f" | grep -q 'UnityPlayer/' &&
echo "$(strings "$f" | grep -P -m1 -o '(?<=UnityPlayer/)[^ ]+') $d" &&
break
done
done | sort -V
[General]
Description=Applications
Opacity=1
Wallpaper=
[Background]
Color=255,255,255
[BackgroundIntense]
Color=220,255,220
@oprypin
oprypin / notice.md
Last active March 17, 2018 23:54
Shenzhen I/O solitaire solver bot