Skip to content

Instantly share code, notes, and snippets.

View penland365's full-sized avatar

Jeffrey N. Davis penland365

View GitHub Profile
@penland365
penland365 / ScalaTuples
Created April 28, 2014 21:03
While I understand the benefits of creating the named portions of a Tuple via OpenStruct, It's 5 lines to create versus one, and in most cases the extra information created by using named parameters isn't beneficial, since I'm wanting to use the Tuple as a dumb ( simple) data container.
// what I'd like to do
def primaryOperation(): Unit = {
// blah
// blah
val triforce = makeTriforce
val complexObject = new ComplexObject(
firstParam = somethingelse
secondParam = triforce._1
thirdParm = snakes
@penland365
penland365 / Curl output
Created September 19, 2014 14:29
SportsData LLC MLB Trial
curl -v https://api.sportsdatallc.org/mlb-t4/schedules/2014.json\?api_key\=[VALID_API_KEY]
* Adding handle: conn: 0x7fdb3b804000
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fdb3b804000) send_pipe: 1, recv_pipe: 0
* About to connect() to api.sportsdatallc.org port 443 (#0)
* Trying 23.23.158.219...
* Connected to api.sportsdatallc.org (23.23.158.219) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
@penland365
penland365 / SomeController.swift
Created May 15, 2015 15:43
Swift Either for handling mock data from Remote Api
class SomeController {
private func loadOfferSummaries() -> Void {
api.fetchOfferSummaries( { either in
switch either {
case let .Failure(boxedError):
NSLog("Failure fetching games, code --> \(boxedError.value.code)")
// mock out test data
self.offers = self.mockOfferSummaries()
self.loadTable()
case let .Success(boxed):
@penland365
penland365 / tmux-up
Created May 19, 2015 22:09
Basic Tmux Script
#! /usr/bin env bash
SESSION_NAME=""
tmux has-session -t $SESSION_NAME &> /dev/null
if [ $? -ne "0" ]
then
tmux new-session -d -s $SESSION_NAME
tmux split-window -h -p 40
tmux split-window -v -p 40
tmux send-keys -t 0 "vim" C-m
@penland365
penland365 / package.scala
Last active August 29, 2015 14:22
Super basic finch-client type layout.
package io.finch
import argonaut._, Argonaut._
import com.twitter.finagle.httpx.path.Path
package object client {
implicit def decodeStrResource: DecodeResource[String] = new DecodeResource[String] {
def apply(r: Resource): String = r.body
}
@penland365
penland365 / decode.scala
Created August 6, 2015 14:12
Argonaut decoding alternating JSON type
//In this case, we are decoding a type `Teams` from a third party service
//If `Teams` has any elements, the presented JSON is an Array of `Team`
//If `Teams` is empty, is is suppoed to be Optional. However, sometimes when `Teams` is empty the service returns an empty JSON object
import argonaut._, Argonaut._
case class Team(id: Int, name: String)
object Team {
implicit val decodeTeamJson: DecodeJson[Team] = { DecodeJson(h => for {
@penland365
penland365 / ServerDispatcher.scala
Last active December 8, 2015 20:26
Potential Finagle ServerDispatcher Annotations solution
package com.twitter.finagle.dispatch
import com.twitter.finagle.context.Contexts
import com.twitter.finagle.tracing.{Annotation, Trace}
import com.twitter.finagle.transport.Transport
import com.twitter.finagle.{Service, NoStacktrace, CancelledRequestException}
import com.twitter.util._
import java.util.concurrent.atomic.AtomicReference
import scala.collection.mutable.ListBuffer
@penland365
penland365 / Because git
Created October 23, 2013 18:22
The world's smallest script to delete files from git control.
git status | grep deleted | awk '{print $3}' | xargs git rm
@penland365
penland365 / gist:7892746
Created December 10, 2013 15:44
*.bz2 example
tar -jvcf email-xml-pairs.tar.bz2 /path/to/base
@penland365
penland365 / create-tar.bz2.sh
Created December 10, 2013 15:46
Email / XML tar command
tar -jvcf email-xml-pairs.tar.bz2 /path/to/base