Skip to content

Instantly share code, notes, and snippets.

View TomTriple's full-sized avatar

TomTriple TomTriple

  • Germany, near Munich
View GitHub Profile
package zio.http
import zio.ZIO
sealed trait QueryParam[+A] { self =>
def flatMap[B](f: A => QueryParam[B]):QueryParam[B] = QueryParam.FlatMap(self, f)
def map[B](f: A => B):QueryParam[B] = self.flatMap(a => QueryParam.succeed(f(a)))
package zio.http
import zio.schema.Schema
import zio.schema.codec.JsonCodec
import java.net.URLDecoder
sealed trait Flash[+A] { self =>
def flatMap[B](f: A => Flash[B]):Flash[B] = Flash.FlatMap(self, f)
import cats.effect._
import cats.implicits._
import cats.data.State
import cats.data.OptionT
import cats.Functor
import cats.data.EitherT
import cats.kernel.Order
object Test extends IOApp {
@TomTriple
TomTriple / bashscript.sh
Created November 12, 2016 14:54
bash_script.example
#####################################################################
# 1. the input for the script at (2) -- e.g. from a database query
#####################################################################
#
# client_addr | count
#----------------+-------
# 172.217.16.35 | 45
# | 1
# 62.153.159.92 | 15
# 217.72.219.144 | 24
@TomTriple
TomTriple / producer_consumer.java
Created November 12, 2016 14:44
producer/consumer example based on wait/notify
package com.mobidat.wp2.missionserviceImpl;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.location.Location;
import android.support.annotation.Nullable;
import android.util.Log;
import com.mobidat.dao.IDaoMission;
import com.mobidat.dao.IDaoMissionData;
@TomTriple
TomTriple / combinator_android_validation.scala
Last active November 12, 2016 14:43
combinator library android validation
// the highlevel validation combinators reside at the bottom of this gist e.g. "def crown" or "def trunk"
protected object Validation {
sealed abstract class VRes[+A]
case class Vok[+A](get:A) extends VRes[A]
case class Verr(err:String) extends VRes[Nothing]
type V[+A] = TextView => VRes[A]
@TomTriple
TomTriple / combinator_db_results.scala
Created November 12, 2016 14:37
scala combinator library for db results
// 1. combinator library for transforming and combining sql results to query result models
// 2. usage of library resides at the bottom of this gist
package object mapping {
type Mapper[+A] = String => A
type ToValueClass[+A] = Long => A
def sendPdf(htmlContent: String, filename: String) = {
val os = new java.io.ByteArrayOutputStream
val renderer = new ITextRenderer
renderer.setDocumentFromString(htmlContent)
renderer.layout
renderer.createPDF(os)
val bytes = os.toByteArray()
os.flush()
class ConsoleImage
def initialize(m, n)
@m = m
@n = n
@colors = Array.new(m * n)
clear
end
def clear
@TomTriple
TomTriple / gist:1304235
Created October 21, 2011 16:13
java <-> jruby
include Java
include_class "java.util.ArrayList"
list = ArrayList.new
block = Proc.new do
add "entry 1"
add "entry 2"
end
list.instance_eval &block
pp list.get(1)