Skip to content

Instantly share code, notes, and snippets.

View ellamental's full-sized avatar

ella frezynski ellamental

  • san francisco, ca
View GitHub Profile
@ellamental
ellamental / comments_hack.json
Created February 13, 2018 05:39
An extraordinarily hacky method for comments in JSON
{
"// ": "------------------------------------------------------------------",
"// ": "JSON doesn't allow comments, so this is a very hacky workaround.",
"// ": [ "If you run into a situation where you need more than one line ",
"for a comment, you can use an array of strings to compensate ",
"for JSON's lack of support for multi-line strings.",
"(Credit to: https://stackoverflow.com/a/7744658)",
"And you can even have paragraph breaks for long comments.",
class HALResource(object):
"""A HAL Resource
Parameters
----------
uri : Optional[str]
URI for the resource.
data : Optional[dict]
Cached data for this resource.
@ellamental
ellamental / tco.js
Created December 28, 2011 08:11
Tail Calls in Javascript
// JavaScript does not do Tail-Call Optimization therefore the straight-forward
// recursive implementation blows up.
var plain_recursive_count = function (c, n, sum) {
if (c < n) {
return plain_recursive_count(c+1, n, sum+c+", ");
}
else {
return sum;
}
@ellamental
ellamental / alarm_clock.py
Created September 28, 2011 02:38
Refactoring alarm_clock.py
# alarm_clock.py
from time import ctime, clock, sleep
import winsound
import sys
import msvcrt
def get_num_tadas_from_user():
while True:
n = input("\nHow many tadas?> ")
@ellamental
ellamental / chess.py
Created September 13, 2011 23:46
Refactoring chess_clock.py
#!/usr/bin/env python
#coding=utf-8
#chessTimer.py
"""
Can be used as a substitute for a real chess timer.
Must be run at command line.
"""
import time
import msvcrt
@ellamental
ellamental / phone_book.py
Created September 12, 2011 20:22
Refactoring phone_book.py
def add_item_to_data(p):
with open("C:/P32Working/Data/phone_book.txt") as file:
keys_list = [line.partition('=')[0] for line in file]
while True:
file = open("C:/P32Working/Data/phone_book.txt", "a+")
new_item = input("Enter new item in form 'key=value' or enter 'q' to quit: ")
#if quit
if new_item in 'Qq':
@ellamental
ellamental / book.py
Created September 10, 2011 21:02
A simple phone book app
"""
Simple phone book app
(c) Nick Zarczynski
license: BSD
"""
import cPickle
from Tkinter import *
FILENAME = 'book.pk'
@ellamental
ellamental / fizzbuzz.scm
Created September 9, 2011 00:07
FizzBuzz fun in Chicken Scheme
;; I came across the FizzBuzz test for the nth time today and figured I'd write down some solutions in Chicken Scheme
;; Here's the Reddit link if anyone's interested http://www.reddit.com/r/programmingchallenges/comments/h21hc/challenge_fizzbuzz/
;; Recursive
(define (fb n)
(if (< n 101)
(begin
(cond ((= (remainder n 15) 0) (print "FizzBuzz"))
@ellamental
ellamental / tvtracker.py
Created March 24, 2011 05:36
This is a simple app to track the current episode that you are on in various TV shows.
#!/usr/bin/env python
##############################################################################
## If you would like to contribute, contact jacktradespublic@gmail.com
##
## tvtracker is free software: you can redistribute it and/or
## modify it under the terms of the GNU Affero General Public
## License version 3 as published by the Free Software Foundation.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
@ellamental
ellamental / classBasedLinkedList.py
Created January 25, 2011 10:43
Python Implementations of Linked Lists
"""
This method uses a class (cons) to represent and construct the cons cell
"""
class cons:
"""
To construct a new cons cell:
a = cons(1, 2)