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
# install protobuf | |
sudo dnf install protobuf* | |
# install bazel | |
# https://docs.bazel.build/versions/master/install-redhat.html | |
sudo dnf copr enable vbatts/bazel | |
sudo dnf install bazel | |
# get TF src | |
git clone https://github.com/tensorflow/tensorflow.git |
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
#!/usr/bin/env python | |
print("Multiplication table") | |
for a in range(0, 11): | |
print("=============") | |
for b in range(0, 11): | |
print(str(a) + " x " + str(b) + " = " + str(a * b)) |
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 scala.concurrent._ | |
import ExecutionContext.Implicits.global | |
object Main extends App { | |
def repeatEvery[T](timeoutMillis: Int)(f: => T): Future[T] = { | |
val p = Promise[T]() | |
val never = p.future | |
f | |
def timeout = Future { |
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/sh | |
exec scala -Dscala.concurrent.context.minThreads=16 -Dscala.concurrent.context.maxThreads=64 "$0" "$@" | |
!# | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import scala.concurrent.duration._ | |
import java.util.concurrent.Executors | |
import scala.concurrent._ | |
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
type Set = Int => Boolean | |
val setOf_1: Set = (i: Int) => (i == 1) | |
val empty: Set = (i: Int) => false | |
val union: (Set, Set) => Set = | |
(s1: Set, s2: Set) => (i: Int) => s1(i) || s2(i) |
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
def take[A](xs: List[A], n: Int): List[A] = { | |
def loop(xy: List[A], rem: Int, accu: List[A]): List[A] = | |
if(rem <= 0) accu | |
else xy match { | |
case h :: t => loop(t, rem - 1, accu ::: List(h)) | |
case _ => accu | |
} | |
loop(xs, n, Nil) | |
} |
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
val add1 = (x: Int) => x + 1 | |
val add100 = (x: Int) => x + 100 | |
val square = (x: Int) => x * x | |
val allFunctions = List(add1, add100, square) |
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
val `namespace` = "namespace" | |
val `elementTerminator` = "elementTerminator" | |
val `openBracket` = "openBracket" | |
val `closeBracket` = "closeBracket" | |
// list of partial functions from list of strings to string: | |
val patterns = List[PartialFunction[List[String], String]]( | |
{ case `namespace` :: value :: `elementTerminator` :: rest => "case1" }, | |
{ case `openBracket` :: rest => "case2" }, | |
{ case `closeBracket` :: `elementTerminator` :: rest => "case3" }) |
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
case class Error(message: String) | |
case class User(id: Int, name: String, accountId: Int) | |
case class Account(id: Int, balance: Double) | |
case class Item(id: Int, title: String, price: Double) | |
case class Failures(isUserFailure: Boolean, isAccountFailure: Boolean, isItemFailure: Boolean) | |
def getUser(id: Int, fail: Boolean = false): Either[Error, User] = | |
if(fail) Left(Error(s"No such user: $id")) else Right(User(id, "Bob", 3)) | |
def getAccount(id: Int, fail: Boolean = false): Either[Error, Account] = |
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
# Prints % of total CPU and memory used in the system | |
# Requires psutil. Install with: | |
# `pip install psutil` | |
# or something like: | |
# `dnf install python3-psutil` | |
# Run with: | |
# `python3 profile_system.py` | |
# Ctrl + C to exit |