This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
while true | |
do | |
run_interval="5" # how many seconds between checks | |
active_vpn=$(nmcli con show | grep 4e99cc84-a234-4bc5-bc69-44df89b33fff | grep ens160) | |
if ! [ "${active_vpn}" ]; | |
then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql: | |
image: mysql:latest | |
environment: | |
- MYSQL_ROOT_PASSWORD=123 | |
- MYSQL_DATABASE=test_db | |
- MYSQL_USER=myuser | |
- MYSQL_PASSWORD=123 | |
volumes: | |
- ./data:/docker-entrypoint-initdb.d | |
- ./MySQL/database:/var/lib/mysql:rw |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static SessionFactory factory; | |
private static ServiceRegistry serviceRegistry; | |
public static SessionFactory createSessionFactory() { | |
Configuration configuration = | |
new Configuration() | |
.configure() | |
.addAnnotatedClass(Employee.class); | |
serviceRegistry = new ServiceRegistryBuilder().applySettings( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.ibm.icu.text.DateFormat; | |
import com.ibm.icu.util.Calendar; | |
public class TestJalali { | |
public static void main(String[] args) { | |
org.joda.time.base.AbstractInstant time = new org.joda.time.DateTime(1471590261000L); | |
System.out.println(time); | |
com.ibm.icu.util.ULocale locale = new com.ibm.icu.util.ULocale("fa_IR@calendar=persian"); | |
com.ibm.icu.util.Calendar c = Calendar.getInstance(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.sql.Timestamp | |
import java.text.SimpleDateFormat | |
import org.apache.spark.sql.SQLContext | |
import org.apache.spark.{SparkConf, SparkContext} | |
case class Record(time: java.sql.Timestamp) | |
object TimeStampExample extends App { | |
val sc = new SparkContext(new SparkConf().setAppName("app").setMaster("local")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object monadLaws extends App { | |
// To qualify as a monald, a type has to satisfy three laws: | |
// Associativity | |
// (m flatMap f) flatMap g = m flatMap (x => f(x) flatMap g) | |
val f = (a: Int) => List(a) | |
val g = (a: Int) => List(a - 1, a + 1) | |
val m1 = 1 to 2 | |
val r1 = m1 flatMap f flatMap g |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object forTranslationRules extends App { | |
val l1 = 1 to 4 | |
val l2 = 3 to 7 | |
val l3 = 2 to 8 | |
// Simple generator | |
val a1 = for (a <- l1) yield a * 2 | |
val a2 = l1 map (_ * 2) | |
assert(a1 == a2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object convertMapToFlatMap extends App { | |
val list = 1 to 10 | |
var res1 = list map (_ * 2) | |
val f = (a: Int) => a * 2 | |
val unit = (a: Int) => List(a) | |
val res2 = list flatMap (f andThen unit) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait BaseTrait extends Product with Serializable | |
case class AT(name: String) extends BaseTrait | |
case class BT(age: Int) extends BaseTrait | |
val listA = AT("a1") :: AT("a2") :: Nil | |
val listB = BT(1) :: BT(2) :: Nil | |
val list = listA ++ listB | |
val res = sc.parallelize(list.toSeq).toDS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Bar(i: Int) { | |
override def toString = s"bar $i" | |
def bar = i | |
} | |
object BarEncoders { | |
implicit def barEncoder: org.apache.spark.sql.Encoder[Bar] = org.apache.spark.sql.Encoders.kryo[Bar] | |
} | |
abstract class Foo |