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 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 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 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 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
| // 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 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
| #redundancy is the max number of survivable failures, so eg 1 for RAID5 | |
| #mtbf_array is an array of either actual mean-time-between-failures, or a nested RAID array | |
| # RAID([100]*7,2) #7 disk RAID 6 | |
| # RAID([RAID([100]*3,1),RAID([1000]*3,1)],0) # RAID 50, 2 arrays of 3 | |
| # RAID([100,100,50,50],1) #RAID 5 with varying reliabilities | |
| from random import random | |
| class RAID(object): |
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
| #include <sys/xattr.h> | |
| /// Set a flag that the files shouldn't be backuped to iCloud. | |
| + (void)addSkipBackupAttributeToFile:(NSString *)filePath { | |
| u_int8_t b = 1; | |
| setxattr([filePath fileSystemRepresentation], "com.apple.MobileBackup", &b, 1, 0, 0); | |
| } | |
| /// Returns the legacy storage path, used when the com.apple.MobileBackup file attribute is not available. | |
| + (NSString *)legacyStoragePath { |
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
| var donutVal = 85; | |
| var donutFull = 100 - donutVal; | |
| var d3_category_socialmedia = ["#0054a6", "#dbdbdb"]; | |
| if(donutVal < 50) { | |
| donutVal = -donutVal; | |
| donutFull = -donutFull; |
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
| -- This is a Hive program. Hive is an SQL-like language that compiles | |
| -- into Hadoop Map/Reduce jobs. It's very popular among analysts at | |
| -- Facebook, because it allows them to query enormous Hadoop data | |
| -- stores using a language much like SQL. | |
| -- Our logs are stored on the Hadoop Distributed File System, in the | |
| -- directory /logs/randomhacks.net/access. They're ordinary Apache | |
| -- logs in *.gz format. | |
| -- | |
| -- We want to pretend that these gzipped log files are a database table, |
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
| -- This is a Hive program. Hive is an SQL-like language that compiles | |
| -- into Hadoop Map/Reduce jobs. It's very popular among analysts at | |
| -- Facebook, because it allows them to query enormous Hadoop data | |
| -- stores using a language much like SQL. | |
| -- Our logs are stored on the Hadoop Distributed File System, in the | |
| -- directory /logs/randomhacks.net/access. They're ordinary Apache | |
| -- logs in *.gz format. | |
| -- | |
| -- We want to pretend that these gzipped log files are a database table, |
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
| """ | |
| realertime.lib.spawn | |
| ~~~~~~~~~~~~~~~~~~~~ | |
| :author: Adam Hitchcock | |
| :copyright: (c) 2012 DISQUS. | |
| :license: Apache License 2.0, see LICENSE for more details. | |
| """ | |
| from __future__ import absolute_import |
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
| from pylab import * | |
| from numpy.random import dirichlet, rand, binomial, uniform, normal | |
| def _unit_weight(dim): | |
| return ones(dim) / float(dim) | |
| ONE_FRAC = 0.5 | |
| SQRT_TWO_INV = 1.0 / sqrt(2.0) | |
| def _feature_vec(dim, method="bernoulli"): | |
| if method == "bernoulli": |
OlderNewer