Skip to content

Instantly share code, notes, and snippets.

@mjhb
mjhb / SmallCaps.swift
Last active December 29, 2017 18:20 — forked from liamnichols/SmallCaps.swift
An extension to simplify use of small caps within a UIFont object in Swift. Updated for Xcode-9.2
import UIKit.UIFont
public extension UIFont {
/// Helper method to create a UIFont with updated attributes applied to the UIFontDescriptor
///
/// - parameter attributes: The new attributes to apply to the fontDescriptor
///
/// - returns: A UIFont object with the new attributes appended to the receivers fontDescriptor
func addingAttributes(_ attributes: [UIFontDescriptor.AttributeName : Any] = [:]) -> UIFont {
@mjhb
mjhb / df_map.py
Created March 25, 2017 17:53
PySpark DataFrame map example
df2=df.rdd.map(lambda row: Row(**dict(row.asDict(), test_name=row.TEST_NAME.strip().lower()))).toDF()
@mjhb
mjhb / remote-puppet.sh
Created August 14, 2015 20:32
Execute puppet run on a list of remote hosts, when puppet daemon is not available
#!/bin/sh
LOG="puppet.log.`date +%Y-%m-%d.%H-%M-%S`"
OPTS="--server puppet.server.com --onetime --no-daemonize --verbose --detailed-exitcodes --color false"
while read HOST; do
echo "*** Processing $HOST" | tee -a $LOG
ssh -oBatchMode=yes -n $HOST "sudo puppet agent $OPTS 2>&1" 2>&1 | tee -a $LOG
done < hosts.txt
@mjhb
mjhb / build.sbt
Last active August 29, 2015 14:24
Uses sbt to start Scala REPL with Algebird loaded and imported. Run 'sbt console' to start (requires sbt)
scalacOptions in (Compile, console) ++= Seq(
"-i", "init.sc"
)
libraryDependencies ++= Seq(
"com.twitter" %% "algebird-core" % "0.10.2",
"com.twitter" %% "algebird-util" % "0.10.2",
"com.twitter" %% "algebird-bijection" % "0.10.2"
)
@mjhb
mjhb / cleveland-streamer.scala
Last active August 29, 2015 14:23
Simple Spark Streaming with Kafka Example
import org.apache.spark.streaming._
import org.apache.spark.streaming.kafka._
import org.apache.spark.{Logging, SparkConf}
import scala.language.implicitConversions
object SimpleStreamer extends Logging {
@mjhb
mjhb / installed-packages.sh
Last active August 29, 2015 14:14
List Explicitly Installed Packages for Ubuntu-based systems (might work on Debian)
# set to appropriate manifest for your distribution and version
MANIFEST=http://cdimage.ubuntu.com/lubuntu/releases/14.10/release/lubuntu-14.10-desktop-amd64.manifest
aptitude search '~i !~M' -F '%p' --disable-columns | sort -u > currentlyinstalled.txt
wget -qO - $MANIFEST | cut -f1 | sort -u > defaultinstalled.txt
comm -23 currentlyinstalled.txt defaultinstalled.txt
@mjhb
mjhb / solution1.py
Last active August 29, 2015 14:13
All consecutive non-overlapping tuples within a range
from itertools import combinations
[p for p in combinations([(i, i+1) for i in range(1,5)],2) if p[0][0] not in p[1] and p[0][1] not in p[1]]