Skip to content

Instantly share code, notes, and snippets.

View njanakiev's full-sized avatar

Nikolai njanakiev

View GitHub Profile
@njanakiev
njanakiev / combine_images.py
Created March 30, 2017 08:40
Resize and combine images to an n by n grid with ImageMagick commands: morgify and convert
import os
import shutil
# Settings
n, m = 6, 6
input_folder = "input"
tmp_folder = "tmp"
output_image = "combined_image.png"
size = 300
@njanakiev
njanakiev / fractal.py
Created November 9, 2017 12:23
Mandelbrot and Julia Set with PIL
import numpy as np
from PIL import Image
output_image = 'fractal.png'
def evalMandelbrot(x, y, n=20):
c = x + 1j*y
out, count = 0, 0
for i in range(n):
if abs(out) <= 2:
@njanakiev
njanakiev / imagemagick-commands.md
Last active April 13, 2018 08:47
Imagemagick Commands

Imagemagick Commands

Resize image (e.g. to size 800x800)

convert -resize 800x800 -quality 100 in.png out.png

Join images horizontally

convert +append *.png out.png
@njanakiev
njanakiev / ffmpeg-commands.md
Created January 3, 2018 11:34
FFmpeg Commands

FFmpeg Commands

This is a collection of useful ffmpeg commands. Detailed description of the commands can be found in the documentation

Extract frames from video, one frame per second, where -r sets the desired framerate (e.g. -r 10 extracts 10 frames per second).

ffmpeg -i movie.mp4 -r 1 frames\\frame_%%04d.png

Create Instagram compatible video from frames

@njanakiev
njanakiev / watchdog_example.py
Created February 19, 2018 11:10
Simple example of monitoring file system events in Python with the watchdog module
import sys
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
class EventHandler(FileSystemEventHandler):
def on_any_event(self, event):
print("EVENT")
print(event.event_type)
print(event.src_path)
print()
@njanakiev
njanakiev / GDAL_OGR_recipes.md
Last active March 9, 2021 19:56
GDAL and OGR command recipes

GDAL and OGR Recipes

Convert Shapefile to CSV file

ogr2ogr -f "CSV" output.csv input.shp -lco GEOMETRY=AS_XY

Convert Shapefile to GeoJSON

ogr2ogr -f "GeoJSON" output.json input.shp
@njanakiev
njanakiev / overpass_api_recipes.md
Last active October 8, 2024 14:57
Overpass API Recipes

Overpass API Recipes

Get all the peaks in the dolomites

area
  [place=region]
  ["region:type"="mountain_area"]
  ["name:en"="Dolomites"];
out body;
@njanakiev
njanakiev / jupyter-word-count.py
Created January 15, 2019 13:09
Jupyter Word Count
import nbformat
filepath = 'notebbook.ipynb'
with open(filepath, 'r', encoding='utf-8') as f:
nb = nbformat.read(f, as_version=4)
wc_markdown, wc_heading, wc_code = 0, 0, 0
for cell in nb.cells:
if cell.cell_type == "markdown":
wc_markdown += len(cell['source'].replace('#', '').lstrip().split(' '))
@njanakiev
njanakiev / load_rescuetime_data.py
Created February 23, 2019 13:08
Load and merge data from Rescuetime
import requests
import datetime
import pandas as pd
import json
import time
# Read rescuetime key
with open('key.txt', 'r') as f:
key = f.read()
@njanakiev
njanakiev / concat_images.py
Created March 28, 2019 15:32
Concat images in a matrix grid with Python and PIL
import os
import random
from PIL import Image, ImageOps
def concat_images(image_paths, size, shape=None):
# Open images and resize them
width, height = size
images = map(Image.open, image_paths)
images = [ImageOps.fit(image, size, Image.ANTIALIAS)