Skip to content

Instantly share code, notes, and snippets.

@anthonynsimon
anthonynsimon / binary_tree.rb
Last active Apr 7, 2016
Simple Binary Tree in Ruby
View binary_tree.rb
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 Apr 7, 2016
Simple Binary Tree in Go
View btree.go
package btree
import (
"fmt"
)
type BinaryTree struct {
Root *Node
NumberOfIterations int
}
@anthonynsimon
anthonynsimon / linkedList.c
Last active Apr 12, 2016
Quick and dirty linked list in C
View linkedList.c
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int value;
struct node* next;
} node_t;
typedef struct list {
node_t* head;
View pubsub.go
package main
import (
"bufio"
"fmt"
"log"
"net"
"io"
)
@anthonynsimon
anthonynsimon / prepend_timestamp.sh
Created Mar 8, 2017
Bash script preprend timestamp to filename
View prepend_timestamp.sh
#!/bin/bash
for f in *; do mv -- "$f" "$(stat -f "%Sm_%N" -t "%Y%m%d" "$f")"; done
View Dockerfile
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 Jun 23, 2017
Generate sbt project structure
View gen_sbt_project
#!/bin/bash
# Usage: script [project name]
PROJECT_NAME=$1
mkdir -p $PROJECT_NAME
cd $PROJECT_NAME
touch build.sbt
@anthonynsimon
anthonynsimon / SortedMergeJoin.scala
Created Mar 6, 2018
Sorted Merge Join in both FP and OOP
View SortedMergeJoin.scala
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)
View EventualPromise.scala
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 Apr 10, 2018
This license applies to all public gists https://gist.github.com/anthonynsimon
View LICENSE
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: