This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this is just a dirty hack to play an mp3 over a network, need netcat and mplayer | |
# on the sending machine (replace localhost with ip): | |
nc localhost 1234 < x.mp3 | |
# on the playing machine: | |
nc -l -p 1234 | mplayer - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This contains various implementations of SQL functions in python | |
The two functions are not built for the same context | |
""" | |
def hash_join(table1, index1, table2, index2): | |
""" | |
Perform a sql like join operation on two dicts, on the specified indexes | |
""" | |
from collections import defaultdict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
#log memory each minute | |
while true; do | |
dt=`date` | |
mem=`cat /proc/meminfo | grep -E "MemFree"` | |
mem2=`cat /proc/meminfo | grep -E "MemAvailable"` | |
echo -e "$dt \t $mem \t $mem2" | tee -a memlog.txt | |
sleep 60 | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy.ext.declarative import declarative_base | |
""" | |
This gist demonstrates ways to retrieve foreign keys in an SQLAlchemy database schema. | |
""" | |
Base = declarative_base() | |
metadata = Base.metadata | |
# then you must populate schema |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8; mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- | |
# vim: fileencoding=utf-8 tabstop=4 expandtab shiftwidth=4 | |
"""User Access Control for Microsoft Windows Vista and higher. This is | |
only for the Windows platform. | |
This will relaunch either the current script - with all the same command | |
line parameters - or else you can provide a different script/program to | |
run. If the current user doesn't normally have admin rights, he'll be |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import win32serviceutil | |
import win32service | |
import win32event | |
import servicemanager | |
import socket | |
import time | |
import logging | |
logging.basicConfig( | |
filename = 'c:\\Temp\\hello-service.log', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# identify all files larger that 1 GB | |
find / -xdev -type f -size +1G -exec ls -lah {} \; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
def reduce2(func, ls): | |
if len(ls) == 1: | |
return ls[0] | |
return func(reduce2(func, ls[:-1]), ls[-1]) | |
# test | |
testset = [1, 2, 3, 4, 5] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
split_fields = lambda addr: [int(f) for f in addr.split(".")] | |
def check_subnet(prefix_addr: str, prefix_length: int, to_check: str): | |
""" | |
Determine if the IPv4 address to_check is within the given subnet | |
:param prefix_addr: address prefix as shown in CIDR notation | |
:param prefix_length: the number of bits in the network section |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pip._internal import main | |
pkg = "numpy" # example | |
main(['install', pkg]) |