Skip to content

Instantly share code, notes, and snippets.

package daily
object BaumSweetSequence extends App {
def baumSweet(n: Int) =
if (n != 0 && n.toBinaryString
.split("1")
.exists(_.length % 2 == 1)) 0
else 1
@msval
msval / Euler3.scala
Created December 18, 2017 21:53
euler scala, solution to problem no.3
object Euler3 extends App {
val a = 600851475143l
def primes(n: Long, div: Long = 2, found: Vector[Long] = Vector.empty): Vector[Long] =
if (n % div == 0)
primes(n / div, div, found :+ div)
else if (div > (n / 2))
found :+ n
else
primes(n, div + 1, found)
@msval
msval / Euler2_imperative.scala
Created December 17, 2017 21:51
Euler 2 imperative way of thinking
object Euler2_imperative extends App {
var a = 0
var b = 1
var sum = 0
while (a + b < 4000000) {
if ((a + b) % 2 == 0) {
sum += a + b
}
@msval
msval / Euler2.scala
Last active December 18, 2017 07:36
Euler project - problem 2
object Euler2 extends App {
def fibs(a: Int, b:Int): Stream[Int] =
b #:: fibs(b, a + b)
val res = fibs(1, 1).
filter(_ % 2 == 0).
takeWhile(_ < 4000000).sum
println(res)
package com.msvaljek
import java.io.File
import org.apache.flink.api.scala._
object FindAndGroupStandingLocations {
def main(args: Array[String]) {
if ("skinny-3of12".equalsIgnoreCase(operation)) {
Select query = QueryBuilder.
select("activity_id", "start_time", "end_time").
from("activities").
where(eq("activity_id", bindMarker())).limit(1);
PreparedStatement select = session.prepare(query);
BoundStatement bstmt = new BoundStatement(select);
bstmt.bind(UUID.fromString("72b493f0-e59d-11e3-9bd6-0050568317e1"));
if ("skinny-3of12".equalsIgnoreCase(operation)) {
Select select = QueryBuilder.select(new String[] { "activity_id", "start_time", "end_time" }).from("activities");
select.where(QueryBuilder.eq("activity_id",
UUID.fromString("72b493f0-e59d-11e3-9bd6-0050568317e1")));
Activity3of12 a;
startTime = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
a = cassandraOps.selectOne(select, Activity3of12.class);
@msval
msval / animationinit
Created July 7, 2013 07:54
animationinit
// standard shim
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function( callback ) {
window.setTimeout(callback, 1000 / 60);
};
})();
@msval
msval / js multiline
Created May 31, 2013 20:57
javascript, js, multiline text
var html = (function () {/*
<!DOCTYPE html>
<html>
<body>
<h1>Hello, world!</h1>
</body>
</html>
*/}).toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1];
@msval
msval / doctype
Created January 2, 2013 13:47
Standard html doctypes
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd”>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>