Skip to content

Instantly share code, notes, and snippets.

View chadselph's full-sized avatar

Chad Selph chadselph

View GitHub Profile
@chadselph
chadselph / PlayAudio.scala
Created May 13, 2014 20:21
Audio Futures
import java.net.URL
import javax.sound.sampled.{AudioSystem, LineListener, LineEvent}
import scala.concurrent.{Promise, Future, Await}
import scala.concurrent.duration.Duration
object PlayAudio extends App {
val f = playUrl(
new URL("http://www.wavsource.com/snds_2014-05-05_4169601282614752/movies/airplane/wrong_week4.wav")
)
@chadselph
chadselph / Smppeezus.scala
Created May 13, 2014 20:31
smpp client to test binds
import java.net.{URL, InetSocketAddress}
import javax.sound.sampled.{AudioSystem, LineListener, LineEvent}
import scala.concurrent.{Promise, Future, Await}
import scala.concurrent.duration.Duration
import scala.concurrent.ExecutionContext.Implicits.global
import akkasmpp.actors.{SmppClient, SmppClientConfig}
import akkasmpp.protocol.{Pdu, BindTransceiverResp, CommandStatus, COctetString, DeliverSm, DeliverSmResp}
import akka.actor.ActorSystem
import akka.pattern.ask
@chadselph
chadselph / flaskwithcron.py
Last active April 21, 2022 10:20
flask with "cron"-like loop
from flask import Flask, render_template, jsonify, request
from threading import Timer, Thread
from time import sleep
app = Flask(__name__)
@app.route("/api/<method>")
def api(method):
data = {
@chadselph
chadselph / JacksonJsonSupport.scala
Created November 19, 2014 02:30
Spray JSON Support with Jackson
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper
import spray.http.{ContentTypes, HttpCharsets, HttpEntity, MediaTypes}
import spray.httpx.marshalling.Marshaller
import spray.httpx.unmarshalling.Unmarshaller
/**
* Use Jackson directly to avoid json4s's dependencies
*/
/**
* A command ID for SMPP
*/
trait FieldHelpers {
val className = getClass.getName.dropRight(1)
val missingLabel = "unknown"
object Test extends App {
trait BitPrinter[B <: BitDescription] {
def printBits(value: Long): (List[String], Long)
}
trait BitDescription
trait BitField extends BitDescription
@chadselph
chadselph / RubyTest.java
Created August 12, 2016 04:59
JRuby instance_evals
import org.jruby.embed.ScriptingContainer;
public class RubyTest {
public static void main(String[] args) {
ScriptingContainer container = new ScriptingContainer();
// From a string
Object myclassString = container.runScriptlet("" +
"class MyClass\n" +
@chadselph
chadselph / ApiFormats.scala
Last active November 8, 2016 02:28
trying to pass along the type of a PathMatcher to a abstract Route member
package gist.chadselph
import akka.http.scaladsl.server.PathMatcher
import akka.http.scaladsl.server._
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.util.ApplyConverter
/**
* Created by chad on 11/4/16.
*/
@chadselph
chadselph / AkkaHttpHeaderExtractor.scala
Last active July 3, 2022 16:04
akka-http directive for opentracing.io
import java.util
import java.util.Map.Entry
import akka.http.scaladsl.model.HttpHeader
import io.opentracing.propagation.TextMap
import scala.collection.JavaConverters.asJavaIteratorConverter
/**
* Used to extract an iterator of Entry[String, String] to the
@chadselph
chadselph / TaskQueue.scala
Last active January 6, 2017 06:04
tiny slick-based distributed task queue prototype
import java.sql.Timestamp
import java.time.{Duration, Instant}
import slick.driver.JdbcProfile
import slick.profile.SqlProfile.ColumnOption.Nullable
import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success}
/**