Skip to content

Instantly share code, notes, and snippets.

@squito
squito / AccumulatorListener.scala
Last active March 15, 2019 06:34
Accumulator Examples
import scala.collection.mutable.Map
import org.apache.spark.{Accumulator, AccumulatorParam, SparkContext}
import org.apache.spark.scheduler.{SparkListenerStageCompleted, SparkListener}
import org.apache.spark.SparkContext._
/**
* just print out the values for all accumulators from the stage.
* you will only get updates from *named* accumulators, though
@wpf500
wpf500 / log-search.py
Created January 9, 2015 17:29
For AWS CloudWatch Logs. Finds the log streams with in a log group that contain log events for a given time and display the relevant logs
#!/usr/bin/python
import sys, boto.logs, time
from datetime import datetime
log_group = 'LOG GROUP NAME'
timestamp = int(datetime.strptime(sys.argv[1], '%Y-%m-%dT%H:%M:%S').strftime('%s')) * 1000
logs = boto.logs.connect_to_region('eu-west-1')
if len(sys.argv) > 2:
@mkrcah
mkrcah / zkDelAll.py
Last active November 8, 2020 03:25
Remove all ZooKeeper nodes according to a given path template, see http://stackoverflow.com/questions/25052245/zookeeper-cli-wildcard-support
import sys
from kazoo.client import KazooClient
if len(sys.argv) not in (2,3):
print('Usage: zkDelAll.py [path] [host:port=localhost:2181]')
exit(1)
host = sys.argv[2] if len(sys.argv) == 3 else 'localhost:2181'
path = sys.argv[1]
@samklr
samklr / MovingAvgSpark.scala
Created December 11, 2014 16:10
Moving Average on stock prices in Spark with custom partitioner
val ts = sc.parallelize(0 to 100, 10)
val window = 3
class StraightPartitioner(p: Int) extends Partitioner {
def numPartitions = p
def getPartition(key: Int) = key * p/0.5
}
val partitioned = ts.mapPartitionsWithIndex((i, p) => {
val overlap = p.take(window - 1).toArray
#!/bin/bash
# Usage: ./gen.sh collected-stacks.txt
TMPSTACKS=/tmp/flamegraph-stacks-collapsed.txt
TMPPALETTE=/tmp/flamegraph-palette.map
./stackcollapse-jstack.pl $1 > $TMPSTACKS
# 1st run - hot: default
@nicolasembleton
nicolasembleton / restart_bluetooth.sh
Last active March 13, 2026 16:50
Restart Bluetooth Daemon on Mac OS X without restarting
#!/bin/bash
sudo kextunload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
sudo kextload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
@acolyer
acolyer / service-checklist.md
Last active May 26, 2026 20:51
Internet Scale Services Checklist

Internet Scale Services Checklist

A checklist for designing and developing internet scale services, inspired by James Hamilton's 2007 paper "On Desgining and Deploying Internet-Scale Services."

Basic tenets

  • Does the design expect failures to happen regularly and handle them gracefully?
  • Have we kept things as simple as possible?
@bigsnarfdude
bigsnarfdude / gist:ff6b20026a903b9d321c
Created September 28, 2014 08:04
Spark Algebird Qtree
// transcribed from an Apache Spark 1.0 spark-shell session
// using data from http://chriswhong.com/open-data/foil_nyc_taxi/
// and the QTree algorithm for approximate quantiles over large datasets
// each of the distanceRange and minutesRange calculations below takes about 15 minutes on my four-core SSD-based Macbook Pro
import com.twitter.algebird._
import com.twitter.algebird.Operators._
implicit val qtSemigroupD = new QTreeSemigroup[Double](6)
val in = sc.textFile("trip_data") // a directory containing all the trip_data*.csv files downloaded from the above link
@debasishg
debasishg / gist:b4df1648d3f1776abdff
Last active June 20, 2025 13:59
another attempt to organize my ML readings ..
  1. Feature Learning
  1. Deep Learning
@asimjalis
asimjalis / TotalOrderPartitionerExample.java
Created September 25, 2014 07:50
Demonstrates how to use Total Order Partitioner on Word Count.
import java.io.*;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.fs.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.mapreduce.lib.input.*;
import org.apache.hadoop.mapreduce.lib.output.*;
import org.apache.hadoop.mapreduce.lib.partition.*;
import org.apache.hadoop.mapreduce.lib.reduce.*;