Skip to content

Instantly share code, notes, and snippets.

@harsgak
harsgak / xtractmp3.py
Last active May 12, 2018 17:24
Input music videos in format ["Artist - Song.ext"] and export mp3 to directories categorized by artist
# coding: utf-8
# author: harsgak
# intent: input music videos in format ["Artist - Song.ext"] and export mp3 to dirs categorised by artist
import pathlib
import ffmpeg #pip install ffmpeg-python
# Get titles
path_current = pathlib.Path('.')
path_mv = path_current.joinpath('Music Videos')
@harsgak
harsgak / nearest_neighbour_network.py
Created April 13, 2018 12:20
Generate the nearest neighbor network from given internode distances (defined on some metric)
# coding: utf-8
# # Nearest Neighbour Network
# Generate the nearest neighbor network from given internode distances (defined on some metric)
# In[1]:
import networkx as nx
def draw_nxgraph3D(G, pos=None, figtitle=None, ax=None, **kwargs):
#pos is an Nx3 array (3D positions of sorted nodes)
#layout is a dict with node keys and pos-vector(3D) values
import numpy as np
if pos is None:
#generate some layout
import networkx as nx
layout = nx.spring_layout(G, dim=3)
pos = np.array([layout[i] for i in sorted(G.nodes())])
if pos.shape[1]==2:
import requests
from collections import deque
import logging
FORMAT = '%(asctime)-15s %(funcName)s %(levelname)s %(message)s'
logging.basicConfig(format=FORMAT,level=logging.INFO, datefmt='%Y-%m-%d %H:%M:%S')
def pathFinder(s = 'source', t = 'sink', filters = []) :
Q=deque([])
@harsgak
harsgak / shortestpathBFS.py
Created October 17, 2017 18:18
Shortest path from s to t
from collections import deque
s="source"
t="sink"
Q=deque([])
Q.append(s)
while len(q) != 0:
v=Q.popleft()
for w in getlinks(v):