Skip to content

Instantly share code, notes, and snippets.

@carymrobbins
carymrobbins / fetch-issues
Created March 14, 2015 17:02
Fetches GitHub issues and stores them into an "issues" directory.
#!/usr/bin/env python
# Requires the `ghi` command line tool (https://github.com/stephencelis/ghi)
# Be sure to generate an API token from GitHub via Settings > Applications > Generate New Token
import os
import commands
import re
import string
@carymrobbins
carymrobbins / pdf-decrypt
Last active April 8, 2017 21:50
Decrypt PDF files
#!/bin/bash
# This requires ghostscript. It can probably be installed via your package manager.
# e.g. `brew install ghostscript`
if [ $# -lt 2 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
cat <<HERE
Usage: $0 <file.pdf> [-p | <password>]
Creates a new file named 'file.pdf-decrypted.pdf'
@carymrobbins
carymrobbins / try-to-either.scala
Last active May 22, 2019 10:02
Implicit conversion of Try to Either in Scala.
trait ToEither[A, B] { def toEither: Either[A, B] }
implicit def tryToEither[A](t: Try[A]): ToEither[Throwable, A] = new ToEither[Throwable, A] {
def toEither = t.map(Right(_)).recover{ case e => Left(e) }.get
}
// Usage
scala> Try { "foo" }.toEither
res0: scala.util.Either[Throwable,String] = Right(foo)
@carymrobbins
carymrobbins / haskforce-repl.sh
Created April 23, 2015 04:06
Scala REPL for HaskForce development
#!/bin/bash
# Since OSX can't do `readlink -f` out of the box.
BASE_DIR=$(cd $(dirname $0) && echo $PWD)
IDEA_HOME=$(grep idea.home "$BASE_DIR/build.properties" | cut -d = -f 2)
IDEA_JARS=$(find "$IDEA_HOME/lib" -name "*.jar")
LOCAL_JARS=$(find "$BASE_DIR/lib" -name "*.jar")
PRODUCTION_CLASSES=$(find "$BASE_DIR/out/production" -maxdepth 1 -type d)
CLASSPATH=${IDEA_JARS//$'\n'/:}:${LOCAL_JARS//$'\n'/:}:${PRODUCTION_CLASSES//$'\n'/:}
/**
* Provides a .nullMap() method for Option which wraps potentially null results in an Option.
* Example:
* foo.getBar().getBaz() <- one of these might be null
* Option(foo).nullMap(_.getBar()).nullMap(_.getBaz()) <- returns None if any value was null.
*/
implicit class ToOptionNullMap[A](o: Option[A]) {
def nullMap[B](f: A => B): Option[B] = o.flatMap(a => Option(f(a)))
}
object SComboBoxMacro {
def impl(c: Context) = {
import c.universe._
Class.forName("javax.swing.JComboBox").getTypeParameters.length match {
case 1 => reify { javax.swing.JComboBox[Object] }
case 0 => reify { javax.swing.JComboBox }
}
}
type SComboBox = macro impl
package com.haskforce.ui;
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.event.AncestorListener;
import javax.swing.event.ListDataListener;
import javax.swing.event.PopupMenuListener;
import javax.swing.plaf.ComboBoxUI;
@carymrobbins
carymrobbins / flip
Last active August 29, 2015 14:20
Bash utility to flip the last two arguments of a command.
#!/bin/bash
# Flips the last two arguments
usage() {
echo "Usage: $0 <command arg1 arg2> [... argN]"
echo
echo "Flips the last two arguments of a command."
echo
echo "Example: \$ flip echo foo bar baz"
@carymrobbins
carymrobbins / SComboBox.scala
Created May 8, 2015 01:13
Macro to allow JComboBox to be used with JDK6+. SComboBoxMacro must be compiled in a separate target before its usage (e.g. before SComboBox). Note that you must use macro paradise for this to work.
package com.haskforce.ui
import javax.swing.JComboBox
/**
* Scala-friendly JComboBox; see [[SComboBoxMacro]] for more details.
*/
@SComboBoxMacro class SComboBox[E] extends JComboBox[E]
@carymrobbins
carymrobbins / TraceId.purs
Created May 13, 2015 03:00
traceId function for PureScript
foreign import traceId
"""
function traceId(string) {
return function(a) {
console.log(string);
return a;
};
}
""" :: forall a. String -> a -> a