Skip to content

Instantly share code, notes, and snippets.

View njanakiev's full-sized avatar

Nikolai njanakiev

View GitHub Profile
@njanakiev
njanakiev / natural_earth_voronoi.md
Last active August 4, 2020 08:58
Voronoi Diagram of the World with Capitals as Centroids
@njanakiev
njanakiev / download_commons_categories.py
Created June 15, 2019 10:55
Download images from commons gallery
import os
import requests
import mwclient
import pandas as pd
category_names = ['Computer_hardware', 'Data_centers', 'Servers',
'Control_rooms', 'Floppy_disk_drives', 'Hard_disks',
'Automobile_dashboards', 'Old_maps', 'Laboratory_equipment']
@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)
@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 / 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 / overpass_api_recipes.md
Last active July 30, 2023 19:24
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 / 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 / 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 / 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 / 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