Skip to content

Instantly share code, notes, and snippets.

@heyhuyen
heyhuyen / Simple Java Setup
Last active February 7, 2017 23:37
Simple Java Environment Setup for command line usage (Mac)
# See https://www.tutorialspoint.com/junit/junit_executing_tests.htm
# ~/.bash_profile
export JAVA_HOME=/Library/Java/Home
export JUNIT_HOME=/Library/JUNIT
export CLASSPATH=$CLASSPATH:$JUNIT_HOME/junit-4.10.jar:.
# TestJunit.java
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@heyhuyen
heyhuyen / naive_string_search_variations.py
Created December 19, 2012 23:35
Naive string search algorithm implementations in Python 2.7
# In the middle of implementing Boyer-Moore's string search algorithm, I decided to play with my original naive search algorithm. It's implemented as an instance method that takes a string to be searched. The object has an attribute 'pattern' which is the pattern to match.
# 1) Here is the original version of the search method, using a double for-loop.
# Makes calls to range and len
def search(self, string):
for i in range(len(string)):
for j in range(len(self.pattern)):
if string[i+j] != self.pattern[j]:
break