Skip to content

Instantly share code, notes, and snippets.

Paul Phillips paulp

  • Unaccompanied
  • Bend, OR
Block or report user

Report or block paulp

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View app.hs
instance Monad f => Applicative (OptionalT f) where
pure = OptionalT . pure . Full
mf <*> ma = OptionalT $ do
optf <- runOptionalT mf
case optf of
Empty -> return Empty
Full f -> do
opta <- runOptionalT ma
return $ f <$> opta
View monad.hs
instance Monad f => Monad (OptionalT f) where
f =<< x = OptionalT $ runOptionalT x >>= \case
Empty -> return Empty
Full a -> runOptionalT $ f a
View gist:244846ffa026ac7bfed3bf57ea0398db
instance Monad f => Monad (OptionalT f) where
f =<< x = OptionalT $ runOptionalT x >>= \case
Empty -> return Empty
Full a -> runOptionalT $ f a
@paulp
paulp / chrome-dns
Created Aug 15, 2018
Visibility into chrome's internal dns
View chrome-dns
#!/usr/bin/env bash
#
output () {
pup 'tbody[id="dns-view-cache-tbody"] tr json{}' \
| jq -r '.[].children[] | select(.tag == "td").text' \
| ag --nocolor --literal .
}
@paulp
paulp / lazylist.scala
Last active Aug 15, 2018
interesting LazyList evaluation semantics
View lazylist.scala
% mscala -v 2.13.0-M4
Welcome to Scala 2.13.0-M4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_181).
Type in expressions for evaluation. Or try :help.
scala> val counter = {
| var count = 0
| () => {
| val res = try "x" + count finally count = count + 1
| try res finally println(res)
| }
View types.scala
object ttypes {
type ->[+A, +B] = (A, B)
type PairOf[+A] = A -> A
type SumOf[+A] = A \/ A
trait Interpret[T[_[_]]] {
type ^[Outer[_], Inner[_]] = Outer[T[Inner]]
trait Transform[F[_], G[_]] {
type FTF = F[T[F]]
View types.scala
/*
* Copyright 2014–2016 SlamData Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@paulp
paulp / Dockerfile
Created Mar 8, 2018
urbit dockerfile
View Dockerfile
FROM alpine:latest
ENV TERM="vt100" \
APK="apk add --no-cache" \
EDGEREPO="http://dl-3.alpinelinux.org/alpine/edge/testing"
WORKDIR /root
RUN $APK bash curl-dev gmp-dev libuv-dev ncurses-dev openssl-dev \
&& $APK --virtual .build-deps apk-tools file git g++ meson re2c \
&& $APK --repository $EDGEREPO libsigsegv-dev \
@paulp
paulp / macports-bin.sh
Created Mar 8, 2018
Mine macports sqlite database for package of origin for each program in /opt/local/bin.
View macports-bin.sh
#!/usr/bin/env bash
#
DB="/opt/local/var/macports/registry/registry.db"
QUERY="select ports.name,files.path
from files
inner join ports
on files.id=ports.id AND files.path GLOB '/opt/local/bin/*'"
sqlite3 -list -separator ' ' "$DB" "$QUERY" \
View clojurelist.scala
object Test {
type List[A] = Option[Cons[A]]
final case class Cons[A](hd: A, tl: Option[Cons[A]]) {
def nth(n: Int): A = if (n == 1) hd else tl.get nth n - 1
}
def list[A](xs: A*): List[A] = if (xs.isEmpty) None else Some(Cons(xs.head, list(xs.tail: _*)))
def single[A](hd: A): Cons[A] = Cons(hd, None)
// (nth (rest (cons 1 nil)) 1)
You can’t perform that action at this time.