Skip to content

Instantly share code, notes, and snippets.

View phderome's full-sized avatar

Philippe Derome phderome

  • Awake Security
  • Elora, ON
View GitHub Profile
@phderome
phderome / traverseExample.scala
Last active November 10, 2017 12:09
example of using traverse
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent._
import scala.concurrent.duration._
case class fourData(a: Int, b: Int, c: Int, d: Int)
val computeListInputs: List[Int] = List(1,2,3,4)
def slowBlockingComputation(input: Int)(implicit ec: ExecutionContext): Future[Int] = {
@phderome
phderome / Queens
Last active February 27, 2018 01:25
Solving Queens using Refined intervals
package code
import eu.timepit.refined._
import eu.timepit.refined.api.Refined
import eu.timepit.refined.auto._
import eu.timepit.refined.numeric._
import scala.annotation.tailrec
object RefinedQueens extends App {
@phderome
phderome / Knights.scala
Created February 18, 2018 20:49
7x7 chessboard Knight Tour
package code
import eu.timepit.refined._
import eu.timepit.refined.api.Refined
import eu.timepit.refined.auto._
import eu.timepit.refined.numeric._
import scala.annotation.tailrec
object Utils1 {
@phderome
phderome / Knights.scala
Last active February 22, 2018 14:48
Knight Tour with trampoline (in response to other gist that uses mutual recursion)
package code
import eu.timepit.refined._
import eu.timepit.refined.api.Refined
import eu.timepit.refined.auto._
import eu.timepit.refined.numeric._
import scala.annotation.tailrec
object KnightTourSolver extends App {
@phderome
phderome / ch6ex1excerpt.py
Created November 28, 2018 02:36
type-hinting-edge-case ch6ex1 FunctionalProgrammingInPythonV2
def fibi2(n: int) -> int:
"""Fibonacci numbers with iteration and memoization
>>> fibi2(20)
6765
>>> fibi2(1)
1
"""
# originally, line 109 had None (replace with Int as 0) f = [0, 1] + [None for _ in range(2, n+1)]
f = [0, 1] + [0 for _ in range(2, n+1)]
@phderome
phderome / queens.py
Last active January 27, 2019 15:28
a somewhat functional approach to Queens using Python
#!/bin/python3
from typing import *
from pymonad import curry
class Square(NamedTuple):
"""
represents a chessboard square indexed by row and col(short column), using 0-based indexing
"""
package com.fantasy.seed
import cats.{Apply, Functor, FunctorFilter, Invariant, Semigroupal}
import cats.implicits._
import monix.reactive._
trait Collector[F[_]] extends Apply[F] with FunctorFilter[F] {
def map[A, B, Z](fa: F[A], fb: F[B], f: Function1[(A, B), Z])(implicit inv: Invariant[F],
semi: Semigroupal[F]): F[Z] =