Skip to content

Instantly share code, notes, and snippets.

View fomkin's full-sized avatar
🎯
Focusing

Aleksey Fomkin fomkin

🎯
Focusing
View GitHub Profile
___________
/ \
| Warning ! |
\___________/
|
-------- __@ __@ | __@ __@ __~@
----- _`\<,_ _`\<,_ _`\<,_ _`\<,_ _`\<,_
---- (*)/ (*) (*)/ (*) (*)/ (*) (*)/ (*) (*)/ (*)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@fomkin
fomkin / gist:d721e5f4ca4f5b54dac3
Last active August 29, 2015 14:04
Simple function match3 in Scala
package com.tenderowls.opensource.match3
import scala.annotation.tailrec
/**
* @author Aleksey Fomkin <aleksey.fomkin@gmail.com>
*/
object Board {
sealed trait Direction
function processData(data) {
for(var i = 0; i < data.length; i++) {
var row = $('<tr></tr>')
.append($('<td>' + data[i].id + '</td>'))
.append($('<td>' + data[i].firstName + '</td>'))
.append($('<td>' + data[i].secondName + '</td>'));
if ($('showCountryCheckbox').checked) {
row.append($('<td>' + data[i].country + '</td>'));
}
$('table').append(row);
object HelloWorld extends Application with MKML {
val message = Var("Hello world")
def start() = {
div(
input(`value` =:= message),
span(message)
)
}
}
object Sum extends Application with MKML {
val a = Var("0")
val b = Var("0")
def start() = {
div(
input(`value` =:= a),
span(" + "),
input(`value` =:= b),
object ProgrammersBehaviorTestSuite extends TestSuite { // "Success"
val tests = TestSuite {
"When weather is fine it should" - { // "Success"
"go for a walk" - { assert(false) } // "Failure"
"go to ride a bike" - { assert(false) } // "Failure"
"drink tea on a terrace" - { assert(true) } // "Success"
}
}
}
val input = Vector("стационар", "соратница", "ватерполистка", "равновесие", "спаниель",
"кильватер", "полковник", "нерасторжимость", "Вениамин", "австралопитек", "своенравие",
"внимание", "апельсин", "вертикаль", "старорежимность", "клоповник",
"пенсионерка", "покраснение")
def anagrams(xs: Seq[String]): Seq[Seq[String]] = {
def wSum(s: String) = {
val ls = s.toLowerCase
val l = ls.length
(0 until l).map(ls.charAt).sum | l << 16
val utestSettings = Seq(
scalaJSStage in Test := FastOptStage,
persistLauncher in Test := false,
testFrameworks += new TestFramework("utest.runner.Framework"),
libraryDependencies += "com.lihaoyi" %%% "utest" % "0.3.1" % "test"
)
lazy val frontend = project.settings(utestSettings:_*)
// build.sbt:
//
// scalaVersion := "2.11.7"
//
// libraryDependencies ++= Seq(
// "com.github.fomkin" %% "scala-reql-akka" % "0.1.0-SNAPSHOT",
// "com.github.fomkin" %% "pushka-json" % "0.2.0",
// "com.typesafe.akka" %% "akka-actor" % "2.3.7"
// )
r.db("involve").table("authorization_codes").get(phoneNumber) update { doc ⇒
// Prepare query to SMSC
val sendSms = {
val params = s"phones=$phoneNumber&mes=$authorizationCode&fmt=3"
r.http(s"https://smsc.ru/sys/send.php?login=user&psw=******&$params")
}
// Check SMS limit is not reached
val timeIsOk = r.now().toEpochTime() - doc.getField("last_update").toEpochTime() > 3600
val countIsOk = doc.getField("count") < 3
// If is fine then execute request