Skip to content

Instantly share code, notes, and snippets.

💭
trolling craigslist for free pallets

Chris Martin chris-martin

💭
trolling craigslist for free pallets
Block or report user

Report or block chris-martin

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
@chris-martin
chris-martin / argonaut-lens.scala
Created Aug 26, 2015
Examples of using a lens to modify JSON with Argonaut http://argonaut.io/doc/zipper/
View argonaut-lens.scala
import argonaut._, Argonaut._
val obj: Json = Parse.parseOption("""{"a":{"b":"x","c":2}}""").get
val a = jObjectPL >=> jsonObjectPL("a") >=> jObjectPL
(a >=> jsonObjectPL("b") >=> jStringPL).mod(_ + "y", obj)
// res0: argonaut.Json = {"a":{"b":"xy","c":2}}
(a >=> jsonObjectPL("c") >=> jNumberPL)
View lens-vs-plens.md

LensFamily:

A Lens Family, offering a purely functional means to access and retrieve a field transitioning from type B1 to type B2 in a record simultaneously transitioning from type A1 to type A2. scalaz.Lens is a convenient alias for when A1 =:= A2, and B1 =:= B2.

The term "field" should not be interpreted restrictively to mean a member of a class. For example, a lens family can address membership of a Set.

PLensFamily:

Partial Lens Families, offering a purely functional means to access and retrieve an optional field transitioning from type B1 to type B2 in a record that is simultaneously transitioning from type A1 to type A2. scalaz.PLens is a convenient alias for when A1 =:= A2, and B1 =:= B2.

View select-angular.html
<div ng-app="app">
<div ng-controller="Ctrl1">
<select ng-model="foo" ng-options="o as o.name for o in options">
</select>
</div>
<div ng-controller="Ctrl2">
<select ng-model="foo" ng-options="o.id as o.name for o in options">
</select>
View listvectorlist.scala
scala> val a = List(Vector(1), List(1))
a: List[scala.collection.immutable.Seq[Int] with scala.collection.AbstractSeq[Int]{def companion: scala.coll
ection.generic.GenericCompanion[scala.collection.immutable.Seq with scala.collection.AbstractSeq{def dropRig
ht(n: Int): scala.collection.immutable.Seq[Any] with scala.collection.AbstractSeq[Any]; def takeRight(n: Int
): scala.collection.immutable.Seq[Any] with scala.collection.AbstractSeq[Any]; def drop(n: Int): scala.colle
ction.immutable.Seq[Any] with scala.collection.AbstractSeq[Any]; def take(n: Int): scala.collection.immutabl
e.Seq[Any] with scala.collection.AbstractSeq[Any]; def slice(from: Int,until: Int): scala.collection.immutab
le.Seq[Any] with scala.collection.AbstractSeq[Any]}]; def dropRight(n: Int): scala.collection.immutable.Seq[
Int] with scala.collection.AbstractSeq[In...
View ummutable.scala
val a = ListBuffer(1, 2, 3)
val b = a.toIterable.asInstanceOf[List[Int]]
// List(1, 2, 3)
a.append(4, 5, 6)
b
// List(1, 2, 3, 4, 5, 6)
View OptionalTest.java
package foo;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
public class OptionalTest {
static class Foo<T> {
View mixpanel_extra.py
from mixpanel import Mixpanel
import json
class MixpanelProject(object):
def __init__(self, token):
self.mixpanel = Mixpanel(token)
def cookie_name(self):
View lazy_init.py
class LazyInit(object):
def __init__(self, cls, *args, **kwargs):
self.wrapped = None
self.cls = cls
self.args = args
self.kwargs = kwargs
def __getattr__(self, key):
if self.wrapped is None:
View locking.py
from django.core.cache import cache
from contextlib import contextmanager
from datetime import timedelta
class LockUnavailable(Exception):
pass
class Lock(object):
View joinby.py
from django import template
register = template.Library()
@register.filter
def joinby(value, arg):
return arg.join(map(unicode, value))
You can’t perform that action at this time.