Skip to content

Instantly share code, notes, and snippets.

View andyscott's full-sized avatar
🌲

Andy Scott andyscott

🌲
View GitHub Profile
@andyscott
andyscott / ParseFacebookUtils.podspec.json
Last active August 29, 2015 14:06
Hack to change FB version!
{
"name": "ParseFacebookUtils",
"version": "1.3.0",
"license": {
"type": "Commercial",
"text": "See https://www.parse.com/about/terms"
},
"homepage": "https://www.parse.com/",
"summary": "Parse is a complete technology stack to power your app's backend.",
"authors": "Parse",
@andyscott
andyscott / zoom.sh
Created September 23, 2015 16:35
zoom script for OSX
#!/usr/bin/osascript
# usage: zoom <room-number> [room-password] [--name=NAME]
on split(theString, theDelimiter)
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to theDelimiter
set theArray to every text item of theString
set AppleScript's text item delimiters to oldDelimiters
return theArray
#!/usr/bin/env bash
# find path to most recently updated simulator log
LOG_PATH=`find ~/Library/Logs/CoreSimulator/*/system.log -type f -print0 | xargs -0 stat -f "%m %N" |
sort -rn | head -1 | cut -f2- -d" "`
green=`tput setaf 2`
reset=`tput sgr0`
# formatter
FORMAT () {
val cl = // a valid ClassLoader
val classNames: List[String] =
classOf[String].getName :: "$$$$" :: List.getClass.getName :: Nil
type Acc = (List[Throwable], List[Class[_]])
val res = classNames.foldLeft((Nil, Nil): Acc) { (acc, className) ⇒
Try(Class.forName(className, true, cl)) match {
case Success(c) ⇒ (acc._1, c :: acc._2)
type F[U <: Universe] = (ToolBox[U], MyUtility[U]) ⇒ Unit
def example(f: F[_]) = {
val toolbox = scala.reflect.runtime.currentMirror.mkToolBox()
val util = MyUtility[toolbox.u.type](toolbox.u)
f(toolbox, util)
}
// usage, doesn't compile
example { (tb, util) ⇒
object DocCommentFinder {
def findByName[G <: Global](g: G)(rootTree: g.Tree, searchNames: Set[String]): Map[g.Symbol, g.DocComment] = {
import g.{ Try ⇒ _, _ }
val searchSymbols: Set[Symbol] = searchNames.map(name ⇒ g.rootMirror.staticModule(name))
findBySymbol(g)(rootTree, searchSymbols)
}
def findBySymbol[G <: Global](g: G)(rootTree: g.Tree, searchSymbols: Set[g.Symbol]): Map[g.Symbol, g.DocComment] = {
import g._
package fail.sauce.example123
import cats.Monad
import shapeless.{HList, HNil, ::}
import shapeless.Poly2
import shapeless.UnaryTCConstraint
import shapeless.UnaryTCConstraint.*->*
import shapeless.ops.hlist.RightFolder
import cats.arrow.NaturalTransformation
import cats.std.option._
import cats.syntax.cartesian._
implicit val opt2opt = NaturalTransformation.id[Option]
implicit def id2F[F[_]: Applicative] = new (Id ~> F) {
def apply[A](a: Id[A]): F[A] = Applicative[F].pure(a)
}
def foo[A: Order, F[_]: ~>[?[_], H], G[_]: ~>[?[_], H], H[_]: Applicative](f: F[A], g: G[A]) = {
// toying with some abstractions with akka
trait Pipeable[F[_]] {
def pipe(value: F[_], target: ActorRef)(implicit sender: ActorRef = ActorRef.noSender): Unit
}
object Pipeable extends PipeableImplicits {
def apply[F[_]](implicit ev: Pipeable[F]): Pipeable[F] = ev
}
sealed trait PipeableImplicits {

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x