Skip to content

Instantly share code, notes, and snippets.

@gatesphere
gatesphere / enc.io
Created October 4, 2012 19:43
Diffie-Hellman key exchange and XOR encryption
#!/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)
@gatesphere
gatesphere / concat.sh
Last active October 12, 2015 17:27
Stupid Bash Tricks
a="hello"
b="world"
c=$a" there, isn't it a wonderful "$b"?"
echo $c
@gatesphere
gatesphere / gridlines.pde
Last active December 10, 2015 20:18
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.
// 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 / create-leo.bat
Last active December 12, 2015 01:38
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 / genpass.py
Created March 5, 2013 14:38
Random Password Generator in Python
#!/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("\\", "")
@gatesphere
gatesphere / light-dusk.txt
Last active December 25, 2015 19:09
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
<?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 / approach_1.py
Last active December 26, 2015 19:19
Passing comparison operators in Python
## 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 / << imports >>.py
Last active December 27, 2015 09:49
Using nodewatch.py for productivity
import datetime
import operator
from dateutil.relativedelta import relativedelta # do a 'pip install python-dateutil' for this
@gatesphere
gatesphere / schelling.py
Last active December 30, 2015 01:39
Simplified Schelling Model
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 / marksweep.py
Created December 9, 2013 19:01
Mark and Sweep garbage collection example
''' 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