Skip to content

Instantly share code, notes, and snippets.

@anthonynsimon
anthonynsimon / binary_tree.rb
Last active April 7, 2016 09:33
Simple Binary Tree in Ruby
class Node
attr_accessor :value, :left, :right
def initialize(value=nil)
@value = value
end
end
class BinaryTree
attr_accessor :root, :num_loops
@anthonynsimon
anthonynsimon / btree.go
Last active April 7, 2016 09:37
Simple Binary Tree in Go
package btree
import (
"fmt"
)
type BinaryTree struct {
Root *Node
NumberOfIterations int
}
@anthonynsimon
anthonynsimon / linkedList.c
Last active April 12, 2016 12:00
Quick and dirty linked list in C
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int value;
struct node* next;
} node_t;
typedef struct list {
node_t* head;
package main
import (
"bufio"
"fmt"
"log"
"net"
"io"
)
@anthonynsimon
anthonynsimon / prepend_timestamp.sh
Created March 8, 2017 16:15
Bash script preprend timestamp to filename
#!/bin/bash
for f in *; do mv -- "$f" "$(stat -f "%Sm_%N" -t "%Y%m%d" "$f")"; done
@anthonynsimon
anthonynsimon / Dockerfile
Created April 25, 2017 15:08
Spark cluster
FROM openjdk:8
RUN mkdir -p /usr/local/spark && \
cd /usr/local/spark && \
curl -O http://d3kbcqa49mib13.cloudfront.net/spark-2.1.0-bin-hadoop2.7.tgz && \
tar -vxf spark-2.1.0-bin-hadoop2.7.tgz
ENV SPARK_HOME /usr/local/spark/spark-2.1.0-bin-hadoop2.7
COPY ./docker-entrypoint.sh /etc/docker-entrypoint.sh
@anthonynsimon
anthonynsimon / gen_sbt_project
Last active June 23, 2017 08:16
Generate sbt project structure
#!/bin/bash
# Usage: script [project name]
PROJECT_NAME=$1
mkdir -p $PROJECT_NAME
cd $PROJECT_NAME
touch build.sbt
@anthonynsimon
anthonynsimon / SortedMergeJoin.scala
Created March 6, 2018 16:50
Sorted Merge Join in both FP and OOP
import scala.collection.mutable
object SortedRelation {
def apply[A, B](seq: Seq[A], key: (A) => B)(implicit ordering: Ordering[B]): SortedRelation[A, B] = new SortedRelation(seq, key)
}
class SortedRelation[A, B](val seq: Seq[A], val key: (A) => B)(implicit ordering: Ordering[B]) {
private val sorted = seq.sortBy(key)
import java.util.concurrent.atomic.AtomicReference
import scala.collection.mutable
import scala.concurrent.ExecutionContext
import scala.util.{Failure, Success, Try}
trait Eventual[A] {
def get: Try[A]
def onComplete(f: Try[A] => Unit): Unit
@anthonynsimon
anthonynsimon / LICENSE
Last active April 10, 2018 15:33
This license applies to all public gists https://gist.github.com/anthonynsimon
MIT License
Copyright (c) 2018 Anthony Najjar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: