This file contains hidden or 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 functools import wraps | |
def parse_keywords(func): | |
""" | |
decorates a python 2 function with the ability to parse list of key=value pair strings into a dict. | |
Dict is accessible through wrapper.arg_d attribute. | |
""" | |
@wraps(func) | |
def wrapper(*args, **kwargs): | |
wrapper.arg_d.update(dict([arg.split('=') for arg in args[0] if '=' in arg])) | |
result = func(*args, **kwargs) |
This file contains hidden or 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
Engineering is done with numbers Analysis without numbers is only an opinion | |
To design a spacecraft right takes an infinite amount of effort This is why it's a good idea to design them to operate when some things are wrong | |
Design is an iterative process The necessary number of iterations is one more than the number you have currently done This is true at any point in time | |
Your best design efforts will inevitably wind up being useless in the final design Learn to live with the disappointment | |
(Miller's Law) Three points determine a curve | |
(Mar's Law) Everything is linear if plotted log-log with a fat magic marker | |
At the start of any design effort, the person who most wants to be team leader is least likely to be capable of it | |
In nature, the optimum is almost always in the middle somewhere Distrust assertions that the optimum is at an extreme point | |
Not having all the information you need is never a satisfactory excuse for not starting the analysis | |
When in doubt, estimate In an emergency, guess But be su |
This file contains hidden or 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 ruby | |
########################### | |
# mike is a toy rake | |
class Task | |
@@tasks = {} | |
@action = nil | |
def initialize(n,&action) | |
@name = n | |
if ! @@tasks.include? n |
This file contains hidden or 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 | |
# Write a script which parses /var/log/messages and generates a CSV with two columns: minute, number_of_messages in sorted time order. | |
import re | |
from collections import defaultdict | |
msg_data = {} | |
for f in open('test.log'): | |
rec = f.split() | |
timestamp = ' '.join(rec[:3]) | |
timestamp = timestamp[:-3] | |
msg_data[timestamp] += 1 |
This file contains hidden or 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
// In the process of creating my first Swift Application using the book "Cocoa Programming for OSX", | |
// I grumbled at what seemed like clumsy, string-handling, then hit a roadblock that nearly turned me completely off. | |
// The string handling code that had worked with Swift 1.2 wouldn't work at all in Swift 3.0. When I figured out | |
// what did work in the latest version I was even more annoyed at the verbosity of it. I could have just left it alone | |
// and dismissed it as not worth wasting any more of my time, but my curiosity got the best of me and I started looking at | |
// the language guide on Apple's Developer site. There I discovered something that totally reversed my thinking: extensions. | |
// I had also read why string-handling had to be that way (flexibility, multiple Unicode encodings, yada, yada, yada). But | |
// I learned that I could utilize extensions to add my own methods to the String class that would give me more convient | |
// string-handling for my own needs. So after much long-windedness, here is |
This file contains hidden or 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 yaml | |
def persistent(K): | |
def __repr__(self): | |
i_vars = dict([(k,self.__dict__[k]) for k in self.__dict__ if not k.startswith('__') and not callable(self.__dict__[k])]) | |
s = "<" + K.__name__ + '(' | |
keywords = [] | |
for i_var in i_vars: | |
keywords.append("%s=%s" % (i_var,repr(i_vars[i_var]))) |
This file contains hidden or 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
def parse_keywords(keywords): | |
""" | |
Returns a dictionary for valid key=value strings | |
""" | |
d = {} | |
try: | |
d = dict([x.split('=',1) for x in keywords]) | |
except ValueError,e: | |
for kw in keywords: |