Skip to content

Instantly share code, notes, and snippets.

import (
"fmt"
"math/rand"
"time"
)
func getUnderside(coin string, upside string) string {
if coin == "Fair" && upside == "Heads" {
return "Tails"
} else {
@boneill42
boneill42 / dump.py
Created April 7, 2016 18:37
Kinesis PySpark example
from __future__ import print_function
import sys
from pyspark import SparkContext
from pyspark.streaming import StreamingContext
from pyspark.streaming.kinesis import KinesisUtils, InitialPositionInStream
import sys
def foo(line):
print(line)
return line.split(" ")
@boneill42
boneill42 / dump_mysql.py
Created November 24, 2015 13:09
Python to dump mysql tables listed in a text file.
from subprocess import call
with open("tables") as f:
tables = f.readlines()
for table in tables:
command = table.strip().split(".")
command.insert(0, "mysqldump")
outfile = open("{0}.sql".format(command[2]), "w")
print command
@boneill42
boneill42 / instances.py
Created September 15, 2015 14:41
Grab instances/ips from ec2 based on existence of key
#!/usr/bin/python
import sys
import json
from subprocess import check_output
if len(sys.argv) < 2:
print ("Usage: instances.py [tag_name]")
else:
instances_json = check_output(["aws", "--region", "us-east-1", "ec2", "describe-instances"])
instances = json.loads(instances_json)
@boneill42
boneill42 / gist:0f89b181f14f271ce18a
Created October 21, 2014 20:04
Tab delimited parsing with OpenCSV
import au.com.bytecode.opencsv.CSVReader;
public class LoadTest {
@Test
public void testLoad(String row) throws IOException, JobNotFoundException, InterruptedException {
CSVReader reader = new CSVReader(new FileReader("/Users/bone/Desktop/foo_data.tab"), '\t');
String[] record;
while ((record = reader.readNext()) != null) {
for (String value : record) {
@boneill42
boneill42 / gist:6235749
Created August 14, 2013 21:18
Storm - Druid - Cassandra Integration
This file has been truncated, but you can view the full file.
2013-08-14 17:18:07,813-0400 | ERROR [Thread-25] TweetSplitterFunction.execute(22) | SPLITTING TWEET [RT @UncleTimi: "Bill Gates left education. So did Steve Jobs"
And?! Are you planning to create Microsoft or Apple? No, I didn't think so. …]
2013-08-14 17:18:07,813-0400 | ERROR [Thread-25] TweetSplitterFunction.execute(22) | SPLITTING TWEET [Is Apple Doomed Without Steve Jobs, as Larry Ellison Predicts? | News & Opinion http://t.co/mrXV1tzldc]
2013-08-14 17:18:07,814-0400 | ERROR [Thread-25] TweetSplitterFunction.execute(22) | SPLITTING TWEET [RT @UncleTimi: "Bill Gates left education. So did Steve Jobs"
And?! Are you planning to create Microsoft or Apple? No, I didn't think so. …]
2013-08-14 17:18:07,814-0400 | ERROR [Thread-25] TweetSplitterFunction.execute(22) | SPLITTING TWEET [RT @UncleTimi: "Bill Gates left education. So did Steve Jobs"
And?! Are you planning to create Microsoft or Apple? No, I didn't think so. …]