Skip to content

Instantly share code, notes, and snippets.

@deanlxvii
deanlxvii / error octave_kernel
Created June 19, 2015 10:45
error on plot with octave_kernel
[IPKernelApp] ERROR | Exception in message handler:
Traceback (most recent call last):
File "/home/dean/.home/opt/jupyter/local/lib/python2.7/site-packages/IPython/kernel/zmq/kernelbase.py", line 213, in dispatch_shell
handler(stream, idents, msg)
File "/home/dean/.home/opt/jupyter/local/lib/python2.7/site-packages/IPython/kernel/zmq/kernelbase.py", line 362, in execute_request
user_expressions, allow_stdin)
File "/home/dean/.home/opt/jupyter/local/lib/python2.7/site-packages/metakernel/_metakernel.py", line 312, in do_execute
retval = self.do_execute_direct(code)
File "/home/dean/.home/opt/jupyter/lib/python2.7/site-packages/octave_kernel.py", line 76, in do_execute_direct
self._make_figs(plot_dir)
@deanlxvii
deanlxvii / norepsim.py
Created March 18, 2015 12:07
noReplacementSimulation(numTrials)
import random
def noReplacementSimulation(numTrials):
'''
Runs numTrials trials of a Monte Carlo simulation
of drawing 3 balls out of a bucket containing
3 red and 3 green balls. Balls are not replaced once
drawn. Returns the a decimal - the fraction of times 3
balls of the same color were drawn.
'''
[Matrix]
definition-foreground = #d301ff
definition-fontStyle = bold
error-foreground = #000000
string-background = #000000
keyword-foreground = #ffbf00
keyword-fontStyle = bold
normal-foreground = #00ff00
comment-background = #000000
hit-foreground = #ffffff
@deanlxvii
deanlxvii / keys.py
Created September 14, 2012 10:01
catch key(board) events (ms-windows)
import pythoncom, pyHook
def OnKeyboardEvent(event):
print 'MessageName:',event.MessageName
print 'Message:',event.Message
print 'Time:',event.Time
print 'Window:',event.Window
print 'WindowName:',event.WindowName
print 'Ascii:', event.Ascii, chr(event.Ascii)
print 'Key:', event.Key
@deanlxvii
deanlxvii / gist:1466141
Created December 12, 2011 09:19
change dir and list
# include this in the .bashrc
cs () {
cd $1
ls
}
@deanlxvii
deanlxvii / hex_byte_conversion.py
Created October 14, 2011 17:38
Hex Byte Conversion
"""
HexByteConversion
Convert a byte string to it's hex representation for output or visa versa.
ByteToHex converts byte string "\xFF\xFE\x00\x01" to the string "FF FE 00 01"
HexToByte converts string "FF FE 00 01" to the byte string "\xFF\xFE\x00\x01"
"""
#-------------------------------------------------------------------------------
@deanlxvii
deanlxvii / single_space.py
Created October 14, 2011 12:48
Remove multiple spaces from a file
def single_space(fileName):
"""
remove multiple spaces from a file
"""
input = open(fileName, 'r')
output = open('tmp.txt', 'w')
output.write(string.join(input.read().split()))
input.close()
output.close()
os.remove(fileName)
@deanlxvii
deanlxvii / count_a_string.py
Created October 14, 2011 12:46
Count the occurrences of a string in a file
def count(fileName, count_string):
"""
Count the occurrences of a string in a file
"""
count = 0
input = open(fileName, 'r')
line = input.readline()
while line <> '':
if count_string in line:
count = count + 1
@deanlxvii
deanlxvii / replace.py
Created October 14, 2011 12:43
replace string in file
import os
def replace(fileName, sstr, rstr):
"""
replace sstr for rstr in a file
"""
input = open(fileName, 'r')
output = open('tmp.txt', 'w')
output.write(input.read().replace(sstr, rstr))
input.close()
@deanlxvii
deanlxvii / walkdir.py
Created October 14, 2011 12:39
walking directory trees
import os, fnmatch
import os.path
def all_files(root, patterns='*', single_level=False, yield_folders=False):
"""
Examine a directroy, or an entire directroy tree rooted in a certain
directory.
"""
# Expande patterns from semicolon-seperated string to list
patterns = patterns.split(';')