Skip to content

Instantly share code, notes, and snippets.

View dsalaj's full-sized avatar
🐙

Darjan Salaj dsalaj

🐙
View GitHub Profile
@dsalaj
dsalaj / extract_frames.py
Created February 1, 2019 09:24
Extract and downsample frames from video to numpy array
import cv2
import numpy as np
print(cv2.__version__)
vidcap = cv2.VideoCapture('vid.mp4')
success,image = vidcap.read()
count = 0
success = True
frames = []
while success:
frames.append(image)
@dsalaj
dsalaj / juwels_cheatsheet.md
Last active February 5, 2024 11:25
JUWELS cheatsheet

local .ssh/config contents

Host juwels
    HostName juwels.fz-juelich.de
    User salaj1
    IdentityFile ~/.ssh/id_rsa_juwels.pub

To connect simply ssh juwels.

juwels

@dsalaj
dsalaj / grammar.py
Created December 16, 2018 23:18
Reber grammar generation and validation
import nltk
from nltk.parse.generate import generate
# Define Reber grammar
# http://christianherta.de/lehre/dataScience/machineLearning/neuralNetworks/pics/embeddedReberGrammar.png
grammarStr = '''
START -> 'B' 'T' REBER 'T' 'E' | 'B' 'P' REBER 'P' 'E'
REBER -> 'B' E1
E1 -> 'T' E2 | 'P' E3
@dsalaj
dsalaj / glider.py
Last active November 23, 2018 12:15
Answer to a question on stackoverflow
#!/usr/bin/python
#!/usr/bin/python
# Answer to this:
# https://stackoverflow.com/questions/53442614/conways-game-of-life-in-python-3-with-matplotlib-problem-with-displaying-a-fo#53442614
# call with: python3 cgl.py 10 500 1 1
import os
import argparse
import numpy as np
@dsalaj
dsalaj / get_results.py
Last active January 22, 2019 08:26
Traverse directory for json files with results and print some value from dict
import json
import sys
import os
folders = []
files = []
RESULT_KEY = 'test_per'
data = {
'subdir1': [],
'subdir2': [],
@dsalaj
dsalaj / resize.py
Created August 19, 2017 10:25
Resize and pad images
import os
import cv2
dir_files = os.listdir('raw_data')
extensions = [filename[-4:] for filename in dir_files]
for ext in extensions:
assert ext == '.jpg'
max_width = 0