Skip to content

Instantly share code, notes, and snippets.

@Maddix
Maddix / let-unpack.lsp
Created September 21, 2016 21:36
Unpack items from a list into variables in a let statment
;;;; NewLisp
(context 'let-unpack) ; (let-unpack (a b c (list 1 2 3)) (+ a b c)) -> 6
(define-macro (let-unpack:let-unpack expressions body)
(letn (rev (reverse expressions) syms (apply list (reverse (rest rev))) vals (eval (first rev)))
(eval (letex (expression (map (fn (symb val) (list symb val)) syms vals) body body)
'(let expression body)))))
(context MAIN)
@Maddix
Maddix / join-paths.lsp
Created September 12, 2016 17:35
Join multiple strings together with the appropriate slash for the os to make a complete path.
(define (join-paths)
(join (flat $args) (if (= ostype "Windows") {\} "/")))
@Maddix
Maddix / guess_my_number_game.py
Created September 30, 2015 00:21
Python version of guess my number game. 17 lines long, though one could make it 15 lines long by removing the win variable and the user = int(user).
import random
num = random.randint(0, 100)
win = False
print("Guess my number game!")
while not win:
user = input("> ")
if user.isdecimal():
user = int(user)
if user > num:
print("To High!")
@Maddix
Maddix / copyItem.js
Last active August 29, 2015 14:16
This function returns a deep copy of a list or object.
copyItem = function(item, shallow) {
var itemProto = Object.prototype.toString.call(item);
var newItem = item;
var getItem = function(child) { return !shallow ? copyItem(child) : child; };
if (itemProto === Object.prototype.toString.call([])) {
newItem = [];
for (var itemIndex=0, len=item.length; itemIndex < len; itemIndex++) newItem.push(getItem(item[itemIndex]));
}
if (itemProto === Object.prototype.toString.call({})) {
newItem = {};