Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am fikander on github.
  • I am fikander (https://keybase.io/fikander) on keybase.
  • I have a public key ASA6LWitkNHk3ihjJdTROmoYtIpFJfg2XrfAv_mu1jVu1wo

To claim this, I am signing this object:

@fikander
fikander / objectdict.py
Created May 13, 2017 22:31
Expose dict keys as object attributes (via dot notation)
class ObjectDict(dict):
"""Allows access to dict elements via dot notation
>>> o = ObjectDict.as_object(dict(a=1, b=2))
>>> o.a
1
>>> o.b
2
>>> o.b = 4
>>> o.b
@fikander
fikander / ktree.py
Created May 1, 2017 13:00
K-ary tree implemented with array, together with few traversal methods
# MIT License
#
# Copyright (c) 2017 Tomasz Kustrzynski
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@fikander
fikander / gist:ba20adc909ff6309e0343e2a04e19782
Created September 1, 2016 12:56 — forked from eduardocardoso/gist:82a629882ddb02ab3677
Script to delete exited containers and untagged/unused images from docker
#!/bin/bash
set -o errexit
echo "Removing exited docker containers..."
docker ps -a -f status=exited -q | xargs -r docker rm -v
echo "Removing dangling images..."
docker images --no-trunc -q -f dangling=true | xargs -r docker rmi
@fikander
fikander / shortest_reach.py
Last active July 29, 2016 13:06
Breadth First Search: Shortest Reach
#!/usr/bin/python
# https://www.hackerrank.com/challenges/bfsshortreach
import unittest
from collections import defaultdict, deque
def bfs_find_paths(graph, start, path=[]):
queue = deque([(start, [start])])
visited = set()
R, C, N = [int(i) for i in input().split()]
board = list()
for i in range(R):
board.append([0 if x == '.' else 1 for x in list(input())])
def print_board(board):
for row in board:
r = ''
for v in row:
@fikander
fikander / split_file.py
Created August 1, 2013 18:54
Split large files and cat them together. Usage: split_file.py (split|cat) [options] Example: split_file.py split -f large.avi -p out -s 52428800 split_file.py cat -f large.avi -i out.0 -i out.1 -i out.2
import sys
from optparse import OptionParser
def split_file(file, prefix, max_size, buffer=1024):
"""
file: the input file
prefix: prefix of the output files that will be created
max_size: maximum size of each created file in bytes
buffer: buffer size in bytes