Skip to content

Instantly share code, notes, and snippets.

View iha2's full-sized avatar

Iheatu Wogu iha2

  • Founder@Recursive.House
  • Toronto
View GitHub Profile
name := "HiClusterer"
version := "1.0"
scalaVersion := "2.10.6"
resolvers += "spray repo" at "http://repo.spray.io"
resolvers += "spray nightlies" at "http://nightlies.spray.io"
@iha2
iha2 / FileInfoContainer.scala
Last active January 4, 2017 04:50
HiClustering Tutorial Snippents
case class DataContainer(columnHeaders: Vector[String], rows: Vector[Vector[Option[Double]]])
def processFile = {
val lines = importFile(file)
val columnHeaders = lines.head.split("\\s *").toVector
val vectorLength = columnHeaders.length
val rows = lines.tail.zipWithIndex.map { case (x, i) =>
val cells = x.split("\\s *")
cells match {
case x if ( x.length != vectorLength ) => {
println("There is missing data in row " + i + ". Skipping..")
class PureHiCluster(clusters: Vector[Cluster], distances: Map[(String, String), Double]) {
def generateClusterCalculations(clusters: Vector[Cluster], distances: Map[(String, String), Double], pairData: PairData) = {
def loop(clusters: Vector[Cluster], futureResults: List[Future[(Map[(String, String), Double], PairData)]]): List[Future[(Map[(String, String), Double], PairData)]] =
clusters match {
case Vector() => futureResults
case x +: xs => loop(xs, Future[(Map[(String, String), Double], PairData)] { computeDistances(clusters.dropWhile { y => y.id != x.id}, distances, x, pairData) } +: futureResults)
}
loop(clusters, List())
@iha2
iha2 / package.json
Last active December 27, 2017 00:43
A package.json file for setting up Angular.js, Typescript and Jest.
{
"name": "webpack-jest",
"version": "1.0.0",
"description": "jest, webpack and typescript",
"main": "src/main.ts",
"scripts": {
"test": "jest"
},
"repository": {
"type": "git",
import 'jest-preset-angular';
@iha2
iha2 / webcam-observable.ts
Last active August 12, 2018 22:04
An implementation of a webcam processed by an observable.
export function initializeWebcam(
videoElem: HTMLVideoElement,
canvasElement: HTMLCanvasElement
) {
return createWebcam(videoElem).pipe(
switchMap(_ =>
timer(0, 40).pipe(
map(() => drawImageOnCanvas(videoElem, canvasElement))
)
)
@iha2
iha2 / initiate-webcam.ts
Created August 12, 2018 21:10
initiate a webcam and turn it into an observable.
import { timer, Subject, from, Observable } from 'rxjs';
export function createWebcam(webcam: HTMLVideoElement): Observable<{}> {
return from(
new Promise<{}>((resolve, reject) => {
if (navigator.getUserMedia) {
navigator.getUserMedia(
{ video: true },
stream => {
webcam.srcObject = stream;
@iha2
iha2 / draw-image.ts
Created August 12, 2018 21:13
draw image on canvas.
const drawImageOnCanvas = (
videoElem: HTMLVideoElement,
canvasElem: HTMLCanvasElement
) => {
const ctx = canvasElem.getContext('2d') as CanvasRenderingContext2D;
const canvasResolution = 224;
ctx.drawImage(videoElem, 224, 0, size, size, 0, 0, 224, 224);
};
@iha2
iha2 / webcam-react-component.ts
Last active August 12, 2018 21:27
A React component made to host a video element drawn on a canvas
<React.Fragment>
<video
ref={(videoElementRef: HTMLVideoElement) =>
(videoElement = videoElementRef)
}
autoPlay={true}
playsInline={true}
muted={true}
style={{ visibility: 'hidden', position: 'fixed' }}
/>