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 / 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 / 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 / gitprompt.sh
Last active December 21, 2015 23:29
.bashrc snippet to include the current Git branch in the prompt
parse_git_branch() {
git branch --no-color 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \1 /'
}
gitps1() {
local GREEN="\[\033[0;32m\]"
local DEFAULT="\[\033[0m\]"
PS1="[\u@\h \W]$GREEN\$(parse_git_branch)$DEFAULT\$ "
}
gitps1
@bhavanki
bhavanki / makeapp.sh
Last active January 2, 2016 14:29 — forked from demonbane/makeapp.sh
Chrome SSB generation script. Modifications since forking: - support for spaces in app name
#!/bin/sh
echo "What should the Application be called (e.g. GCal)?"
read inputline
name="$inputline"
echo "What is the url (e.g. https://www.google.com/calendar/render)?"
read inputline
url="$inputline"
@bhavanki
bhavanki / MetadataTableUtilTesting.java
Created March 20, 2014 15:32
An example of using a factory class to improve testability over a static method call.
/*
* Current getMetadataTable() method. This is hard to test because it requires a real HdfsZooInstance object.
*/
public synchronized static Writer getMetadataTable(Credentials credentials) {
Writer metadataTable = metadata_tables.get(credentials);
if (metadataTable == null) {
metadataTable = new Writer(HdfsZooInstance.getInstance(), credentials, MetadataTable.ID);
metadata_tables.put(credentials, metadataTable);
}
return metadataTable;
@bhavanki
bhavanki / gist:e6e21ea15cf5670ba534
Created May 27, 2014 22:18
Out-of-memory stack traces when writing and scanning Accumulo rows of 100 cells with 100 MB values in each cell
Observed in monitor:
Unexpected throwable while invoking!
java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2786)
at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:94)
at org.apache.thrift.transport.TFramedTransport.write(TFramedTransport.java:146)
at org.apache.thrift.protocol.TCompactProtocol.writeBinary(TCompactProtocol.java:342)
at org.apache.thrift.protocol.TCompactProtocol.writeBinary(TCompactProtocol.java:337)
at org.apache.accumulo.core.data.thrift.TKeyValue$TKeyValueStandardScheme.write(TKeyValue.java:465)
@bhavanki
bhavanki / master-protect-pre-push
Created March 10, 2015 21:09
Protects origin/master from your screwed-up pushes
#!/bin/bash
protected_branch='master'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
remote_name=$1
if [[ $remote_name != "origin" ]]; then
exit 0
fi
@bhavanki
bhavanki / director_install.sh
Last active September 25, 2017 17:39
A bash script for installing Cloudera Director. If you are feeling adventurous, use curl to pipe it into bash. Otherwise, download and run.
#!/usr/bin/env bash
# Copyright 2017 William A. Havanki, Jr.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
{
"basics": {
"name": "William A. Havanki, Jr.",
"label": "",
"picture": "",
"email": "[email protected]",
"website": "http://havanki.us/",
"summary": "",
"location": {
"address": "1234 Test St.",
@bhavanki
bhavanki / Bash.markdown
Created November 4, 2021 21:33
My cheat sheet for helpful Bashisms

Read the lines output from a command into an array variable

readarray -t var < <(command)
var=()
while IFS= read -r line; do
  var+=( "$line" )