Skip to content

Instantly share code, notes, and snippets.

View jpswain's full-sized avatar

Jamie Swain jpswain

View GitHub Profile
#!/Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -i -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
import Foundation
class JSON {
struct Path: Printable {
enum Element {
case Index(Int)
case Key(String)
@rnapier
rnapier / gist:b639da64d5890a0340d5
Last active October 26, 2015 20:50
Simple FFT example
import Accelerate
func spectrumForValues(signal: [Double]) -> [Double] {
// Find the largest power of two in our samples
let log2N = vDSP_Length(log2(Double(signal.count)))
let n = 1 << log2N
let fftLength = n / 2
// This is expensive; factor it out if you need to call this function a lot
let fftsetup = create_fftsetupD(log2N, FFTRadix(kFFTRadix2))
@platy
platy / ScheduledExecutor.scala
Created January 25, 2015 01:11
Scala wrapper around java's ScheduledExecutorService
import java.util.concurrent.ThreadPoolExecutor.AbortPolicy
import java.util.concurrent._
import scala.concurrent.{ Promise, Future }
import scala.concurrent.duration.FiniteDuration
import scala.language.implicitConversions
import scala.util.Try
object ScheduledExecutor {
private val defaultHandler: RejectedExecutionHandler = new AbortPolicy
@gigiigig
gigiigig / auxpattern.scala
Last active September 18, 2025 20:18
Aux Pattern
import shapeless._
import scalaz._
import Scalaz._
object console extends App {
trait Foo[A] {
type B
def value: B
@milessabin
milessabin / tuplegeneric.scala
Last active March 13, 2023 20:27
Convert (small enough) case classes to and from tuples using shapeless ...
import shapeless._
import ops.hlist.Tupler
trait TupleGeneric[C <: Product] extends Serializable {
type Repr <: Product
def to(t : C) : Repr
def from(r : Repr) : C
}
@tasdikrahman
tasdikrahman / python_tests_dir_structure.md
Last active February 10, 2025 22:15
Typical Directory structure for python tests

A Typical directory structure for running tests using unittest

Ref : stackoverflow

The best solution in my opinion is to use the unittest [command line interface][1] which will add the directory to the sys.path so you don't have to (done in the TestLoader class).

For example for a directory structure like this:

new_project

├── antigravity.py

@leandrob13
leandrob13 / SlickQueryOps.scala
Last active July 14, 2022 21:09
Trait that adds two functions to the slick Query type. I am using typelevel.cats as the functional library. Works for play-slick 3.1
trait SlickQueryOps {
databaseConfig: HasDatabaseConfig[ JdbcProfile ] =>
import cats.Apply
import cats.std.list._
import driver.api._
type BooleanOp = ( Rep[ Boolean ], Rep[ Boolean ] ) => Rep[ Boolean ]
implicit class OptionFilter[ X, Y ]( query: Query[ X, Y, Seq ] ) {
@mihow
mihow / load_dotenv.sh
Last active October 20, 2025 01:05
Load environment variables from dotenv / .env file in Bash
# The initial version
if [ ! -f .env ]
then
export $(cat .env | xargs)
fi
# My favorite from the comments. Thanks @richarddewit & others!
set -a && source .env && set +a