Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am lemonxah on github.
  • I am lemonxah (https://keybase.io/lemonxah) on keybase.
  • I have a public key ASBPKUv1ZJq8dx5ecT66xbt_Yy_QZYRv5OQpp3sH6LCHCgo

To claim this, I am signing this object:

object ops {
implicit class SemigroupOps[F](val self: F)(implicit val F: Semigroup[F]) {
def |+|(other: => F): F = F.combine(self, other)
}
}
import ops._
trait Semigroup[A] {
@lemonxah
lemonxah / Option.cs
Created August 15, 2016 12:55
Option Monad example for C#
using System;
namespace Functional {
public class GetOnEmptyOptionException : Exception { }
public interface Some { }
public interface None { }
public abstract class Option {
public static bool operator ==(Option a, Option b) =>
!ReferenceEquals(a, null) && !ReferenceEquals(b, null) && a.Equals(b);
public static bool operator !=(Option a, Option b) => !(a == b);
public static Option<A> None<A>() => new None<A>();
package com.fullfacing.queue
import java.io.{ByteArrayOutputStream, ByteArrayInputStream}
import java.util.Properties
import java.util.concurrent.ConcurrentHashMap
import java.util.zip._
import akka.actor.ActorRef
import com.fullfacing.framework.Security
import com.fullfacing.message.{Response, Request, Retry}
trait ModelWithId[A] { def copy(id: Option[String]):A }
trait Model { def deleted: Boolean; def id: Option[String] }
trait DAO[A <: Model, B, C, Q] {
def interpreter(q: Query, empty: Q): Throwable \/ Q
def insert(a: A)(implicit m: Mappable[A, B, C], ev: A ⇒ ModelWithId[A]): A
def insertRaw(b: B)
def list(skip: Int = 0, limit: Int = 0)(implicit m: Mappable[A, B, C]): Vector[A]
def filter(query: Query, skip: Int = 0, limit: Int = 0)(implicit m: Mappable[A, B, C]): Vector[A]
def headOption(query: Query)(implicit m: Mappable[A, B, C]): Option[A]
class MongoDAO[A <: Model](coll: MongoCollection) extends DAO[A, DBObject, DBObject, DBObject] {
import MongoInterpreter._
def interpreter(q: Query, empty: DBObject = new MongoDBObject()): Option[DBObject] = {
try { Some(implicitly[Writer[Query, DBObject]].write(q)) } catch { case e: Exception => None }
}
override def list(limit: Int = 0)(implicit m: Mappable[A, DBObject, DBObject]): Vector[A] = {
coll.find().limit(limit).toVector.map(m.fromDBType)
}
package com.fullfacing.test
import java.text.DecimalFormat
import com.fullfacing.network.{TcpClient, Execution}
import org.slf4j.LoggerFactory
import scala.concurrent.{Await, Promise, ExecutionContext, Future}
import scala.language.implicitConversions
package com.fullfacing.dao
import com.fullfacing.ticketing.macros.Mappable
import scala.language.higherKinds
/**
* Project: dbabspro
* Created on 2015/05/19.
* ryno aka lemonxah -
* https://github.com/lemonxah
# nvidia-xconfig: X configuration file generated by nvidia-xconfig
# nvidia-xconfig: version 340.76 (buildmeister@swio-display-x86-rhel47-01) Thu Jan 22 12:12:24 PST 2015
Section "ServerLayout"
Identifier "Layout0"
Screen 0 "Screen0" 0 0
InputDevice "Keyboard0" "CoreKeyboard"
InputDevice "Mouse0" "CorePointer"
EndSection
local/lib32-nvidia-340xx-libgl 340.76-1
NVIDIA drivers libraries symlinks (32-bit)
local/lib32-nvidia-340xx-utils 340.76-1
NVIDIA drivers utilities (32-bit)
local/libvdpau 1.1-1
Nvidia VDPAU library
local/nvidia-340xx 340.76-7
NVIDIA drivers for linux, 340xx legacy branch
local/nvidia-340xx-libgl 340.76-2
NVIDIA drivers libraries symlinks