Skip to content

Instantly share code, notes, and snippets.

@darkseed
darkseed / durationFromMillisToHumanReadable.scala
Last active October 23, 2018 19:59
Time in milliseconds to human readable
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
@darkseed
darkseed / gatlingClusterRun.sh
Last active September 7, 2015 10:41 — forked from Nimrod007/gatlingClusterRun.sh
Gatling - running on multiple machines and aggregating the results
#!/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)
##################################################################################################################
@darkseed
darkseed / deepdream-install.md
Last active September 1, 2015 19:29 — forked from robertsdionne/deepdream-install.md
Deepdream installation
#!/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
@darkseed
darkseed / CorsSupport.scala
Last active August 29, 2015 14:28 — forked from joseraya/CorsSupport.scala
CORS directive for Spray
package com.agilogy.spray.cors
import spray.http.{HttpMethods, HttpMethod, HttpResponse, AllOrigins}
import spray.http.HttpHeaders._
import spray.http.HttpMethods._
import spray.routing._
// see also https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
trait CORSSupport {
this: HttpService =>
@darkseed
darkseed / nnet_plot_update.r
Last active August 29, 2015 14:26 — forked from fawda123/nnet_plot_update.r
nnet_plot_update
plot.nnet<-function(mod.in,nid=T,all.out=T,all.in=T,bias=T,wts.only=F,rel.rsc=5,
circle.cex=5,node.labs=T,var.labs=T,x.lab=NULL,y.lab=NULL,
line.stag=NULL,struct=NULL,cex.val=1,alpha.val=1,
circle.col='lightblue',pos.col='black',neg.col='grey',
bord.col='lightblue', max.sp = F,...){
require(scales)
#sanity checks
if('mlp' %in% class(mod.in)) warning('Bias layer not applicable for rsnns object')
import numpy as np
from scipy.spatial.distance import cdist
def nearest_neighbor(samples, targets, samples_to_classify, metric='euclidean'):
return targets[np.argmin(cdist(samples_to_classify, samples, metric=metric), axis=1)]
@darkseed
darkseed / getcolor.py
Last active February 25, 2017 10:25 — forked from zollinger/getcolor.py
import Image, ImageDraw
def get_colors(infile, outfile, numcolors=10, swatchsize=20, resize=150):
image = Image.open(infile)
image = image.resize((resize, resize))
result = image.convert('P', palette=Image.ADAPTIVE, colors=numcolors)
result.putalpha(0)
colors = result.getcolors(resize*resize)
@darkseed
darkseed / lm_example
Last active August 29, 2015 14:23 — forked from yoavg/lm_example
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# The unreasonable effectiveness of Character-level Language Models\n",
"## (and why RNNs are still cool)\n",
"\n",
"###[Yoav Goldberg](http://www.cs.biu.ac.il/~yogo)\n",
{
"tests": {
"buttoncolortst" : {
"description" : "Test which button color has a higher click-through.",
"version" : 1,
"rule" : null,
"constants" : {
},
"salt" : "buttoncolortst",
"buckets" : [ {
import sys
import numpy
from nltk.cluster import KMeansClusterer, GAAClusterer, euclidean_distance
import nltk.corpus
from nltk import decorators
import nltk.stem
stemmer_func = nltk.stem.EnglishStemmer().stem
stopwords = set(nltk.corpus.stopwords.words('english'))