Skip to content

Instantly share code, notes, and snippets.

View KoStard's full-sized avatar
👾

Ruben Kostandyan KoStard

👾
View GitHub Profile
@KoStard
KoStard / vlc-play-videos-with-external-audio-file.sh
Created December 29, 2020 22:12
How to specify and use external audio track for videos with VLC CLI
# --audio-track= using 1 here, as my video files have audio, but in different language, so after adding the second audio, it's index will become 1 (it's 0 based)
vlc --audio-track=1 \
video_file_path_1 \
:input-slave=external_audio_path_1 \
video_file_path_2 \
:input-slave=external_audio_path_2
#... You can continue this command for as many files you want
# This way you can start VLC with all your files already linked and easily move to next/previous episodes, instead of manually doing "Advanced Open File", specifying the external audio file and changing the track to the new one.
import heapq
class Node: # Trie node
def __init__(self, val=""):
self.mem = [None] * 26
self.count = 0
self.val = val
def register_word(root, word):
node = root
@KoStard
KoStard / lfu_cache.py
Created July 19, 2019 13:26
Implementing LFU Cache with linked lists of linked lists.
class EnhancedLinkedListNode:
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c
self.next = None
self.prev = None
def remove(self):
if self.prev:
@KoStard
KoStard / lfu_cache.py
Created July 19, 2019 13:26
Implementing LFU Cache with linked lists of linked lists.
class EnhancedLinkedListNode:
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c
self.next = None
self.prev = None
def remove(self):
if self.prev:
@KoStard
KoStard / avl_tree.py
Created July 18, 2019 15:52
Implemented AVL tree.
"""
Difference between height of left and right childs has to be <=1
"""
class AVLTreeNode:
def __init__(self, val, parent=None):
self.val = val
self.left = None
self.right = None
@KoStard
KoStard / sort_algorithms.py
Created July 18, 2019 12:54
Selection sort, Insertion sort, Shell sort, Merge sort, Quick sort (+in-place), Radix sort
def selection_sort(arr):
"""
Is named selection sort, because we are selecting smallest element each time and putting it as next
Time Complexity - O(N**2)
Space Complexity - O(1)
12.471 seconds for 10_000 numbers
"""
t = mn = 0
for i in range(len(arr)):
mn = i
@KoStard
KoStard / finder.py
Created July 18, 2019 04:32
Checker is a base class for all checkers - it makes all children classes to have same methods.
class Checker:
@staticmethod
def is_this_type(expr):
raise NotImplementedError()
def does_match(self, value):
raise NotImplementedError()
class NameChecker(Checker):
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class BSTIterator:
def __init__(self, root: TreeNode):
@KoStard
KoStard / .xonshrc
Created December 15, 2018 09:29
Start command from new line in xonsh.
$PROMPT='{env_name:{} }{BOLD_GREEN}{user}@{hostname}{BOLD_BLUE} {cwd}{branch_color}{curr_branch: {}}{NO_COLOR} {BOLD_BLUE}\n{prompt_end}{NO_COLOR} '
@KoStard
KoStard / NergativeImage.java
Created July 14, 2018 09:44
Make negative copy of image with java.
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class NergativeImage {
public static BufferedImage saveImageFromPixels(int[][][] pixels, String name, String format, int width, int height, int type) {
BufferedImage temp = new BufferedImage(width, height, type);