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 / solarPosition.m
Last active March 20, 2025 02:40
solar position calculator
function [angles,projection] = solarPosition(datetime,latitude,longitude,time_zone,rotation,dst)
%SOLARPOSITION Calculate solar position using most basic algorithm
% This is the most basic algorithm. It is documented in Seinfeld &
% Pandis, Duffie & Beckman and Wikipedia.
%
% [ANGLES,PROJECTION] = SOLARPOSITION(DATE,TIME,LATITUDE,LONGITUDE,TIME_ZONE)
% returns ZENITH & AZIMUTH for all DATE & TIME pairs at LATITUDE, LONGITUDE.
% ANGLES = [ZENITH,AZIMUTH] and PROJECTION = [PHI_X, PHI_Y]
% PHI_X is projection on x-z plane & PHI_Y is projection on y-z plane.
% DATETIME can be string, vector [YEAR, MONTH, DAY, HOURS, MINUTES, SECONDS],
@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 / vcvarsall.bat.patch
Last active April 9, 2017 20:40
Fix for vcvarsall.bat to build Python-2.7 extensions using v90 instead of sdk7
--- C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.txt
+++ C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat
@@ -16,23 +16,23 @@
goto :eof
:amd64
-if not exist "%~dp0bin\amd64\vcvarsamd64.bat" goto missing
-call "%~dp0bin\amd64\vcvarsamd64.bat"
+if not exist "%~dp0bin\vcvars64.bat" goto missing
+call "%~dp0bin\vcvars64.bat"
@mikofski
mikofski / django_service.py
Last active May 31, 2022 02:05
Start a Windows service to run the Django debug server - WARNING! not recommended for deployment!
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Attribution: Hijacked from tracservice.py by Florent Xicluna <[email protected]>
# http://trac-hacks.org/wiki/WindowsServiceScript
#
# To use this class, users must do the following:
# 1. Download and install the PyWin32all package
# (http://starship.python.net/crew/mhammond/win32/)
# 2. Edit the constants section with the proper information.
@mikofski
mikofski / Gaussian_elimination.py
Last active September 29, 2022 03:31
numpy scipy gaussian elimination using LU decomposition with pivoting
#! /usr/bin/env python
"""
Solve linear system using LU decomposition and Gaussian elimination
"""
import numpy as np
from scipy.linalg import lu, inv
def gausselim(A,B):
@mikofski
mikofski / excel_diff.py
Created July 15, 2014 20:31
diff of excel file in Git repository index and working copy
#! /usr/bin/env python
"""
diff of excel files
"""
from dulwich.repo import Repo # import Repo object from dulwich
import sys
import os
from openpyxl import load_workbook
@mikofski
mikofski / Django_view_utilities.py
Last active August 29, 2015 14:05
Django view utilities to add GET parameters to context and to use a Bootstrap navbar login template
from functools import wraps
from django.contrib.auth.views import login as auth_login
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse, HttpResponseRedirect, QueryDict
from django.core.urlresolvers import reverse, resolve
from django.template.response import TemplateResponse
def add_GET_to_context(*keys):
"""
Check view's URL GET query string for keys and add values to context data
@mikofski
mikofski / memcached_service.py
Created August 26, 2014 16:54
memcached service for windows
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Attribution: Hijacked from tracservice.py by Florent Xicluna <[email protected]>
# http://trac-hacks.org/wiki/WindowsServiceScript
#
# To use this class, users must do the following:
# 1. Download and install the PyWin32all package
# (http://starship.python.net/crew/mhammond/win32/)
# 2. Edit the constants section with the proper information.
@mikofski
mikofski / gen_toc.html
Last active August 29, 2015 14:06
generate table of contents
<html>
<head>
<!-- either head or body -->
<style type="text/css">
.toc_item {
color: green;
}
</style>
<!-- css class -->
</head>