Skip to content

Instantly share code, notes, and snippets.

View mikofski's full-sized avatar
😎
Solving solar

Mark Mikofski mikofski

😎
Solving solar
View GitHub Profile
@mikofski
mikofski / scrolled_lists.py
Created June 25, 2013 21:35
scroll 2 listboxes in paned windows
#! /usr/bin/env python
from Tkinter import *
from ttk import *
import calendar
root = Tk()
master = Frame(root)
@mikofski
mikofski / scrolled_canvas.py
Last active December 19, 2015 05:49
ttk widgets
from Tkinter import Canvas, GROOVE, BOTH, X, Y, YES, RIGHT, LEFT, W
from ttk import Frame, Scrollbar, Checkbutton
import logging
import tkMessageBox
class ScrolledCanvas(Frame):
"""
A scrolling canvas of frames with checkboxes.
"""
import ast
import math
SAFE_FX = {
'exp': math.exp,
}
SAFE_NODES = set(
(ast.Expression,
ast.Num,
import ast
allowed_functions = set([
#math library
'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh',
'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf',
'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod',
'frexp', 'fsum', 'gamma', 'hypot', 'isinf', 'isnan', 'ldexp',
'lgamma', 'log', 'log10', 'log1p', 'modf', 'pi', 'pow', 'radians',
'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc',
@mikofski
mikofski / topological_sort.py
Created August 18, 2013 17:08
topological sorting methods
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
`Topological sort by Kahn (1962) on Wikipedia
<http://en.wikipedia.org/wiki/Topological_sorting>`_
L ← Empty list that will contain the sorted elements
S ← Set of all nodes with no incoming edges
while S is non-empty do
remove a node n from S
@mikofski
mikofski / air.m
Created August 29, 2013 18:26
Thermal-physical properties of air at 1 atm between temperatures of 200 K and 350 K.
classdef air < handle
% AIR Thermal-physical properties of air at 1 atm between temperatures
% of 200 K and 350 K.
% Mark Mikofski
% Version 1-0, 2010-10-29
properties
description = 'air at 1 atm between 200 and 350 K'
end
properties
Temp
@mikofski
mikofski / OpenSSH2JavaKeyPairDemo.java
Last active December 26, 2015 03:39
Demonstration of SSH -> Java KeyPair Conversion from SO (http://stackoverflow.com/a/19435226/1020470) by @erickson
static KeyPair OpenSSH2JavaKeyPairDemo(InputStream pub, InputStream pvt)
throws IOException, GeneralSecurityException
{
KeyFactory f = KeyFactory.getInstance("RSA");
RSAPublicKeySpec pubspec = decodeRSAPublicSSH(readAllBase64Bytes(pub));
RSAPrivateCrtKeySpec pvtspec = decodeRSAPrivatePKCS1(readAllBase64Bytes(pvt));
return new KeyPair(f.generatePublic(pubspec), f.generatePrivate(pvtspec));
}
@mikofski
mikofski / help_server.py
Created January 10, 2014 00:37
simple non-blocking asynchronous web server to serve help docs since sphinx search doesn't work on google chrome otherwise
# -*- coding: utf-8 -*-
"""
Starts the help server so that Sphinx search works even in Google Chrome.
"""
import SimpleHTTPServer
import SocketServer
from threading import Thread
from Queue import Queue
@mikofski
mikofski / JSONFormatter.py
Created January 11, 2014 05:17
pygments JSONFormatter
from pygments.lexers import MatlabLexer
from pygments.formatter import Formatter
from pygments.token import STANDARD_TYPES
from pygments import highlight
class JSONFormatter(Formatter):
def format(self, tokensource, outfile):
tokensource = [{STANDARD_TYPES[k]: v} for k, v in tokensource]
json.dump(tokensource, outfile)
@mikofski
mikofski / darwin.mk
Last active July 10, 2016 04:40
overloading ccompiler to build dylibs for mac osx with xcode
#define macros
SOLPOSAM = libsolposAM.dylib
SOLPOSAM_LIB = solposAM
SPECTRL2 = libspectrl2.dylib
SPECTEST = spectest
STEST00 = stest00
SRC_DIR = src
BUILD_DIR = build