Skip to content

Instantly share code, notes, and snippets.

View nartamonov's full-sized avatar

Nikolay Artamonov nartamonov

View GitHub Profile
#custom development
mariadb:
image: mariadb:latest
container_name: mariadb
env_file: ./database/.env
ports:
- "3306:3306"
volumes:
- /home/user/data/mariadb:/var/lib/mysql
@nartamonov
nartamonov / url-parsers.scala
Last active August 30, 2016 15:39
Пример парсера URL на parboiled2 (из доклада "No more regular expressions", см. https://skillsmatter.com/skillscasts/5847-no-more-regular-expressions)
import org.parboiled2._
import org.parboiled2.CharPredicate._
class URLParser(val input: ParserInput) extends Parser {
def URL = rule { URLPattern ~> UrlParts }
def URLPattern = rule { Scheme ~ "://" ~ Host ~ Port ~ Path ~ QueryParams }
def QueryParams = rule { '?' ~ oneOrMore(QPPair).separatedBy('&') ~> (kvs => Map(kvs: _*)) }
@nartamonov
nartamonov / Future.scala
Created July 13, 2016 12:57
Простая реализация монады Future и операций из стандартной библиотеки Scala
import java.util.concurrent.{Executor, Executors}
import java.util.concurrent.atomic.AtomicReference
import scala.annotation.tailrec
import scala.util.{Failure, Success, Try}
import scala.util.control.NonFatal
object Future {
def apply[T](expression: => T)(implicit executor: Executor) = new FutureImpl(expression)
}
@nartamonov
nartamonov / FRP.scala
Created July 8, 2016 12:34
Простейшая реализация FRP в виде сигналов, моделирующих значения, зависимые от времени.
/**
* Простейшая реализация FRP в виде сигналов, моделирующих значения, зависимые от времени.
*
* Из курса "Functional Program Design in Scala" (2016), Lecture 4.3
* https://www.coursera.org/learn/progfun2/lecture/5lWVa/lecture-4-3-a-simple-frp-implementation
*/
trait SimpleFRP {
class Signal[T](expr: => T) {
@nartamonov
nartamonov / queens.scala
Created July 7, 2016 10:55
Решение задачи о N ферзях для шахматной доски размером NxN
/**
* Решает задачу о N ферзях [1] для шахматной доски размером NxN.
*
* Возвращает множество возможных расстановок ферзей на шахматной доске,
* такие, чтобы ни один не находился под боем другого.
*
* Реализация основана на материале [2] курса
* "Functional Programming Principles in Scala" (2016), лекция 6.3.
*
* Источники:
@nartamonov
nartamonov / Bools.scala
Created June 1, 2016 10:07
How to define logical operation `not` without conditionals and OOP dispatching
object Bools extends App {
class Bool(negated: () => Bool) {
def not = negated()
}
val True: Bool = new Bool(() => False)
val False: Bool = new Bool(() => True)
assert(True == True)
assert(False == False)
@nartamonov
nartamonov / wait-response.py
Last active May 20, 2016 14:37
Waiting HTTP 200 from web service
#!/usr/bin/env python
# DEPENDENCIES:
# - requests
# Installation: aptitude install python-requests
import requests
import sys
from time import time, sleep
@nartamonov
nartamonov / Bar.scala
Created May 8, 2016 12:59 — forked from RichyHBM/Bar.scala
Avian executable with Scala example
//In subdirectory src/Foo
package Foo
object Bar {
val str = "Hello, world!"
}
@nartamonov
nartamonov / SassMeister-input-HTML.html
Created June 1, 2014 21:23
Generated by SassMeister.com.
<div id="container">
<h1>Hello Plunker!</h1>
<p>Привет, ребята!</p>
</div>
@nartamonov
nartamonov / gist:1362070
Created November 13, 2011 12:43
Selection sort in scala. Purely functional implementation with iterative behavior and using persistent collections.
def selectionSort[T <% Ordered[T]](seq: Seq[T]): Seq[T] = {
def pickMax(seq: Seq[T]): (T, Seq[T]) =
seq.tail.foldRight((seq.head, Seq.empty[T])) {
case (next, (max, passed)) =>
if (next > max)
(next, max +: passed)
else
(max, next +: passed)
}