Skip to content

Instantly share code, notes, and snippets.

View LMnet's full-sized avatar

Yuriy Badalyants LMnet

View GitHub Profile
@LMnet
LMnet / ErrorFactory.js
Last active December 26, 2015 04:59
Gist for creating custom error objects, with inheritance, factory-function and instanceof functionality.
/**
* Custom Error classes factory
* Usage:
* var MyError = ErrorFactory('MyError');
* try{
* throw new MyError('my error text'); //or throw MyError('my error text');
* }catch(e){
* if(e instanceof MyError){
* console.log('This is my error!');
* }
@LMnet
LMnet / syncTimeout.js
Created October 24, 2013 04:40
Synchronous JavaScript timeout.
/**
* Synchronous timeout
* @param {Integer} delay Delay in milliseconds
*/
var syncTimeout = function(delay){
var endTime = new Date((new Date()).getTime() + delay);
var curTime;
do {
curTime = new Date();
}while(curTime.getTime() <= endTime.getTime());
@LMnet
LMnet / ExtraPropertiesToMapConverter.groovy
Last active August 29, 2015 14:05
Transparently set properties in resources through gradle extra properties
/**
* Convert extra properties with multilevel nesting into simple map.
* Each nesting level is separated by '.'.
*
* For example, this:
* <pre>
* ext {
* elem1 = 'val1'
* elem2 = 'val2'
* lev1 = [
----- Esc -----
Quick change directory: Esc + c
Quick change directory history: Esc + c and then Esc + h
Quick change directory previous entry: Esc + c and then Esc + p
Command line history: Esc + h
Command line previous command: Esc + p
View change: Esc + t (each time you do this shortcut a new directory view will appear)
Print current working directory in command line: Esc + a
Switch between background command line and MC: Ctrl + o
Search/Go to directory in active panel: Esc + s / Ctrl + s then start typing directory name
@LMnet
LMnet / pushka.scala
Created April 1, 2016 05:07
Error with inheritance in pushka
import pushka.json._
import pushka.annotation.pushka
@pushka
sealed trait TraitA
object TraitA {
sealed trait TraitB extends TraitA
def debounce(wait: FiniteDuration)(f: ⇒ Unit): () ⇒ Unit = {
var lastStartTime = Long.MinValue
var finishTime = lastStartTime + wait.toMillis
() ⇒ {
val now = System.currentTimeMillis()
val ready = finishTime <= now
lastStartTime = now
finishTime = lastStartTime + wait.toMillis
import scala.concurrent.{ExecutionContext, Future}
/**
* Takes care of computations
*
* Success(either) - the computation will be continued.
* Failure(error) - the computation was failed with unhandled error.
*
* Either[Result, T]:
* Left(result) is a final and handled result, another computations (map, flatMap) will be ignored.
@LMnet
LMnet / KafkaSenderConfig.scala
Created September 15, 2017 09:23
KafkaSenderConfig.scala
object KafkaSender {
sealed trait Config
object Config {
case class WithPublishing(url: String, queueSize: Int) extends Config
case object WithoutPublishing extends Config
}
}
implicit val kafkaSenderConfigConvert: ConfigConvert[KafkaSender.Config] = {
val key = "publishing"
@LMnet
LMnet / CronSource.scala
Last active October 9, 2017 07:55
CronSource.scala
package ru.dgis.casino.sharpy
import java.util.Date
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.{AtomicBoolean, AtomicReference}
import akka.actor.Cancellable
import akka.stream.scaladsl.Source
import akka.stream.stage.{AsyncCallback, GraphStageLogic, GraphStageWithMaterializedValue, OutHandler, StageLogging, TimerGraphStageLogic}
import akka.stream.{Attributes, Outlet, SourceShape}
@LMnet
LMnet / links
Created November 27, 2017 13:45
For scalameta speach