Skip to content

Instantly share code, notes, and snippets.

@momania
momania / DateUtil.scala
Created January 14, 2020 17:15
Simple Scala date util to get all week days between two given dates
import java.time.{DayOfWeek, LocalDate}
object DateUtil {
@inline private def isWeekend(d: LocalDate): Boolean = {
d.getDayOfWeek == DayOfWeek.SATURDAY || d.getDayOfWeek == DayOfWeek.SUNDAY
}
def businessDayStream(from: LocalDate, to: LocalDate): Stream[LocalDate] = {
Stream.iterate(from)(_.plusDays(1)).filterNot(isWeekend).takeWhile(_.isBefore(to))
@momania
momania / nvidia-smi-exporter.service
Last active February 22, 2018 13:44
Setup of nvidia smi exporter for prometheus
[Unit]
Description=nvidia smi epxorter
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/nvidia-smi-exporter
[Install]
WantedBy=multi-user.target
@momania
momania / cool_gpu2.sh
Last active February 7, 2018 10:58 — forked from squadbox/cool_gpu2.sh
A script to control Nvidia GPU fan speed on headless (non-X) linux nodes
#!/bin/bash
# cool_gpu2.sh This script will enable or disable fixed gpu fan speed
#
# Description: A script to control GPU fan speed on headless (non-X) linux nodes
# Original Script by Axel Kohlmeyer <[email protected]>
# https://sites.google.com/site/akohlmey/random-hacks/nvidia-gpu-coolness
#
# Modified for newer drivers and removed old work-arounds
@momania
momania / gist:1379932
Created November 20, 2011 07:35
CoffeePot Cake
object CoffeePot extends App {
ComponentRegistry.coffeeWarmer.trigger
}
trait OnOffDevice {
def on: Unit
def off: Unit
}
trait SensorDevice {
@momania
momania / MySlf4jEventHandler.scala
Created August 29, 2011 12:05
Single line logging evenhandler
package com.acme.logging
import akka.actor.Actor
import akka.event.EventHandler
import akka.event.slf4j.{Logger, Logging}
class MySlf4jEventHandler extends Actor with Logging {
import EventHandler._
self.id = ID
@momania
momania / gist:959172
Created May 6, 2011 15:33
Extractor pattern matching in partial function
object ExtractionTest extends Application {
case object Message
case class Event(event: Any, data: Int)
def partialWithNormalCase: PartialFunction[Event, Int] = {
case Event(Message, 1) => 1
case Event(Message, 2) => 2
}
@momania
momania / gist:896062
Created March 31, 2011 09:01
Over engineered Akka FSM scala Swing undecorated dialog using shapes and fading (why? because we can!)
package notification
import com.sun.awt.AWTUtilities
import java.awt.geom.RoundRectangle2D
import org.jdesktop.animation.timing.{TimingTarget, Animator}
import swing._
import event.MouseClicked
import com.efgfp.creditspy.util.GuiUtil
import akka.actor.{FSM, Actor}
import org.jdesktop.animation.timing.Animator.{Direction, RepeatBehavior}
@momania
momania / gist:858476
Created March 7, 2011 13:05
Akka AMQP Loadbalance
import akka.amqp.AMQP._
import akka.amqp._
import akka.actor._
import java.util.concurrent.{TimeUnit, CountDownLatch}
import util.Random
object LoadBalancingDemo {
def main(args: Array[String]) {
@momania
momania / gist:715371
Created November 25, 2010 13:15
Simple FSM Lock
package samples.fsm.lock
import java.util.concurrent.TimeUnit
import TimeUnit._
import akka.actor.{ActorRegistry, FSM, Actor}
sealed trait LockState
case object Locked extends LockState
case object Open extends LockState
@momania
momania / gist:713819
Created November 24, 2010 15:30
Updated HeartMonitor
import akka.actor.{Actor, FSM}
import java.util.concurrent.TimeUnit
sealed trait Health
case object Stale extends Health
case object Alive extends Health
case object Dead extends Health
case object HeartBeat