This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
curl \ | |
--write-out "%{http_code},%{time_namelookup},%{time_appconnect},%{time_connect},%{time_appconnect},%{time_starttransfer},%{time_total}\n" \ | |
--silent \ | |
--output /dev/null \ | |
-L | |
"$1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Assumes that the branches already exist | |
#Assumes that files contain the contents of git log --format=oneline | |
import argparse | |
import json | |
parser = argparse.ArgumentParser(description='Phabricator orphan branch file generator') | |
parser.add_argument('original', help='The unmodified original branch git log') | |
parser.add_argument('orphan', help='The rebased --onto branch git log') | |
parser.add_argument('repository', help='The repository') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Field: | |
def __get__(self, obj, obj_type=None): | |
if not obj: | |
return self | |
return getattr(obj.view(), self.__name__) | |
def __set__(self, obj, value): | |
obj.update(self.__name__=value) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from weakref import WeakKeyDictionary | |
from collections.abc import Hashable | |
#Only works with hashable objects | |
class WriteOnce: | |
def __init__(self): | |
self.__values = WeakKeyDictionary() | |
def __get__(self, obj, obj_type=None): | |
if obj_type is not None: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Param: | |
'''Python descriptor for representing a query param within a url''' | |
def __init__(self, default=None, name=None, required=False): | |
self.default = str(default) | |
self.name = name | |
self.required = required | |
self.values = {} # in a real impl you'd use a WeakRefDict | |
def __set_name__(self, owner, name): | |
if not self.name: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Trying to transform | |
// def foo(value: Int) = something(value) } | |
//into | |
// def foo(value: Int) = { def defer$[A](f: => A) = { () => f }; something(defer$(value)) } | |
def mkDefer(methSym: Symbol): Tree ={ | |
val sym = methSym.newMethodSymbol(TermName("defer$"), newFlags = ARTIFACT) | |
val tpe = sym.newAbstractType(TypeName("A"), newFlags = PARAM) | |
tpe.setInfo(TypeBounds.empty) | |
val tref = typeRef(NoPrefix, tpe, Nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub vcl_hash { | |
set req.hash += req.url; | |
set req.hash += req.http.host; | |
if (req.http.request-method) { | |
set req.hash += req.http.request-method; | |
} | |
return (lookup); | |
} | |
sub vcl_miss { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats.data.Kleisli | |
import cats.Eval | |
type Partial[A, B] = Kleisli[Eval, A, B] | |
object Partial{ | |
def apply[A, S, B](f: (S, A) => B)(s: Eval[S]): Partial[A,B] = left(f)(s) | |
def right[A, S, B](f: (A, S) => B)(s: Eval[S]): Partial[A, B] = Kleisli(a => s.map(f(a, _))) | |
def left[A, S, B](f: (S, A) => B)(s: Eval[S]): Partial[A, B] = Kleisli(a => s.map(f(_, a))) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mapParams(methSym: Symbol, tree: DefDef) ={ | |
val DefDef(_, _, _, vp :: vps, _, _) = tree | |
val refTree = gen.mkAttributedRef(tree.symbol.owner.thisType, methSym) | |
val forwarderTree = (Apply(refTree, vp map forwardArg) /: vps){ | |
(fn, params) => Apply(fn, params map forwardArg) | |
} | |
deriveDefDef(tree)(_ => localTyper.typedPos(tree.symbol.pos)(forwarderTree)) | |
} | |
def forwardArg(param: Tree): Tree = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats.~> | |
//what would happen if you tried to make a continuation based on natural transforms... | |
abstract class ContK[F[_], G[_], R]{ self => | |
def apply(fg: F ~> G): G[R] | |
def map[B](f: R => B)(implicit fn: Functor[G]) = new ContK[F, G, B]{ | |
def apply(fg: F ~> G) = fn.map(self(fg))(f) | |
} | |
NewerOlder