Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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
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 / 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)
@anthonynsimon
anthonynsimon / signal_pool.py
Created Apr 6, 2018
Signal pool thread pool example
View signal_pool.py
import threading
from threading import Thread, Lock
import sys
import time
class Q:
def __init__(self):
self._items = []