Skip to content

Instantly share code, notes, and snippets.

@danslapman
danslapman / main.yml
Created March 1, 2017 14:11
Login to ecr
---
- name: Obtain Amazon ECR token
shell: |
docker run -i --rm \
-e "AWS_KEY={{ amazon_ecr_aws_key }}" \
-e "AWS_SECRET_KEY={{ amazon_ecr_aws_secret_key }}" \
opedge/awscli:latest \
aws ecr --region us-east-1 get-authorization-token
register: ecr_token_result
@danslapman
danslapman / aux.scala
Created December 7, 2016 19:08
Selectors
val book =
('author ->> "Benjamin Pierce") ::
('title ->> "Types and Programming Languages") ::
('id ->> 262162091) ::
('price ->> 44.11d) ::
HNil
def readBook[B <: HList](book:B)(implicit
author: Selector.Aux[B, Witness.`'author`.T, String],
title: Selector.Aux[B, Witness.`'title`.T, String],
@danslapman
danslapman / memoize.py
Created December 6, 2016 12:37
Python memoization decorator
__author__ = 'Daniil <danslapman> Smirnov'
__copyright__ = 'Copyleft 2013, danslapman'
__contact__ = 'https://bitbucket.org/danslapman/memoize'
def memoize(cache):
def memoize(fun):
def memoizator(*args, **kwargs):
if args in cache:
return cache[args]
else:
@danslapman
danslapman / state.scala
Created October 16, 2016 15:07
StateT as a monad
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
import scalaz.{Monad, StateT}
import scalaz.std.AllInstances._
object Test extends App {
implicit val ifsmi = StateT.stateTMonadState[Int, Future]
import ifsmi.{get, put}
@danslapman
danslapman / InlineOps.fs
Last active December 11, 2023 23:22
InlineOps
let inline is_null (x:^T when ^T : not struct) = obj.ReferenceEquals (x, null)
let inline (!>) (x:^a) : ^b = ((^a or ^b) : (static member op_Implicit : ^a -> ^b) x)
let inline (^) f x = f x
let inline (~%) x = ignore x
@danslapman
danslapman / LList.cs
Last active December 9, 2015 09:11
Immutable Linked List
using System.Collections;
using System.Collections.Generic;
namespace Immutable
{
public sealed class LList<T> : IReadOnlyCollection<T>
{
public T Head { get; }
public LList<T> Tail { get; }
public bool IsEmpty { get; }