Skip to content

Instantly share code, notes, and snippets.

@gcetusic
gcetusic / sort_data.py
Created December 6, 2022 09:11
Sort lists/dict with mixed object types
def sort_data(data, ignored_keys=None):
"""
Sort members of lists and dictionaries, regardless of type
"""
if ignored_keys is None:
ignored_keys = []
if isinstance(data, dict):
return {k: sort_data(data[k], ignored_keys=ignored_keys) for k in sorted(data)}
@gcetusic
gcetusic / ufw_plex.md
Created December 12, 2021 10:06 — forked from nmaggioni/ufw_plex.md
Plex Media Server UFW rule

/etc/ufw/applications.d/plexmediaserver

[plexmediaserver]
title=Plex Media Server (Standard)
description=The Plex Media Server
ports=32400/tcp|3005/tcp|5353/udp|8324/tcp|32410:32414/udp

[plexmediaserver-dlna]
title=Plex Media Server (DLNA)
description=The Plex Media Server (additional DLNA capability only)
@gcetusic
gcetusic / codedeploy_deploy.py
Created April 8, 2020 15:04 — forked from djravine/codedeploy_deploy.py
codedeploy_deploy.py - Implement exponential back off to reduce chance rate limiting and increase number of retries
# Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file
# except in compliance with the License. A copy of the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is distributed on an "AS IS"
# BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under the License.
@gcetusic
gcetusic / data.md
Created February 28, 2020 17:44 — forked from jordansissel/data.md
Compression on large JSON file

The Data

Compression

  • Original: 708MB
  • xz -3: 70MB, 5:41.02 (2.07 mb/sec - 10:1 ratio)
  • bzip2 -3: 74MB, 4:39.11 (2.53 mb/sec - 9.5:1 ratio)
  • gzip -3: 103MB: 0:15.15 (46.73 mb/sec - 6.87:1 ratio)
  • lzop -3: 146MB, 0:06.53 (108.42 mb/sec - 4.85:1 ratio)
import xmldataset
import pandas as pd
import argparse
import time
import re
import os
from datetime import datetime
from multiprocessing import Pool
from glob import glob
@gcetusic
gcetusic / aiohttp_uptime_http_server.py
Created June 23, 2018 08:21 — forked from jbn/aiohttp_uptime_http_server.py
An example showing how to stream HTML in a aiohttp server.
import asyncio
from aiohttp import web
import subprocess
async def uptime_handler(request):
# http://HOST:PORT/?interval=90
interval = int(request.GET.get('interval', 1))
# Without the Content-Type, most (all?) browsers will not render
import xmldataset
import pandas as pd
import re
import os
from datetime import datetime
# TODO: make this dynamic in the script that iterates over files in folders
input_file = 'Downloads/zade_30_cat_20180306_000530.xml'
account = '1009'
#################
@gcetusic
gcetusic / longestpath.py
Created August 29, 2017 07:24 — forked from baoilleach/longestpath.py
How to find the longest path in a directed acyclic graph
from collections import defaultdict
def toposort(graph):
"""http://code.activestate.com/recipes/578272-topological-sort/
Dependencies are expressed as a dictionary whose keys are items
and whose values are a set of dependent items. Output is a list of
sets in topological order. The first set consists of items with no
dependences, each subsequent set consists of items that depend upon
items in the preceeding sets.
@gcetusic
gcetusic / tree.md
Created May 31, 2017 07:40 — forked from hrldcpr/tree.md
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

@gcetusic
gcetusic / weasyprint_complex_headers.py
Created May 24, 2017 12:18 — forked from pikhovkin/weasyprint_complex_headers.py
Repeat on each page of complex headers (eg, tables) except the first page
# coding: utf-8
from weasyprint import HTML, CSS
def get_page_body(boxes):
for box in boxes:
if box.element_tag == 'body':
return box