Skip to content

Instantly share code, notes, and snippets.

View efruchter's full-sized avatar
🏠
Working from home

Eric Fruchter efruchter

🏠
Working from home
  • Epic Games
  • Los Angeles, CA
View GitHub Profile
@efruchter
efruchter / mediated.py
Last active August 29, 2015 14:02
insecure
import os
from flask import Flask, request, redirect, url_for
from werkzeug.utils import secure_filename
from flask import Flask, jsonify
from flask.ext.cors import cross_origin
app = Flask(__name__)
@app.route('/order', methods=['GET'])
@efruchter
efruchter / changemaker.py
Last active August 29, 2015 14:03
Make change using a given amount of coins. No memoization, for simplicity's sake.
# The denominations
denoms = [1, 5, 10, 25]
def make_change(change, denoms):
return _make_change(change, sorted(denoms, reverse=True))
def _make_change(cents, denoms):
ways = []
for denom in denoms:
if cents == denom:
@efruchter
efruchter / RandomBag.py
Last active August 29, 2015 14:03
A bag of random elements to pick from. Usage: when you want to guarantee that a random event will occur an exact number of times, but want a random ordering. Good for RPG A.I., as it will prevent the AI from picking the same move too many times, but still have a skewed random pick.
import random
# A bag of random elements to pick from.
# Usage: when you want to guarantee that a random
# event will occur, but want a random ordering.
class RandomBag:
# Build a bag. Fill it with counts using tuples
# [('attack', 3), ('flee', 1), ...]
def __init__(self, element_count_tuples=[]):
@efruchter
efruchter / markov_ride.py
Last active August 29, 2015 14:12
MC Ride Trigrams. Enjoy the soothing verse of MC Ride from the comfort of your own computer.
from nltk.util import ngrams
from nltk.model import NgramModel
from nltk.probability import LidstoneProbDist
# Source: should be formatted on multiple lines for each sentence.
SOURCE_TEXT = 'Mystery.txt'
LINE_START = "<line>"
LINE_END = "</line>"
@efruchter
efruchter / RenderTextureInNewTabExample.cs
Last active August 29, 2015 14:17
Open a texture from Unity3D Web player in another tab of the web browser.
using UnityEngine;
using System.Collections;
using System.Text;
public class RenderTextureInNewTabExample : MonoBehaviour
{
public Texture2D texture;
void Start ()
{
@efruchter
efruchter / secretshader.shader
Last active August 29, 2015 14:18
cuts two alpha holes in a texture.
Shader "Expiremental/CircleCutout"
{
Properties
{
[PerRendererData] x1 ("1.x", Float) = 0
[PerRendererData] y1 ("1.y", Float) = 0
[PerRendererData] x2 ("2.x", Float) = 0
[PerRendererData] y2 ("2.y", Float) = 0
@efruchter
efruchter / Trie.cs
Last active April 22, 2018 21:35
A Trie implementation in C#
using System;
using System.Collections.Generic;
/**
* A space-saving data structure to store words and their counts.
* Words that share prefixes will have common paths along a branch of the tree.
*/
public class Trie
{
private TrieNode head;
@efruchter
efruchter / Trie.cpp
Last active January 14, 2016 14:52
fast hashset for character arrays.
//
// Trie.cpp
// CPPTest
//
// Created by Eric Fruchter on 12/26/15.
// Copyright © 2015 Eric Fruchter. All rights reserved.
//
#include "Trie.hpp"
@efruchter
efruchter / radix_sort_test.cpp
Last active January 14, 2016 14:43
radix-sort for 32-bit 2's-compliment integers. Implemented a homegrown clone of of std's stable_partition.
#include <iostream>
#include <functional>
#include <iterator>
#include <vector>
struct Node {
Node* next = nullptr;
int data;
};
@efruchter
efruchter / Snake.cpp
Created February 27, 2017 02:21
A 1-script snake game implemented in object-less c++
// Snake.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <Windows.h>
using namespace std;