Skip to content

Instantly share code, notes, and snippets.

View muscar's full-sized avatar

Alex Muscar muscar

View GitHub Profile
@muscar
muscar / markov.py
Created October 13, 2012 09:01
Markov chain text generator
import sys
import random
# Read
def read_file(path):
f = open(path)
text = f.read()
f.close()
return text.split()
@muscar
muscar / serv.py
Created October 21, 2012 06:21
Dumb static file server in Python
import mimetypes as mime
import os
import socket
import sys
WWW_ROOT = 'www_root'
STATUS_MESSAGES = { 200: 'OK',
404: 'Not Found',
500: 'Internal Server Error' }
class ExpEndpoint<T>
{
private Queue<T> inputQueue;
private Queue<T> outputQueue;
private Object stateLock = new Object();
private TaskCompletionSource<T> reader;
public ExpEndpoint(Queue<T> inputQueue, Queue<T> outputQueue)
{
this.inputQueue = inputQueue;
//
// Program.cs
//
// Author:
// Alex Muscar <muscar@gmail.com>
//
// Copyright (c) 2013 Alex Muscar
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
//
// main.cpp
// wirth
//
// Created by Alex Muscar on 6/20/13.
// Copyright (c) 2013 Alex Muscar. All rights reserved.
//
#include <iostream>
#include <vector>
//
// main.cpp
// wirth
//
// Created by Alex Muscar on 6/20/13.
// Copyright (c) 2013 Alex Muscar. All rights reserved.
//
#include <iostream>
#include <vector>
@muscar
muscar / expr.cpp
Created January 11, 2014 10:51
A simple language
struct expr { };
struct num : expr
{
int value;
num(int value) : value(value) { }
};
struct plus : expr
func tryInc(n: Int?) -> Int? {
if let x = n {
return x + 1
}
return nil
}
func tryIncUnsafe(n: Int!) -> Int? {
return n + 1
}
class Person {
let age: Int
init(age: Int) {
self.age = age
}
}
let p1: Person? = Person(age: 27)
let p2: Person? = nil
@muscar
muscar / gist:3732f15691e33ea5b04b
Created July 9, 2014 14:56
Unsafe optionals in Swift
func tryInc(n: Int?) -> Int? {
if let x = n {
return x + 1
}
return nil
}