Skip to content

Instantly share code, notes, and snippets.

View thengineer's full-sized avatar

thengineer

  • some global corporation
  • somewhere between the shore and the mountains
View GitHub Profile
! outlook
outlook.live.com##._1j7WZ-n7dxhS9AQV-FL8U7 > ._2qPmszDwBfYpF7PO9Mn3KN
! --- SX cleanups ------------------------------------
###hot-network-questions
##.s-hero--container
using System;
using System.Collections.Generic;
using System.Linq;
using Foundation;
using UIKit;
using XLabs.Ioc;
using XLabs.Platform.Device;
using XLabs.Forms;
@thengineer
thengineer / significant_number_round.py
Last active August 29, 2015 13:59
round a float to a defined number of significant digits
def round_significant(number, nsig):
from math import log10
if number != 0:
lg10 = int((log10(abs(number))))
if abs(number) < 1:
lg10 -= 1
ndig = nsig - lg10 - 1
rded = round(number, ndig)
if ndig <= 0:
rded = int(rded)
@thengineer
thengineer / strides_2d.py
Last active April 25, 2016 02:34
rolling statistics for numpy 2D arrays with strides
import numpy as np
from numpy.lib.stride_tricks import as_strided
#
# 1-D sample
# based on: http://www.rigtorp.se/2011/01/01/rolling-statistics-numpy.html
def strides_1d(a, r):
ax = np.zeros(shape=(a.shape[0]+2*r))#, dtype=np.uint8) # `a` extended
ax[:] = np.nan
@thengineer
thengineer / autocadblockreader.py
Created October 25, 2013 16:27
AutoCAD automation via python and win32com: read all attributes from BlockReferences
import win32com.client
acad = win32com.client.Dispatch("AutoCAD.Application")
doc = acad.ActiveDocument # Document object
# iterate trough all objects (entities) in the currently opened drawing
# and if its a BlockReference, display its attributes and some other things.
for entity in acad.ActiveDocument.ModelSpace:
name = entity.EntityName