Skip to content

Instantly share code, notes, and snippets.

View malcolmgreaves's full-sized avatar

Malcolm Greaves malcolmgreaves

View GitHub Profile
@betehess
betehess / ammonite-shapeless
Created May 26, 2015 16:43
Using shapeless to drive Ammonite's PPrinter derivation, used to print shapeless values
> runMain ammonite.repl.Repl
[info] Running ammonite.repl.Repl
Loading Ammonite Repl...
@ load.ivy("com.chuusai" %% "shapeless" % "2.1.0")
@ import shapeless._
import shapeless._
@ 1 :: "lol" :: List(1, 2, 3) :: HNil
@manjuraj
manjuraj / scalaz-applicative.scala
Created July 9, 2015 06:01
scalaz applicative
//
// Apply extends the Functor Typeclass by adding a method `ap` which
// is similar to `map` from Functor in that it takes a functor that
// that has a function in it and another functor and extracts that
// function from the first functor and then maps it over the second
// one
//
// Alternatively, you can say `ap` lets you apply a function in a
// context to a value in a context
//
@manjuraj
manjuraj / scalaz.scala
Last active September 29, 2015 00:37
scalaz type constructors
//
// Foldable
// - fold a data structure
// - usually, fold F[A] given a Monoid[A]
//
trait Foldable[F[_]] { self =>
def foldRight[A, B](fa: F[A], z: => B)(f: (A, => B) => B): B
def foldLeft[A, B](fa: F[A], z: B)(f: (B, A) => B): B = {
@mefellows
mefellows / scala-travis-ci-sonatype-yml
Last active October 16, 2015 21:51
Scala - Travis CI Publish Sonatype YAML Sample
language: scala
scala:
- 2.10.4
jdk:
- oraclejdk8
- oraclejdk7
services: mongodb
script:
- sbt scoverage:test
- sbt coveralls
import scala.language.higherKinds
import scala.reflect.ClassTag
import scala.language.implicitConversions
trait Data[D[_]] extends Serializable {
def map[A, B: ClassTag](d: D[A])(f: A => B): D[B]
def flatMap[A, B: ClassTag](d: D[A])(f: A => Iterable[B]): D[B]
@travisbrown
travisbrown / FreeMacros.scala
Last active December 13, 2015 10:55
Quick sketch of a not very general implementation of boilerplate-free coyoneda'd constructors
import scala.language.experimental.macros
import scala.reflect.macros.whitebox
class FreeMacros(val c: whitebox.Context) {
import c.universe._
def smartName(name: String): String = (
name.toList match {
case h :: t => h.toLower :: t
case Nil => Nil
@tedsta
tedsta / deep_learn_xor.rs
Last active February 2, 2016 20:16
Example of untrained xor circuit using deeplearn-rs
extern crate deeplearn;
extern crate matrix;
use deeplearn::Graph;
use deeplearn::op::{MatMul, Relu};
fn main() {
let ctx = matrix::Context::new();
// Setup the graph
@krishnanraman
krishnanraman / RESULTS.txt
Last active February 13, 2016 22:23
Image Detection using Statistical Moments + KMeans dominant color + Binary SVM
Dataset: COREL subset ( 7 classes, 100 images per class => 7*100 = 700 jpgs )
COREL: https://sites.google.com/site/dctresearch/Home/content-based-image-retrieval
Training Test Ratio: 80-20
Equal number of true & false samples ie. train on 80 dinos & 80 random non-dinos out of 700-100 = 600 non-dinos.
So training sample size = 80 + 80 = 160
Test sample = 20 dinos + 20 non-dinos
Train 1 SVM classifier per class => 7 SVM classifiers
object DiffieHellmanMerkle {
import java.math.BigInteger
import scala.language.implicitConversions
import scala.util.Random
def main(args: Array[String]): Unit =
println(
diffieHellmanMerkle(generator = 3, modulus = 17, alicePrivateKey = 54, bobPrivateKey = 24)
)
@inanna-malick
inanna-malick / pusher.scala
Last active August 11, 2016 00:27 — forked from gre/pusher.scala
Using Pusher API with Play framework in scala for publishing events
//send messages via Pusher API in play 2.4
import play.api.libs.json.{ Writes, Json }
import play.api.libs.ws.{ WSResponse, WSClient }
import play.api.libs.ws.ning.NingWSClient
import java.security.MessageDigest
import java.math.BigInteger
import javax.crypto.Mac
import javax.crypto.spec.SecretKeySpec
import scala.concurrent.{ ExecutionContext, Future }