Skip to content

Instantly share code, notes, and snippets.

View devsprint's full-sized avatar
🏠
Working from home

Gabriel Ciuloaica devsprint

🏠
Working from home
View GitHub Profile
object portfolio {
/**
* EXERCISE 1
*
* Using only sealed traits and case classes, develop a model of a stock
* exchange. Ensure there exist values for NASDAQ and NYSE.
*/
sealed trait Exchange
object Exchange {

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
@devsprint
devsprint / spark-thred-safe.scala
Last active September 10, 2015 11:53 — forked from ezhulenev/spark-thred-safe.scala
Thread-safe Spark Sql Context
object ServerSparkContext {
private[this] lazy val _sqlContext = {
val conf = new SparkConf()
.setAppName("....")
val sc = new SparkContext(conf)
// TODO: Bug in Spark: http://stackoverflow.com/questions/30323212
val ctx = new HiveContext(sc)
ctx.setConf("spark.sql.hive.convertMetastoreParquet", "false")
@devsprint
devsprint / gitw
Created June 18, 2015 12:36
Git client wrapper for wowapp
#!/bin/bash
# git client wrapper to be used with wowapp gitlab
git config user.name "Gabriel Ciuloaica"
git config user.email [email protected]
git "$@"
import spray.json._
import spray.http.HttpBody
import spray.httpx.marshalling._
import spray.httpx.unmarshalling._
import spray.http.MediaTypes._
import spray.routing.directives._
import spray.routing._
import spray.http._
import spray.json.DefaultJsonProtocol
import spray.httpx.SprayJsonSupport
@devsprint
devsprint / kafka.md
Created January 28, 2014 07:30 — forked from ashrithr/kafka.md

Introduction to Kafka

Kafka acts as a kind of write-ahead log (WAL) that records messages to a persistent store (disk) and allows subscribers to read and apply these changes to their own stores in a system appropriate time-frame.

Terminology:

  • Producers send messages to brokers
  • Consumers read messages from brokers
  • Messages are sent to a topic
package net.devsprint.reactive.cassandra;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import rx.Observable;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Session;
package net.devsprint.reactive.cassandra;
import java.util.concurrent.ExecutorService;
import rx.Observable;
import rx.Observer;
import rx.Subscription;
import rx.subscriptions.Subscriptions;
import com.datastax.driver.core.ResultSet;

slow

This bash script offers quick shortcuts to simulate slower network connections. It is useful when you need to simulate a wireless network on a Linux network server, especially when you are using a virtual machine guest on your local machine or in the cloud.

slow 3G                   # Slow network on default eth0 down to 3G wireless speeds
slow reset                # Reset connection for default eth0 to normal
slow vsat --latency=500ms # Simulate satellite internet  with a high latency
slow dsl -b 1mbps         # Simulate DSL with a slower speed than the default

slow modem-56k -d eth0 # Simulate a 56k modem on the eth1 device. eth0 is unchanged.

@devsprint
devsprint / gist:5363023
Last active November 3, 2020 02:51
Write a blob content to Cassandra using datastax\java-driver
private static String WRITE_STATEMENT = "INSERT INTO avatars (id, image_type, avatar) VALUES (?,?,?);";
private final BoundStatement writeStatement=writeStatement = session.prepare(WRITE_STATEMENT)
.setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM).bind();
try {
BoundStatement stmt = driver.getWriteStatement();
stmt.enableTracing();
stmt.setLong("id", accountId);
stmt.setString("image_type", image.getType());
stmt.setBytes("avatar", ByteBuffer.wrap(image.getBytes()));