Skip to content

Instantly share code, notes, and snippets.

View agaro1121's full-sized avatar

Anthony Garo agaro1121

View GitHub Profile
/**
 * Created by Hierro on 4/18/16.
 */
public class Recursion {
    public static void main(String[] args) {
        int[] array = {1,2,3};

        int sum = getSum(array);
 int sum2 = getSum2(array);
@agaro1121
agaro1121 / PlaySbtIntegrationTest.md
Last active July 6, 2016 17:40
Setting up proper sbt integration tests in Play SBT

Build.sbt

Defaults.itSettings
sourceDirectory in IntegrationTest := baseDirectory.value / "test-integration"
libraryDependencies +=
  "com.typesafe.play" %% "play-test" % play.core.PlayVersion.current % "it" //makes this available to integration tests
parallelExecution in IntegrationTest := false //Singleton Mongo Client not thread-safe for parallel tests. NullPointer being thrown because 1 test closed the connection while the other test needed it
@agaro1121
agaro1121 / FutureToFutureTry.md
Last active January 31, 2017 15:23
Create Future[Try[T]] from Future[T]
def mapValue[T]( f: Future[T] ): Future[Try[T]] = {
  val prom = Promise[Try[T]]()
  f onComplete prom.success
  prom.future
}

def traverseFilteringErrors[A, B](seq: Seq[A])(f: A => Future[B]): Future[Seq[B]] = {
  Future.traverse( seq )( f andThen mapValue ) map ( _ collect{ case Success( x ) => x } )
}
@agaro1121
agaro1121 / XmlNodeDiff.md
Created October 22, 2016 22:16
Quick way to parse and compare xml node trees
/** Check that the XMLs are the same, ignoring empty text nodes (whitespace). */
private def assertEqual(actual: xml.Node, expected: xml.Node) {

    def recurse(actual: xml.Node, expected: xml.Node) {
        // depth-first checks, to get specific failures
        for ((actualChild, expectedChild) <- actual.child zip expected.child) {
            recurse(actualChild, expectedChild)
        }
 actual should be (expected)
@agaro1121
agaro1121 / BasicRingBuffer.md
Last active October 29, 2016 01:17
Basic Ring Buffer
class RingBuffer[T] {
  val array = new Array[T](5)
  var count = 0

  override def toString: String = array.mkString(",")

  def add(value: T): RingBuffer[T] = {
    if (count < array.length) {
 array(count) = value
@agaro1121
agaro1121 / TarCommand.md
Last active November 24, 2016 22:01
The tar Command
#gzip

#compress
tar czvf testZipFile.tar.gz myDir/

#decompress
tar xzvf testZipFile.tar.gz

#view files without decompressing
@agaro1121
agaro1121 / MagnetPattern.md
Last active December 26, 2016 06:30
Magnet Pattern Implementation
package magnetpattern

import scala.language.implicitConversions

sealed trait Magnet {
  type Result
  def apply(): Result
}
@agaro1121
agaro1121 / FreeMonad.md
Last active January 28, 2017 07:11
Sample 1 page Free Monad
package free

import free.FunctorTransformer.{Id, ~>}
import scala.language.higherKinds

/**************************** Boilerplate ********************************/
trait Functor[F[_]] {
  def map[A, B](a: F[A])(fn: A => B): F[B]
}
@agaro1121
agaro1121 / Mac SSH Autocomplete
Created February 24, 2017 16:38 — forked from aliang/Mac SSH Autocomplete
Add auto complete to your ssh, put into your .bash_profile
_complete_ssh_hosts ()
{
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
comp_ssh_hosts=`cat ~/.ssh/known_hosts | \
cut -f 1 -d ' ' | \
sed -e s/,.*//g | \
grep -v ^# | \
uniq | \
grep -v "\[" ;
@agaro1121
agaro1121 / mac_ulimit.md
Last active December 6, 2017 21:39
when you hit the ulimit

ulimit

Cause: java.io.IOException: Too many open files in system
[info]   at sun.nio.ch.KQueueArrayWrapper.init(Native Method)
[info]   at sun.nio.ch.KQueueArrayWrapper.<init>(KQueueArrayWrapper.java:98)
[info]   at sun.nio.ch.KQueueSelectorImpl.<init>(KQueueSelectorImpl.java:88)
[info]   at sun.nio.ch.KQueueSelectorProvider.openSelector(KQueueSelectorProvider.java:42)
[info]   at io.netty.channel.nio.NioEventLoop.openSelector(NioEventLoop.java:156)
[info] at io.netty.channel.nio.NioEventLoop.(NioEventLoop.java:149)