Skip to content

Instantly share code, notes, and snippets.

@adelehedrick
adelehedrick / Makefile
Created February 13, 2017 15:52
Basic Makefile for Antlr in Ubuntu
all:
java -cp ~/antlr-4.6-complete.jar:. org.antlr.v4.Tool -no-listener -no-visitor *.g4
javac -cp ~/antlr-4.6-complete.jar:. *.java
run:
java -cp ~/antlr-4.6-complete.jar:. ParseFile inputfile
clean:
import pandas as pd
import numpy as np
df = pd.read_csv('data/train.csv')
df = df.drop(['Name', 'Ticket', 'Cabin'], axis=1)
###########################################################
# 1. We need to fill the NaN values rather than drop them
# Improvments go here for training
###########################################################
@adelehedrick
adelehedrick / Makefile
Created March 10, 2016 15:37
Makefile for when using Windows for the antlr-actions code
all:
antlr4 -no-listener -no-visitor *.g4
javac *.java
run:
@java -cp C:\libs\antlr-4.5.2-complete.jar;. ExprParser < inputfile
clean:
del *.java *.tokens *.class
import java.util.regex.*;
import static java.lang.System.out;
class Demo1 {
public static void main(String[] args) {
String pattern_string = args[0];
String content_string = args[1];
Pattern pattern = Pattern.compile(pattern_string);
Matcher matcher = pattern.matcher(content_string);
@adelehedrick
adelehedrick / bellman-ford.py
Created November 13, 2015 15:11
Implements bellman-ford algorithm in python by https://gist.github.com/joninvski/701720. Parses data from assignment 2.
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
# This wonderful bellman-ford algorithm is brought
# to you by https://gist.github.com/joninvski/701720
# Step 1: For each node prepare the destination and predecessor
def initialize(graph, source):
d = {} # Stands for destination
@adelehedrick
adelehedrick / MyPlot.py
Last active October 22, 2015 19:28
Simple python script that reads in integers from a file and plots it.
import matplotlib.pyplot as plt
with open('runtime.txt') as f:
runtimes = [int(line.strip()) for line in f]
plt.hist(runtimes)
plt.savefig('runtime.png')
plt.show()
@adelehedrick
adelehedrick / gist:f64d7a0fa0aedc19ef87
Last active October 14, 2015 23:54
Looping within the makefile.
prepare:
javac World/Person.java
javac World/Community.java
n ?= 10
run:
n=$(n); \
while [ $${n} -gt 0 ] ; do \
echo $$n ; \
n=`expr $$n - 1`; \
@adelehedrick
adelehedrick / InsertionSort.java
Created September 18, 2015 13:52
September 18, 2015 - Tutorial 1 completed tutorial code
import java.util.Arrays;
/*
*
Insertion sort algorithm
for j = 2 to A.length
key = A[j]
i = j-1
@adelehedrick
adelehedrick / InsertionSort.java
Created September 15, 2015 17:33
Scaffolding code for tutorial on insertion sorting algorithm
import java.util.Arrays;
/*
*
Insertion sort algorithm
for j = 2 to A.length
key = A[j]
i = j-1