Skip to content

Instantly share code, notes, and snippets.


Mallory M. malzzz

  • Asymmetric Finance
  • /dev/null
View GitHub Profile
malzzz / CallbackExecutionContext.scala
Created Oct 31, 2017 — forked from viktorklang/CallbackExecutionContext.scala
Creates an ExecutionContext inside an Actor that will execute the runnables inside the Actor receive block, so that the risk of closing over Actor internals is less problematic.
View CallbackExecutionContext.scala
//Warning: Uses Akka internal APIs (not binary compatible),
//can be written not to depend on that but implemented like this for brevity.
package akka.util
trait CallbackExecutionContext { this:
// Defines our signal for callback execution
case object Execute
// ``SerializedSuspendableExecutionContext`` is Akka-internal
private[this] final val ssec: SerializedSuspendableExecutionContext = {
malzzz / Future-retry.scala
Created Oct 31, 2017 — forked from viktorklang/Future-retry.scala
Asynchronous retry for Future in Scala
View Future-retry.scala
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext
import scala.concurrent.Future
import akka.pattern.after
* Given an operation that produces a T, returns a Future containing the result of T, unless an exception is thrown,
* in which case the operation will be retried after _delay_ time, if there are more possible retries, which is configured through
* the _retries_ parameter. If the operation does not succeed and there is no retries left, the resulting Future will contain the last failure.
malzzz / gist:15639fc36d069490b7709be2f3a4d522
Last active Jul 20, 2021 — forked from Frozenfire92/gist:3627e38dc47ca581d6d024c14c1cf4a9
Install Scala 2.12.3 and SBT using apt-get on Ubuntu 16.04
View gist:15639fc36d069490b7709be2f3a4d522
## Java
sudo apt-get update
sudo apt-get install default-jdk
## Scala
sudo apt-get remove scala-library scala
sudo wget
sudo dpkg -i scala-2.12.3.deb
sudo apt-get update
sudo apt-get install scala
malzzz / convolution.scala
Last active Oct 2, 2016
Functional 2d convolution, less broken; i.e., works (I think). Probably slow af.
View convolution.scala
def conv2[A: ClassTag](input: Vector[A], kernel: Vector[A], padding: Int, stride: Int)(implicit ev: Numeric[A]) = {
// Static sizes
val inputHW = sqrt(input.length).toInt
val kernelHW = sqrt(kernel.length).toInt
val rowSizeAfterPad = inputHW + kernelHW - 1
val rowSizeStrided = rowSizeAfterPad + stride
val opsPerPass = rowSizeAfterPad / kernelHW
val passSize = kernelHW * rowSizeStrided
val inputSizePaddedStrided = (rowSizeStrided * inputHW) + (rowSizeStrided * 2)
malzzz / NArray.scala
Created Sep 28, 2016
Refactoring stuff, saving this for later
View NArray.scala
trait NArray[I, A] { self =>
def dims: List[Idx[I]]
def coords: data.Vector[A]
def resetCoords(v: data.Vector[A]): NArray[I, A] =
if (coords.dim == v.dim) {
new NArray[I, A] {
val dims = self.dims
val coords = v
View GoogLeNet.scala
import org.deeplearning4j.nn.api.OptimizationAlgorithm
import org.deeplearning4j.nn.conf._
import org.deeplearning4j.nn.conf.graph.MergeVertex
import org.deeplearning4j.nn.conf.layers._
import org.deeplearning4j.nn.weights.WeightInit
import org.nd4j.linalg.lossfunctions.LossFunctions
* GoogLeNet:
View gist:37784f06bb57b725c6ab
from tensorflow.models.embedding.word2vec_optimized import FLAGS, Options, Word2Vec
class MyOptions(Options):
def __init__(self):
super(MyOptions, self).__init__()
self.train_data = FLAGS1.train_data = "new_train_data"