#!/usr/bin/env bash
# Assuming OS X Yosemite 10.10.4
# Install XCode and command line tools
# See https://itunes.apple.com/us/app/xcode/id497799835?mt=12#
# See https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/xcode-select.1.html
xcode-select --install
This file contains 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
/* | |
Copyright 2012 Twitter, Inc. | |
Licensed under the Apache License, Version 2.0 (the "License"); | |
you may not use this file except in compliance with the License. | |
You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software | |
distributed under the License is distributed on an "AS IS" BASIS, | |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
See the License for the specific language governing permissions and |
This file contains 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 breeze.linalg._ | |
import breeze.stats._ | |
import scala.math.sqrt | |
/** | |
* Effecient for sparse vectors. Scales in O(activeSize) | |
*/ | |
// Must take SparseVector, for implicits to be linked correctly | |
def pearson(a: SparseVector[Double], b: SparseVector[Double]): Double = { |
This file contains 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
// genrate all combinations of integers in range from 0 to `len`-1 | |
// fast as fuck | |
def combIdxs(len: Int, k: Int): Iterator[Array[Int]] = { | |
val arr = Array.range(0, k) | |
arr(k-1) -= 1 | |
val end = k-1 | |
Iterator.continually { | |
arr(end) += 1 | |
if (arr(end) >= len) { |
This file contains 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
// min-hash | |
val fs: Vector[Int => Int] // hash funkce | |
items map { it => fs map { f => f(it) } } fold (vectorPairwise(min), initialValue = Vector.fill(infinity)) | |
// HyperLogLog |
This file contains 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 breeze._ | |
import breeze.linalg._ | |
import breeze.numerics._ | |
import java.awt.image.BufferedImage | |
import javax.imageio.ImageIO | |
val f = ??? | |
val img = javax.imageio.ImageIO.read(new File(f)) | |
val gray = new BufferedImage(img.getWidth, img.getHeight, BufferedImage.TYPE_BYTE_GRAY) | |
val g = gray.createGraphics() |
This file contains 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 breeze.linalg._ | |
import breeze.stats | |
import breeze.numerics._ | |
val dataFile = new File(???) | |
val userItems: Array[SparseVector[Double]] = loaderUserItemsWithRatings(dataFile, """[ ,:]""".r) | |
val itemUsers: Array[SparseVector[Double]] = transpose(userItems) map { vec => normalize(vec, 2) } | |
// weights | |
val N = DenseVector.fill[Double](itemIndex.size)(userIndex.size) // vector where total numbers of users is repeated |
This file contains 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
package breeze.linalg.functions | |
import breeze.generic.UFunc | |
import breeze.linalg.{SparseVector, DenseVector} | |
import breeze.numerics.sqrt | |
/** | |
* A weighted Euclidean distance function implementation | |
*/ | |
object weightedEuclideanDistance extends UFunc { |
This file contains 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 durationFromMillisToHumanReadable(duration: Long):String = { | |
val milliseconds = duration % 1000L | |
val seconds = (duration / 1000L) % 60L | |
val minutes = (duration / (1000L*60L)) % 60L | |
val hours = (duration / (1000L*3600L)) % 24L | |
val days = (duration / (1000L*86400L)) % 7L | |
val weeks = (duration / (1000L*604800L)) % 4L | |
val months = (duration / (1000L*2592000L)) % 52L | |
val years = (duration / (1000L*31556952L)) % 10L | |
val decades = (duration / (1000L*31556952L*10L)) % 10L |
This file contains 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 | |
################################################################################################################## | |
#Gatling scale out/cluster run script: | |
#Before running this script some assumptions are made: | |
#1) Public keys were exchange inorder to ssh with no password promot (ssh-copy-id on all remotes) | |
#2) Check read/write permissions on all folders declared in this script. | |
#3) Gatling installation (GATLING_HOME variable) is the same on all hosts | |
#4) Assuming all hosts has the same user name (if not change in script) | |
################################################################################################################## |