Skip to content

Instantly share code, notes, and snippets.

View andyscott's full-sized avatar
🌲

Andy Scott andyscott

🌲
View GitHub Profile
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]) = {
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
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._
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) ⇒
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)
#!/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 () {
@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
@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",
before_deploy:
- mkdir deploy_staging
- cp */target/**/*.jar deploy_staging
deploy:
skip_cleanup: true
provider: s3
bucket: build-bucket
region: us-west-2
local-dir: deploy_staging
trait Magnetic[T] {
protected sealed trait TagMag
type Magnet = T @@ TagMag
protected implicit def tag(value: T) = Tag[T, TagMag](value)
def apply(mag: Magnet): T = mag
}
object CreateDescriptor extends Magnetic[CreateDescriptor] {
implicit def default(unit: Unit): Magnet = CreateDescriptor(None, AssetDescriptorRecord())
implicit def fromUser(user: ProfilePair): Magnet = CreateDescriptor(Some(user), AssetDescriptorRecord())