Skip to content

Instantly share code, notes, and snippets.

@kadirmalak
kadirmalak / currying-2.scala
Created December 28, 2019 15:56
currying syntax in scala
// notice that we first take 2 arguments and then a single argument
def betterWayToCurry(a: Int, b: String)(c: Double) = {
println("a: " + a + ", b: " + b + ", c: " + c)
}
val f2 = betterWayToCurry(1, "str") _ // first 2 params saved
f2(3.14) // now we can call using the third
@kadirmalak
kadirmalak / currying-1.scala
Created December 28, 2019 15:52
currying-1
def someFunc(a: Int, b: String, c: Double) = {
println("a: " + a + ", b: " + b + ", c: " + c)
}
someFunc(1, "str", 3.14) // we need all parameters to call it
// we're turning 3-arg function into 1-arg function
def someFuncCurried(a: Int, b: String) = {
def temp(c: Double) = {
someFunc(a, b, c) // a and b are remembered, only c is needed
import numpy as np
M1 = np.array([[1, 2], [3, 4], [5, 6]]) # matrix M1
M2 = np.array([[7], [8], [9]]) # matrix M2
M3 = np.c_[M1, M2] # combine
M4 = M3.T # transpose of M3
def createSomeSortOfComplicatedString(someImportantVariable: String, otherImportantThing: String) = {
val a = someImportantVariable
val b = otherImportantThing
s"""<a href="#" target="_blank" onclick="$a(); $b()">somestring</a>"""
}
class DBClient {
// ...
def createDBConnection(dbUsername: String, dbPassword: String, dbPort: Int, dbName: String) = {
// we're in a db context, are all those prefixes necessary?
}
def createConnection(user: String, pass: String, port: Int, db: String) = {
// more concise
def example1(trainInstances: Array[Array[Double]], trainLabels: Array[Double]) = {
// trainInstances and trainLabels are OK, but we could do better
}
def example2(xTrain: Array[Array[Double]], yTrain: Array[Double]) = {
// X is a common convention for instance list, x usually represents a single instance
// but just to stick to the camel case convention, we could not use X
// it's misleading
}
// long variables names are somewhat hiding the underlying equation.
// long method name is ok though.
def calculateSomethingImportant1(someImportantVariable: Int, someOtherImportantVarible: Double) = {
math.pow(someImportantVariable, 2) * someOtherImportantVarible + math.pow(someOtherImportantVarible, 2) + someImportantVariable
}
// it's more clear that the equation is x^2 y + y^2 x
def calculateSomethingImportant2(x: Int, y: Double) = {
math.pow(x, 2) * y + math.pow(y, 2) + x
}
#!/usr/bin/env bash
if [ "$#" -ne 4 ]; then
echo "usage: $0 <normal-label> <anomaly-label> <K-percent> <actual__predicted__confidence.csv>"
exit 1
fi
LABEL_0=$1
LABEL_1=$2
K=$3 # percent
@kadirmalak
kadirmalak / 6_CLOSE_012345_test.txt
Created March 19, 2019 11:59
export OMP_NUM_THREADS=6; export OMP_PROC_BIND="CLOSE"; export GOMP_CPU_AFFINITY="0 1 2 3 4 5"
> export OMP_NUM_THREADS=6
> export OMP_PROC_BIND="CLOSE"
> export GOMP_CPU_AFFINITY="0 1 2 3 4 5"
> ./runtests --gtest_filter="PlaygroundTests.FastScalar"
Note: Google Test filter = PlaygroundTests.FastScalar
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from PlaygroundTests
[ RUN ] PlaygroundTests.FastScalar
@kadirmalak
kadirmalak / OMP_NUM_THREADS_6_test.txt
Created March 19, 2019 08:43
export OMP_NUM_THREADS=6; ./runtests --gtest_filter="PlaygroundTests.FastScalar"
> export OMP_NUM_THREADS=6
> ./runtests --gtest_filter="PlaygroundTests.FastScalar"
Note: Google Test filter = PlaygroundTests.FastScalar
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from PlaygroundTests
[ RUN ] PlaygroundTests.FastScalar