Skip to content

Instantly share code, notes, and snippets.

@aparrish
aparrish / understanding-word-vectors.ipynb
Last active Aug 1, 2021
Understanding word vectors: A tutorial for "Reading and Writing Electronic Text," a class I teach at ITP. (Python 2.7) Code examples released under CC0 https://creativecommons.org/choose/zero/, other text released under CC BY 4.0 https://creativecommons.org/licenses/by/4.0/
View understanding-word-vectors.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@umbertogriffo
umbertogriffo / Transpose.scala
Created Oct 26, 2016
Utility Methods to Transpose a org.apache.spark.mllib.linalg.distributed.RowMatrix
View Transpose.scala
def transposeRowMatrix(m: RowMatrix): RowMatrix = {
val transposedRowsRDD = m.rows.zipWithIndex.map{case (row, rowIndex) => rowToTransposedTriplet(row, rowIndex)}
.flatMap(x => x) // now we have triplets (newRowIndex, (newColIndex, value))
.groupByKey
.sortByKey().map(_._2) // sort rows and remove row indexes
.map(buildRow) // restore order of elements in each row and remove column indexes
new RowMatrix(transposedRowsRDD)
}
def rowToTransposedTriplet(row: Vector, rowIndex: Long): Array[(Long, (Long, Double))] = {
anonymous
anonymous / index.html
Created Mar 7, 2015
qExGJZ
View index.html
<div class="trans">
Black scale:
<div class="main t1">lightest</div>
<div class="main t2">lighter</div>
<div class="main t3">light</div>
<div class="main t4">normal</div>
<div class="main t5">dark</div>
<div class="main t6">darker</div>
<div class="main t7">darkest</div>
</div>
View fractals.asm.js
fractalModule =function(stdlib){
"use asm";
var pow = stdlib.Math.pow;
var abs = stdlib.Math.abs;
var atan2 = stdlib.Math.atan2;
var cos = stdlib.Math.cos;
var sin = stdlib.Math.sin;
function mandlebrot(cx, cy, maxIter) {
cx = +cx;
cy = +cy;
anonymous
anonymous / debug-toolbox.js
Created Dec 22, 2012
Developer tools window to debug toolbox open in current tab.
View debug-toolbox.js
/*
* Running this scratchpad will open a Developer Tools window that's debugging
* the currently selected tab's toolbox.
*/
Cu.import("resource:///modules/devtools/Target.jsm");
let target = TargetFactory.forTab(gBrowser.selectedTab);
let toolboxToDebug = gDevTools.getToolbox(target);
let tbTarget = TargetFactory.forWindow(toolboxToDebug.frame.contentWindow);
@robinsloan
robinsloan / langoliers.rb
Last active Jul 27, 2021
The Langoliers, a tweet deletion script
View langoliers.rb
require "rubygems"
require "twitter"
require "json"
# things you must configure
TWITTER_USER = "your_username"
MAX_AGE_IN_DAYS = 1 # anything older than this is deleted
# get these from dev.twitter.com
CONSUMER_KEY = "your_consumer_key"
View scratchpad.js
/*
TODO:
- zoom level menu
- need to find a way to re-start the update
- add color tools
- integrate better in Firefox
- crosshair has a 1px offset
*/
@nrabinowitz
nrabinowitz / quantize.js
Created Jul 25, 2011
Javascript module for color quantization, based on Leptonica
View quantize.js
/*!
* quantize.js Copyright 2008 Nick Rabinowitz.
* Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
*/
// fill out a couple protovis dependencies
/*!
* Block below copied from Protovis: http://mbostock.github.com/protovis/
* Copyright 2010 Stanford Visualization Group
* Licensed under the BSD License: http://www.opensource.org/licenses/bsd-license.php