Skip to content

Instantly share code, notes, and snippets.

@NapalmHorn
NapalmHorn / r2csv.py
Last active July 11, 2016 00:43
Keeps a csv of connection counts on openwrt router, requires conntrack
#!/usr/bin/env python2
csv_file = "/tmp/conn_log.csv"
#imports
import collections
import re
import subprocess
import os.path
import datetime
@NapalmHorn
NapalmHorn / python_syntax_check.lua
Last active January 3, 2016 01:37 — forked from rgieseke/python_syntax_check.lua
Textadept: Check Python syntax after saving.
events.connect('file_after_save',
function() -- shows all Python errors as annotations
if buffer:get_lexer() == 'python' then
local lfs = require 'lfs'
local buffer = buffer
buffer:annotation_clear_all()
local filepath = buffer.filename:iconv(_CHARSET, 'UTF-8')
local filedir, filename = '', filepath
if filepath:find('[/\\]') then
filedir, filename = filepath:match('^(.+[/\\])([^/\\]+)$')
@NapalmHorn
NapalmHorn / system-wide-PIL.sh
Created October 2, 2015 19:39
Even now that pil is deadish, this is installs it. Consider switching to something maintained.
sudo apt-get install python-dev libjpeg-dev libjpeg8-dev libpng3 libfreetype6-dev
sudo ln -s /usr/lib/i386-linux-gnu/libfreetype.so /usr/lib
sudo ln -s /usr/lib/i386-linux-gnu/libjpeg.so /usr/lib
sudo ln -s /usr/lib/i386-linux-gnu/libz.so /usr/lib
sudo pip install PIL --allow-unverified PIL --allow-all-external
@NapalmHorn
NapalmHorn / make_or_break_xlsx.py
Last active August 29, 2015 14:28
Code to "test" openpyxl pandas xlsx export
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import json
import numpy as np
import openpyxl
import pandas as pd
import string
import sys
@NapalmHorn
NapalmHorn / bi_funct_search.py
Created February 18, 2015 18:01
bi_funct_search
def bi_funct_search(f, x, low=0, high=None):
"""a text book binary search against a function
f is a strictly increasing function
x is a number in (low, high) and the domain of f
low is lower bound
high is upperbound (usually should not be omitted)
returns z such that f(z) = x or None if not found"""
if high is None:
high = x ** 2
while low < high:
@NapalmHorn
NapalmHorn / funct_cache
Created February 11, 2015 23:25
A very simple function cache, version agnostic python
def funct_cache(f, a, cache):
"""cashes function calls
f is the function, a is the parameter (can be complex data type)
cache is a dict"""
if not f in cache.keys():
cache[f] = {}
if not a in cache[f].keys():
cache[f][a] = f(a)
return cache[f][a]
@NapalmHorn
NapalmHorn / shum.sh
Last active August 29, 2015 14:09
SHell script Update Mint
#!/bin/bash
apt-get update
apt-get --assume-yes -q upgrade
@NapalmHorn
NapalmHorn / kill_tabs.py
Last active August 29, 2015 14:06
Removes tabes from a file and replaces them with 4x spaces.
# kill_tabs.py
import sys
def main():
"""Removes tabes from a file and replaces them with 4x spaces."""
if len(sys.argv) != 3:
print("Syntax:python[3] kill_tabs.py infile outfile")
sys.exit(0)
@NapalmHorn
NapalmHorn / makeChartGoogle3d
Last active August 29, 2015 14:04
Create a local html file with a google charts 3d pie chart and open it
import os.path # used by makeChart to create new unnamed charts
import webbrowser # used by makeChart to open the freshly created chart.
def makeChart(chartableDict):
"""Takes a dictionary with the subset of data that we want and makes a chart
Input : chartableDict which can have special entries
"control chart title" => the title of the new chart,
if absent or blank title will be 'chart title'
"control chart options" => the options to be sent to google charts,
if absent or blank defaults will be used
@NapalmHorn
NapalmHorn / boilerplateTester.py
Created July 30, 2014 03:53
A cut and paste (aka boilerplate) unit test
import unittest
# import fuctions for testing
#import testFunction from testFile # replace with the name of your file and fuctions
#to test simply run 'python boilerplatetester.py'
class boilerplateTestCase(unittest.TestCase):
def test_boilplate_good(self):
"""Does the test case return true when expected"""
expectedResult = True #expected result for good data
testCase = 'testcase' # good input that should yield expectedResult