Skip to content

Instantly share code, notes, and snippets.

################################################################################
# Making custom named pipes
################################################################################
Open two ssh sessions to a system. In one, create your pipe and then send some command output to it.
$ mkfifo mypipe
$ cal > mypipe
Don’t worry that your command just seems to hang.
In the other, read from the pipe.
@shaunhess
shaunhess / monitor_notes
Created April 1, 2014 01:26
Monitor Notes
################################################################################
# Calculate Pixels Per Inch
################################################################################
# Calculate w/ the Horizontal x Vertical resolution, Horizontal & Vertical size
################################################################################
Horizontal_Resolution = 2560
Vertical_Resolution = 1440
Horizontal_Size_MM = 597.89
Vertical_Size_MM = 336.31
@shaunhess
shaunhess / cache_perf_calc
Created April 19, 2015 19:18
Cache Performance Calculation
Cache is a net benefit in perf if time saved in cache hits exceeds time lost in cache overhead.
L = Regular lookup
H = Cache Hit
M = Cache Miss
R = Cache Hit Ratio (500 lookups/100 served from cache is 20%)
H x R + M x (1 - R) < L
@shaunhess
shaunhess / Scheme_Notes
Created July 18, 2015 22:30
Notes from SICP using Scheme (LISP)
;; Installation on Mac OS X
;; After downloading and installing into applications folder run the following commands from the terminal
;; sudo ln -s /Applications/MIT\:GNU\ Scheme.app/Contents/Resources /usr/local/lib/mit-scheme-x86-64
;; sudo ln -s /usr/local/lib/mit-scheme-x86-64/mit-scheme /usr/bin/scheme
;; To Launch simply type "scheme" in the terminal
;; Using operators on operands (Scheme uses prefix notation)
(+ 4 4) ; Add 4 + 4 = 8
;; Add two numbers that are multiplied
@shaunhess
shaunhess / Memory_Intro
Last active August 29, 2015 14:27
A Brief Introduction to Memory
RAM, random access memory, is the ability to store/read values based on address inputs
(versus say sequentially). It is also commonly referred to as voltile memory because it
requires a constant supply of electricity to retain its contents.
The number of values that a RAM array can store is based on the number of address inputs.
With 1 address input we can store 2 values (0 or 1).
2 addresses = 4 values (00, 01, 10, 11)
3 addresses = 8 values (000, 001, 010, 100, 011, 101, 110, 111)
4 addresses = 16 values
@shaunhess
shaunhess / code_complexity_efficiency.py
Last active September 30, 2015 23:51
Measuring Code Complexity and Efficiency
# Measure complexity as a function of input size
# - Worst case scenario
# - Largest factor in expression
# Asymptotic Notation - provide a formal way to talk about the relationship between
# the running time of an algorithm and the size of inputs.
#
# Asymptotic notation describes the complexity of an algorithm as the size of it's
# inputs approaches infinity
@shaunhess
shaunhess / gist:4192086
Created December 3, 2012 01:42
Python - Quick and Dirty Web Service
# Server Side
from SimpleXMLRPCServer import SimpleXMLRPCServer
def file_reader(file_name):
with open(file_name, 'r') as f:
return f.read()
server = SimpleXMLRPCServer(('localhost', 8000))
server.register_introspection_functions()
@shaunhess
shaunhess / gist:4192072
Created December 3, 2012 01:39
Python - Pretty Printing JSON
>>> import json
>>> print(json.dumps(data)) # No indention
{"status": "OK", "count": 2, "results": [{"age": 27, "name": "Oz", "lactose_intolerant": true}, {"age": 29, "name": "Joe", "lactose_intolerant": false}]}
>>> print(json.dumps(data, indent=2)) # With indention
{
"status": "OK",
"count": 2,
"results": [
{
"age": 27,
#!/usr/bin/env python
#
# Python Timer Class - Context Manager for Timing Code Blocks
# Corey Goldberg - 2012
#
from timeit import default_timer
@shaunhess
shaunhess / Test_Prime_Num_PowerShell
Created October 20, 2013 19:20
Testing for Prime Numbers Using Powershell
So what is a prime number anyway. Lets see what Wikipedia has to say:
A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself. A natural number greater than 1 that is not a prime number is called a composite number. For example, 5 is prime, as only 1 and 5 divide it, whereas 6 is composite, since it has the divisors 2 and 3 in addition to 1 and 6. The fundamental theorem of arithmetic establishes the central role of primes in number theory: any integer greater than 1 can be expressed as a product of primes that is unique up to ordering. This theorem requires excluding 1 as a prime.
Since there are infintely number of primes, it's always fun to see how fast and how many we can find. The largest know prime number has nearly 13 million decimal digits!
Now thats out of the way lets see how we can test to see whether a number is prime or not using Powershell. Today we will look at a few different methods, including my favorite, Sieve of Eratosthenes.