Skip to content

Instantly share code, notes, and snippets.

Jacob Peck gatesphere

Block or report user

Report or block gatesphere

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@gatesphere
gatesphere / marksweep.py
Created Dec 9, 2013
Mark and Sweep garbage collection example
View marksweep.py
''' inspired by http://journal.stuffwithstuff.com/2013/12/08/babys-first-garbage-collector/ '''
INITIAL_GC_THRESHOLD = 8
STACK_MAX = 256
class PLObj(object):
def __init__(self):
self.marked = False
self.next = None
@gatesphere
gatesphere / schelling.py
Last active Dec 30, 2015
Simplified Schelling Model
View schelling.py
import random
neighborhood = 2 # cells on both sides
happy = 2 # at least this many cells are same
empty = .1
red = .45
blue = .45
numcells = 80
@gatesphere
gatesphere / << imports >>.py
Last active Dec 27, 2015
Using nodewatch.py for productivity
View << imports >>.py
import datetime
import operator
from dateutil.relativedelta import relativedelta # do a 'pip install python-dateutil' for this
@gatesphere
gatesphere / approach_1.py
Last active Dec 26, 2015
Passing comparison operators in Python
View approach_1.py
## approach 1
def myfun(a, b, mode='<'):
valid_modes = ['<', '<=', '>', '>=', '==', '!=']
if mode not in valid_modes:
print 'Error!'
... # error handling code here
return
if mode == '<':
if a < b:
@gatesphere
gatesphere / light-dusk.txt
Last active Dec 25, 2015
Leo - Light Dusk theme (body editor only) Copy the raw text below (it contains a Leo tree) and paste it into your myLeoSettings.leo under @settings
View light-dusk.txt
<?xml version="1.0" encoding="utf-8"?>
<!-- Created by Leo (http://leoeditor.com/leo_toc.html) -->
<?xml-stylesheet ekr_test?>
<leo_file xmlns:leo="http://www.leo-editor.org/2011/leo" >
<leo_header file_format="2"/>
<vnodes>
<v t="peckj.20131009135732.3509"><vh>Body editor: light-dusk</vh>
<v t="peckj.20131009135732.3491"><vh>Colors</vh>
<v t="peckj.20131122130640.6165"><vh>Color definitions</vh>
<v t="peckj.20131122130640.6166"><vh>@color MistyRose1 = #FFE4E1</vh></v>
@gatesphere
gatesphere / genpass.py
Created Mar 5, 2013
Random Password Generator in Python
View genpass.py
#!/usr/bin/python
# this script generates a random password of length 8,
# or whatever length is passed in on the command line
from string import ascii_letters, digits, punctuation
import sys, random
chars = ascii_letters + digits + punctuation
chars = chars.replace("\\", "")
View create-leo.bat
@echo off
:: A batch file which generates other batch files to run the Leo Editor,
:: adapted for the local machine. Optionally, it will also set the Windows
:: filetype and association so .leo files can be opened from Explorer.
::
:: It needs to live in the same folder as "launchLeo.py"
::
:: Open Source X/MIT License
:: initial version * 2012-Dec-13 * matt wilkie <maphew@gmail.com>
:: modified version * 2013-Jan-31 * jacob peck <suschord@suspended-chord.info>
@gatesphere
gatesphere / gridlines.pde
Last active Dec 10, 2015
A skeleton gridline sketch in Processing. This is useful for people who want to line up their items according to a grid when designing. The grid can be turned off in the final product by changing the GRID_DRAW value from true to false.
View gridlines.pde
// gridlines
// grid specific vars
// grid spacing in pixels
int GRID_MINOR_SPACING = 10;
int GRID_MAJOR_SPACING = 100;
// gridline colors
color GRID_MINOR_COLOR = color(147, 161, 247, 127);
color GRID_MAJOR_COLOR = color(0, 19, 137, 127);
// gridline weights in pixels
@gatesphere
gatesphere / concat.sh
Last active Oct 12, 2015
Stupid Bash Tricks
View concat.sh
a="hello"
b="world"
c=$a" there, isn't it a wonderful "$b"?"
echo $c
@gatesphere
gatesphere / enc.io
Created Oct 4, 2012
Diffie-Hellman key exchange and XOR encryption
View enc.io
#!/usr/bin/env io
Person := Object clone do(
pub ::= nil // "composed" key
priv ::= nil // private key
shared ::= nil // generated key
init := method(
self setPub(nil)
self setPriv(nil)
You can’t perform that action at this time.