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 / MapGenerator.java
Created October 30, 2012 18:43
Map generating algorithm for a roguelike with a GUI map viewer.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
/**
* A static utility class for generating random maps for a dungeon-crawler.
*
* @author Eric
@efruchter
efruchter / HelloWorld.lua
Created June 5, 2013 20:48
A simple intro to the Lua language, with everybody's favorite program, Hello World! Credit goes to Corsix.org.
_={_=_G}for--[[]]__--[[]]in(next),_["_"]do(_)[_]=(__)_[#_[_]],_[_[_]:byte(-#"#"
)+#_[_]-(#{}+#"(#''"*#"*#*#*"*#"_[_[]]")]=_[_],_[_]end(_)[_]=_._[_[#""]]{[_._[_
[#""]]]=_}_[""]=_._[_._[_[#[=[=#=]=]*-((#[=[#[=]#]=]))]](_._[_[-#[[_[-#[#_[_]]]
](_))]_[";"]=_._[_[#"#"+(#")#^")^#"#^"]]_["'"]=[[sub]]_['"']=_[""][_["'"]]_["/"
]=[[/_)=.,[#"('*:^;+]]_["'"]=_[""][_['"'](_[-#[[=[=]=]]],-#",_",-#"..").._["'"]
]_["["]=_['"'](_[-#"#-]_"],#",",#{_}).._['"'](_[-#"-"],#",",#"#").._['"'](_[-(#
"^#^")^#"^#"],#"-",#"(").._['"'](_[#_[-#"#"]*-#"[#"],#_[-#"#"],#_[-#"#"]).._[''
..'"'](_[-#[[=[]=]]],#_["/"]/#_["/"],#"/").._['"'](_[-(#"#)-")^#[[""]]],-#"-,",
-#[=[[]]=])_["]"]=_['"'](_[-#_[-#"-"]],#",",#"#").._[";"](_["["]..[=[('\]=]..(#
'#).'*#',..]]'*#'",#"#",'-#'(').."')")().._['"'](_[-#_[-#"-"]],-#_[-#"-"]-#"-",
@efruchter
efruchter / .gitignore-unity
Created June 17, 2013 07:15
Nice .gitignore for Unity3D projects in particular. Put it in root, don't forget to put unity in meta file mode! Also rename this file when you get to using it.
/Library/
/Temp/
*.blend*
!*.blend
!*.meta
@efruchter
efruchter / .xbindkeysrc
Last active December 23, 2015 01:58
display rotate script for Thinkpad x200 using xrandr, xsetwacom, and xbindkeys.
"bash rotate_display flip"
m:0x0 + c:161
NoSymbol
@efruchter
efruchter / viterbi.py
Last active December 26, 2015 02:29
Viterbi Solver for homework 3. Sloppy, but it gets the job done.
def avalanche(sequence, print_all=False):
states = ['1', '2']
emissions = {}
emissions[('1', 'C')] = .1
emissions[('1', 'C#')] = .1
emissions[('1', 'D')] = .4
emissions[('1', 'D#')] = .4
emissions[('2', 'C')] = .4
@efruchter
efruchter / rotate_screen_widget.py
Last active December 31, 2015 02:29
Rotate the screen using this GTK taskbar icon
#!/usr/bin/python
# -*- coding: utf-8 -*-
# [SNIPPET_NAME: Screen Rotate]
# [SNIPPET_DESCRIPTION: Shows a widget to rotate screen]
# [SNIPPET_AUTHOR: Eric Fruchter <[email protected]>]
# [SNIPPET_LICENSE: GPL]
#
import gtk
@efruchter
efruchter / Fruchterhash.java
Last active August 29, 2015 13:56
Programming Warmups
package test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
/**
* A not-very-efficient hashmap with an array as a base.
*
@efruchter
efruchter / geocode.py
Created February 12, 2014 09:54
A python script to convert addresses into lat/lng pairs via Google's API.
import time
import json
import urllib2
import csv
def geocode(a):
h = a.replace(' ', '+')
req = 'http://maps.googleapis.com/maps/api/geocode/json?address=' + h + '&sensor=false'
data = json.load(urllib2.urlopen(req))
ploc = data['results']
@efruchter
efruchter / cipher.py
Last active August 29, 2015 14:01
Some basic ciphers for infosec.
#python 2.7
from __future__ import division
padding = '|'
cipher_key = 'abcdefghijklmnopqrstuvwxyz '
cipher_key_length = len(cipher_key)
# A shift cipher. Can also use a key, turning it into a vernam cipher.
# text = the text
# key = the key. Can be a number or a string.
@efruchter
efruchter / weighted_random.py
Last active August 29, 2015 14:01
An implementation of weighted random selection in python. O(n*log(n))
import random
# This method randomly picks a single choice from a collection of choices.
# freq_tuples: List of tuples of the form: (choice, count)
# Returns a choice, or None if empty list.
def weighted_random_selection(freq_tuples):
if len(freq_tuples) == 1:
return freq_tuples[0][0]
sorted_freq_tuples = sorted(freq_tuples, key = lambda tup : tup[1], reverse=True)
total = sum([count for gram, count in freq_tuples]) * random.random()