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 play.api.libs.json._ | |
trait ConstEnumType[T] { self: T => | |
val name: String | |
val jsonKey: String = "type" | |
lazy val reads: Reads[T] = (JsPath \ jsonKey).read[String].filter(_ == name).map(_ => self) | |
lazy val matcher: PartialFunction[String, Option[T]] = { |
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
implicit class JoinableMap[K, V1](left: Map[K, V1]) { | |
def innerJoin[V2](right: Map[K, V2]): Map[K, (V1, V2)] = ( | |
for { | |
k <- (left.keySet & right.keySet).toSeq | |
l <- left.get(k) | |
r <- right.get(k) | |
} yield (k -> (l, r)) | |
).toMap | |
def leftJoin[V2](right: Map[K, V2]): Map[K, (V1, Option[V2])] = ( |
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
# Example: | |
# unenqueue '411a80c7-fbcf-4312-a504-ebddfdbf5b1f' | |
def unenqueue(runtime_id) | |
default_queue = Mimir::Runtime::WorkQueue.new | |
Redis.current.multi do | |
default_queue.upcoming.delete(runtime_id) | |
Redis.current.lpush(default_queue.in_progress.key, runtime_id) | |
end | |
end |
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 | |
# USAGE ./check-container.sh $CONATINER_ID | |
[[ "$(docker inspect --format='{{ .State.Running }}' --type=container $1)" == "true" ]] && exit 0 || exit 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
module Kernel | |
def it | |
(Class.new(BasicObject) { | |
def method_missing(name, *args) | |
@calls ||= [] | |
@calls << { name: name, args: args } | |
self | |
end | |
def to_proc | |
Proc.new do |rcv| |
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
# Creates directories and empty __init__.py files for the given python package in the current directory. | |
# Usage: | |
# pypkg a.python.package.name | |
pypkg () { | |
local pkgpath="$(echo $1 | sed 's:\.: :g')" | |
local fspath="." | |
for el in $pkgpath; do | |
fspath="${fspath}/${el}" | |
(mkdir "$fspath" && touch "${fspath}/__init__.py") &>/dev/null | |
done |
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
#!/usr/bin/env ruby | |
require 'shelly' | |
require 'shellwords' | |
include Shelly | |
$YELLOW = `tput setaf 3` | |
$BLUE = `tput setaf 4` | |
$WHITE = `tput setaf 7` | |
$RESET = `tput sgr0` |
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
"foo\uFFFF".each_char.to_a.collect(&:ord).reject { |x| x > 65000 }.collect(&:chr).join | |
# => "foo" |
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
begin | |
code_that_could_break | |
rescue SignalException => se | |
raise se | |
rescue Exception => e | |
puts e | |
end |
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 | |
# tputcolors | |
echo | |
echo -e "$(tput bold) reg bld und tput-command-colors$(tput sgr0)" | |
for i in $(seq 1 7); do | |
echo " $(tput setaf $i)Text$(tput sgr0) $(tput bold)$(tput setaf $i)Text$(tput sgr0) $(tput sgr 0 1)$(tput setaf $i)Text$(tput sgr0) \$(tput setaf $i)" | |
done |
NewerOlder