Skip to content

Instantly share code, notes, and snippets.

package app.site
import org.apache.spark.graphx.{Edge, Graph}
import org.apache.spark.SparkContext
import org.apache.spark.sql.SparkSession
import org.apache.spark.rdd.RDD
object Sample {
def main(args: Array[String]): Unit = {
val spark = SparkSession
@barrettc
barrettc / matrix_rotate.rb
Last active August 29, 2015 14:20
Rotate a matrix 90 in place
# [[1, 2, 3, 4, 5],
# [6, 7, 8, 9, 10],
# [11, 12, 13, 14, 15],
# [16, 17, 18, 19, 20],
# [21, 22, 23, 24, 25]]
#input = [[1, 2, 3, 4],[5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]
input = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [21, 22, 23, 24, 25]]
# Transpose
for n in 0..input.length-2
@barrettc
barrettc / gist:6662530
Created September 22, 2013 18:30
Steps to upgrade from PostgreSQL 9.2.4 -> 9.3 using Homebrew
Jotting this down so I can reference in the future. These are the steps I followed to upgrade from 9.2.4 to 9.3.
1. brew upgrade postgresql
2. pg_ctl -D /usr/local/var/postgres stop -s -m fast
3. mv /usr/local/var/postgres /usr/local/var/postgres92
4. initdb /usr/local/var/postgres -E utf8
5. pg_upgrade -b /usr/local/Cellar/postgresql/9.2.4/bin -B /usr/local/Cellar/postgresql/9.3.0/bin -d /usr/local/var/postgres92 -D /usr/local/var/postgres
6. pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
@barrettc
barrettc / gist:6112327
Last active December 20, 2015 09:59
Assign random attribute to every record in collection
function setRandom() { db.skill.find().forEach(function (obj) {obj.random = Math.random();db.skill.save(obj);}); } db.eval(setRandom);
@barrettc
barrettc / gist:5587288
Created May 15, 2013 20:53
socket hang up
info: Creating snapshot 0.0.0-35
info Uploading: [=============================] 100%
error: Error running command deploy
error: Nodejitsu Error (500): Internal Server Error
error: socket hang up
help: For help with this error contact Nodejitsu Support:
help: webchat: <http://webchat.nodejitsu.com/>
help: irc: <irc://chat.freenode.net/#nodejitsu>
help: email: <support@nodejitsu.com>
help:
@barrettc
barrettc / gist:5587119
Created May 15, 2013 20:31
jitsu deploy problem
info: Creating snapshot 0.0.0-35
info Uploading: [=============================] 100%
error: Error running command deploy
error: Nodejitsu Error (500): Internal Server Error
error: npm http GET http://165.225.138.160:5984/registry/_design/app/_rewrite/request/2.21.0
npm http GET http://165.225.138.160:5984/registry/_design/app/_rewrite/time/0.9.2
npm http GET http://165.225.138.160:5984/registry/_design/app/_rewrite/redis/0.8.3
npm http GET http://165.225.138.160:5984/registry/_design/app/_rewrite/nodemailer/0.4.2
npm http GET http://165.225.138.160:5984/registry/_design/app/_rewrite/mongoose-pagination/1.0.0
npm http GET http://165.225.138.160:5984/registry/_design/app/_rewrite/express.io/1.1.9