Skip to content

Instantly share code, notes, and snippets.

View n1chre's full-sized avatar
💯

Filip Hrenić n1chre

💯
View GitHub Profile
@n1chre
n1chre / download.py
Last active August 21, 2018 03:35
Download the first song from youtube by searching for "artist - song"
#!/usr/bin/env python3
import fileinput
import os
import random
import re
import string
import subprocess
def rand_str(k=12):
@n1chre
n1chre / artwork.sh
Last active July 13, 2018 05:23
Add artwork to songs by using the thumbnail from the first video on youtube
#!/usr/bin/env bash
ROOT_DIR='/directory/with/artist/album/song' # root directory which will be traversed
ALBUM='Unknown Album' # only set artwork for songs in given album (for each artist)
pushd "$(pwd)"
cd "$ROOT_DIR"
for artist in *; do
cd "$artist"
if [ -d "$ALBUM" ]; then
@n1chre
n1chre / file_test.md
Last active June 29, 2018 17:13
Bash stuff: parameter substitution, expansion and manipulation operators; file test operators
Test Description
-e file exists
-f file is a regular file (not a directory or device file)
-s file is not zero size
-d file is a directory
-b file is a block device
-c file is a character device
-p file is a pipe
-L file is a symbolic link
@n1chre
n1chre / timestamp.py
Created June 28, 2018 16:56
Transform a timestamp into int (microseconds precision)
import time
import datetime
timestamp_format = '%Y-%m-%d %H:%M:%S,%f' # 2018-06-28 13:34:04,776
epoch = datetime.datetime.utcfromtimestamp(0) # timestamp at 1970-01-01 00:00:00
def timestamp_to_int(ts):
dt = datetime.datetime.strptime(ts, timestamp_format)
return int((dt-epoch).total_seconds()*1000)
@n1chre
n1chre / bsfile.py
Last active June 28, 2018 16:51
Binary search a line in a file having all lines formatted the same way
from __future__ import print_function
from time import time
class BSFile(object):
def __init__(self, filename, key_func):
self.filename = filename
self.key_func = key_func
def find(self, key):
'''

Shell initialization files are ways to persist common shell configuration, such as:

  • $PATH and other environment variables
  • shell prompt
  • shell tab-completion
  • aliases, functions
  • key bindings
@n1chre
n1chre / emoji.txt
Created October 14, 2017 11:25
Unicode emojis
ʘ‿ʘ
Innocent face
ಠ_ಠ
Reddit disapproval face
(╯°□°)╯︵ ┻━┻
Table Flip / Flipping Table
┬─┬ ノ( ゜-゜ノ)
@n1chre
n1chre / tmux.md
Created October 1, 2017 15:23 — forked from Bekbolatov/tmux.md
Clean tmux cheat-sheet

Clean tmux cheat-sheet

By resources

sessions

list-sessions        ls         -- List sessions managed by server
new-session          new        -- Create a new session
@n1chre
n1chre / tmux.cheat
Created October 1, 2017 15:12 — forked from afair/tmux.cheat
Tmux Quick Reference & Cheat sheet - 2 column format for less scrolling!
========================================== ==========================================
TMUX COMMAND WINDOW (TAB)
========================================== ==========================================
List tmux ls List ^b w
New -s <session> Create ^b c
Attach att -t <session> Rename ^b , <name>
Rename rename-session -t <old> <new> Last ^b l (lower-L)
Kill kill-session -t <session> Close ^b &
package hrucc;
import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
/**
* This class should be used when some object is producing stuff for some consumer and consume() is