Skip to content

Instantly share code, notes, and snippets.

View tpgmeligmeyling's full-sized avatar

Thomas Gmelig Meyling tpgmeligmeyling

View GitHub Profile
/// Prefix operator to turn a KeyPath into a function
prefix operator ~
/// Allows a key path to be passed into mapping functions
///
/// e.g. people.map(~\.name)
///
prefix func ~<A, B>(_ keyPath: KeyPath<A, B>) -> (A) -> B {
return { $0[keyPath: keyPath] }
}
@guifromrio
guifromrio / compress-pdf-with-gs.md
Created August 30, 2013 14:39
Compress PDF files with ghostscript

This can reduce files to ~15% of their size (2.3M to 345K, in one case) with no obvious degradation of quality.

ghostscript -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

Other options for PDFSETTINGS:

  • /screen selects low-resolution output similar to the Acrobat Distiller "Screen Optimized" setting.
  • /ebook selects medium-resolution output similar to the Acrobat Distiller "eBook" setting.
  • /printer selects output similar to the Acrobat Distiller "Print Optimized" setting.
  • /prepress selects output similar to Acrobat Distiller "Prepress Optimized" setting.
@seadowg
seadowg / Semaphore.scala
Created May 20, 2012 13:32
Semaphore implementation with Scala's synchronized
class Semaphore(private var count : Int) {
def p() {
synchronized {
while (count < 1) {}
count = count - 1
}
}
def v() {
synchronized {