Skip to content

Instantly share code, notes, and snippets.

View bhavanki's full-sized avatar
💭
Flossing

Bill Havanki bhavanki

💭
Flossing
View GitHub Profile
@bhavanki
bhavanki / Sieve.java
Created August 26, 2013 20:42
Java implementation of Sieve of Eratosthenes
import java.util.List;
public class Sieve {
static List<Integer> sieve(int n) {
List<Integer> l = new java.util.ArrayList<Integer>();
byte[] bs = new byte[(n / 8) + 1]; // 0 => maybe prime
bs[0] = (byte) 0xc0; // skip 0 and 1
for (int i = 2; i <= n / 2; i++) {
for (int c = i; c <= n; c += i) {
int bidx = c / 8;
@bhavanki
bhavanki / groovynotes.md
Created August 13, 2013 15:40
Notes on transitioning from Java to Groovy

Notes on Groovy

Optional (Duck) Typing

class Duck {
  def walk() { println "I'm a duck, I walk" }
  def swim() { println "I'm a duck, I swim" }
  def quack() { println "QUACK" }
}

class Person {

@bhavanki
bhavanki / httpd.py
Created August 12, 2013 20:55
Simple HTTP server in Python; serves the current directory.
import os
import sys
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
pid = os.fork()
if pid != 0:
print "Server PID is", pid
sys.exit()
@bhavanki
bhavanki / gojdk.sh
Created August 9, 2013 19:16
Script to swap environment to a different JDK. Must be sourced to work.
#!/bin/bash
echo Switching to Java $1
OLD_JAVA_HOME=$JAVA_HOME
if [ "$1" == "1.6" -o "$1" == "6" -o "$1" == "6.0" ]; then
export JAVA_HOME=/usr/lib/jvm/java-1.6.0
elif [ "$1" == "1.7" -o "$1" == "7" -o "$1" == "7.0" ]; then
export JAVA_HOME=/usr/lib/jvm/java-1.7.0
@bhavanki
bhavanki / cdpom.sh
Created August 9, 2013 19:12
Simple script to bounce you back up to the first parent directory with a Maven POM in it. Must be sourced to work as expected (so alias it).
#!/bin/bash
POMDIR=$(pwd)
while [[ "$POMDIR" != "/" && ! -f "$POMDIR/pom.xml" ]]; do
POMDIR=$(dirname "$POMDIR")
done
if [[ "$POMDIR" != "/" ]]; then
cd "$POMDIR"
else
@bhavanki
bhavanki / charesc.html
Created January 23, 2013 19:06
Page to emit character literal escape sequences in different programming languages.
<html>
<head><title>Character Escapes</title>
<style type="text/css">
body {
font-family: sans-serif;
margin-top: 1in;
}
p {
font-size: large;
text-align: center;
@bhavanki
bhavanki / glitchdate.py
Created November 4, 2012 03:24
Python script to report the current time in Ur, the world of Glitch.
#!/usr/bin/python
import calendar
from datetime import datetime
from optparse import OptionParser
import sys
# Define command line options: -D, -f, -F.
op = OptionParser()
op.add_option('-D', '--date', dest='date_to_use',
help='UTC date to use instead of now, as %Y%m%d%H%M')
@bhavanki
bhavanki / prompt_open_file_path.py
Created August 15, 2012 21:08
Sublime Text 2 plugin for emacs-like file open. Based on https://bitbucket.org/chrisguilbeau/cg-sublime.
import sublime, sublime_plugin
from os import listdir
from os.path import commonprefix
from os.path import isdir
#from os import getenv
from os import getcwd
from os import sep
class PromptOpenFilePathCommand(sublime_plugin.WindowCommand):
@bhavanki
bhavanki / colorize-maven.sh
Created June 21, 2012 21:10 — forked from mike-ensor/colorize-maven.sh
Colorize Maven output
#!/bin/sh
# Written by Mike Ensor (mike@ensor.cc)
# Copywrite 2012
# Use as needed, modify, have fun!
# Modified by Bill Havanki
# This was intended to be used for Maven3 + Mac OSX, but it's been modified for Cygwin and Linux.
# Maybe it still works on OSX?
# Changes from original:
# - Cygwin support
@bhavanki
bhavanki / tamdate.sh
Created June 9, 2012 02:17
Bash script to report the date in the Tamrielic (Elder Scrolls) calendar
#!/bin/bash
# tamdate.sh - echoes the date in the Tamrielic calendar
# Calendar information from http://www.uesp.net/wiki/Lore:Calendar
usage() {
echo Usage: tamdate.sh [options]
echo Options:
echo -m = include Tamrielic month
echo -d = include Tamrielic weekday