Skip to content

Instantly share code, notes, and snippets.

View toff63's full-sized avatar

Christophe Marchal toff63

View GitHub Profile
/**
* In Scala it is a good practice to keep configuration in traits.
* The main reason is that you can easily override them programmatically
* using the fact that the last trait imported to a class will win in case of override
*/
// Default configuration
trait Configuration {
lazy val defaultName:String = "default"
}
create window HomeStatus.win:length(1) as (status string);
insert into HomeStatus select 'ok' as status 
from BedroomTemperatureStatus as bedroom ,
HallTemperatureStatus as hall
where bedroom.status = hall.status and bedroom.status = 'ok';

insert into HomeStatus select 'warning' as status 
from BedroomTemperatureStatus as bedroom ,
 HallTemperatureStatus as hall
create window HallTemperatureStatus.win:length(1) as (status string);

insert into HallTemperatureStatus select 'warning' as status from HallTemperature(temperature > 18 and temperature <=22);
insert into HallTemperatureStatus select 'alert' as status from HallTemperature(temperature <= 18);
insert into HallTemperatureStatus select 'ok' as status from HallTemperature(temperature > 22);

create window BedroomTemperatureStatus.win:length(1) as (status string) ;

insert into BedroomTemperatureStatus select 'warning' as status from BedroomTemperature(temperature &gt; 18 and temperature &lt;=22);
create schema Temperature(place string, temperature double);

create window HallTemperature.win:length(2) as Temperature;
insert into HallTemperature select * from Temperature(place='hall');

create window BedroomTemperature.win:length(2) as Temperature;
insert into BedroomTemperature select * from Temperature(place='bedroom');
create schema Temperature(place string, temperature double);
        
create window HallTemperature.win:length(1) as Temperature;
insert into HallTemperature select * from Temperature(place='hall');
        
create window HallTemperatureStatus.win:length(1) as (status string);
        
insert into HallTemperatureStatus select 'warning' as status from HallTemperature(temperature > 18 and temperature <=22);
insert into HallTemperatureStatus select 'alert' as status from HallTemperature(temperature <= 18);
@toff63
toff63 / RunningActors.scala
Created November 25, 2015 13:21
List of Running Actors
class RunningActors extends Actor with ActorLogging {
def receive = {
case "start" =>
log.info("Current Actors in system:")
self ! ActorPath.fromString("akka://Streams/user/")
case path: ActorPath =>
context.actorSelection(path / "*") ! Identify(())

Install conscript

As I use cygwin

curl https://raw.githubusercontent.com/n8han/conscript/master/setup.sh | sh
mv ~/.conscript/sbt-launch-0.13.7.jar ~/.conscript/sbt-launch.jar

Then edit $HOME/bin/cs

java -jar "cygpath -m "$HOME/.conscript/sbt-launch.jar"" "@file:///C:/Users/PUT_YOUR_USERNAME/.conscript/n8han/conscript/cs/launchconfig" "$@"

A workaround is to manually force every VM to use the host's resolver with VBoxManage modifyvm "VM name" --natdnshostresolver1 on or to modify the guest's /etc/resolv.conf file with an external nameserver.

SSH tunnel using putty

In the menu go to Connection -> SSH -> Tunnels

  • Select Dynamic below destination
  • Put 1024 as source port
  • Click on Add

Login.

SSH tunnel using ssh

import java.io.File
import scala.io.Source
import org.apache.log4j.Logger
import org.apache.log4j.Level
import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._