Skip to content

Instantly share code, notes, and snippets.

View randerzander's full-sized avatar

Randy Gelhausen randerzander

View GitHub Profile
@randerzander
randerzander / Centos5-Python26
Last active August 29, 2015 14:06
Install python26 on RHEL/Centos 5.10
wget http://dagobah.ftphosting.net/yum/smartfile.repo -O /etc/yum.repos.d/smartfile.repo
mv smartfile.repo /etc/yum.repos.d/
wget http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
sudo rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm
yum install -y libffi python26
@randerzander
randerzander / Hive-Mongo
Last active August 29, 2015 14:10
An example of bidirectional communication between a MongoDB collection and Apache Hive.
# Git clone, build, and copy the necessary MongoDB jars to your worker node $HADOOP_HOME/lib directories
cd ~/
git clone https://github.com/mongodb/mongo-hadoop
cd mongo-hadoop
./gradlew jar
sudo cp build/libs/* /usr/lib/hadoop/lib
sudo cp core/build/libs/* /usr/lib/hadoop/lib
sudo cp hive/build/libs/* /usr/lib/hadoop/lib
cd ~/
@randerzander
randerzander / .vimrc
Last active August 29, 2015 14:18
.vimrc
set number
set autoindent
set smartindent
set expandtab
set shiftwidth=2
set tabstop=2
@randerzander
randerzander / csv2ddl.sh
Last active August 29, 2015 14:19
csv2ddl
set -eu
FILE=$1
HEADER_LINE_NUM=$2
DELIM=$3
TABLE_NAME=$4
LOCATION=$5
# This script assumes columns are all strings. Edit the DDL file after running the script and change column types at will.
@randerzander
randerzander / compress.sh
Created April 19, 2015 17:35
tar and gzip everything in a directory
DIR=$1
cd $DIR
for file in *
do
tar -czvf $file.tgz $file/
done
@randerzander
randerzander / dbf2csv.py
Last active September 9, 2015 22:47
export dbf to csv file
#!/usr/bin/python
import sys, pyproj, shapefile
input_file = sys.argv[1]
output_file = sys.argv[2]
source_spatialref = sys.argv[3]
target_spatialref = sys.argv[4]
sf = shapefile.Reader(input_file)
shapes = sf.shapes()
@randerzander
randerzander / map.js
Last active April 3, 2016 06:16 — forked from granturing/reactive_map.js
Sample reactive Leaflet code for Zeppelin
%angular
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.5/leaflet.css" />
<div id="map" style="height: 500px; width: 100%"></div>
<script type="text/javascript">
function initMap() {
var map = L.map('map').setView([30.00, -30.00], 3);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
var geoMarkers = L.layerGroup().addTo(map);
@randerzander
randerzander / cell1.html
Created April 5, 2016 01:58
Give Zeppelin interpreter results to arbitrary JS
%angular
<div id='testDiv'>
</div>
<script>
var el = angular.element($('#testDiv').parent('.ng-scope'));
angular.element(el).ready(function() {
window.locationWatcher = el.scope().compiledScope.$watch('dummy', function(newValue, oldValue) {
$('#testDiv').append(newValue);
});
});
@randerzander
randerzander / cell1.scala
Created May 27, 2016 05:23
Data-Driven dynamic forms in Apache Zeppelin
def list(table: String, col: String) : Array[(String, String)] = {
sqlContext.sql("select distinct " + col + " from " + table + " order by " + col).collect.map(x => (x(0).asInstanceOf[String], x(0).asInstanceOf[String]))
}
def tables(): Array[(String, String)] = {
sqlContext.sql("show tables").collect.map(x => (x(0).asInstanceOf[String], x(0).asInstanceOf[String]))
}
def columns(table: String) : Array[(String, String)] = {
sqlContext.sql("select * from " + table + " limit 0").columns.map(x => (x, x))
@randerzander
randerzander / cell1.scala
Last active June 1, 2016 03:18
QueryBuilder in Zeppelin
//Get list of distinct values on a column for given table
def distinctValues(table: String, col: String) : Array[(String, String)] = {
sqlContext.sql("select distinct " + col + " from " + table + " order by " + col).collect.map(x => (x(0).asInstanceOf[String], x(0).asInstanceOf[String]))
}
//Get list of tables
def tables(): Array[(String, String)] = {
sqlContext.sql("show tables").collect.map(x => (x(0).asInstanceOf[String], x(0).asInstanceOf[String]))
}