This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static <A> Node<A> reverse(final Node<A> head) { | |
Node<A> curr; | |
Node<A> previous = null; | |
while (head != null) { | |
curr = head.next; | |
head.next = previous; | |
previous = head; | |
head = curr; | |
} | |
return previous; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ryangantt.scala | |
import scala.collection.mutable.Queue | |
import scala.collection.mutable.ArrayBuffer | |
abstract class Element[+T] | |
case class Node[T](val left: Element[T], val right: Element[T], val value: Leaf[T]) extends Element[T] | |
case class Leaf[T](val value: T) extends Element[T] | |
case object Sentinel extends Element |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: atdgen stock_price | |
stock_price: | |
corebuild -pkg core_extended,netclient,yojson,atdgen stock_price.native | |
atdgen: | |
atdgen -j yfinance.atd | |
atdgen -t yfinance.atd | |
clean: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ryangantt.monad; | |
/** | |
* Implementation of the identity monad | |
*/ | |
public class Identity<T> { | |
public T value; | |
public T getValue() { | |
return value; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface Monoid<T> { | |
public T apply(T a, T b); | |
} | |
public class StringMonoid implements Monoid<String> { | |
public static final String IDENTITY = StringUtils.EMPTY_STRING; | |
public String apply(String a, String b) { | |
return a + b; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* FP fanservice | |
*/ | |
private interface Predicate<T> { | |
public boolean evaluate(final T item); | |
} | |
protected <T> Collection<T> filter(final Collection<T> collection, final Predicate<T> predicate) { | |
final Collection<T> filtered = new ArrayList<T>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ryangantt.util; | |
import java.util.ArrayList; | |
import java.util.Collection; | |
import java.util.Deque; | |
import java.util.LinkedList; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.TreeMap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Latency Comparison Numbers | |
-------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns | |
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms | |
Read 4K randomly from SSD* 150,000 ns 0.15 ms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* ============ | |
* Defect: can alias-override class constructor, but only when using legacy constructor naming convention | |
* ============ | |
*/ | |
trait SomeTrait { | |
private function constructor() { | |
echo "this is abuse\n"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** inside of a method */ | |
$that = $this; | |
return $this->argmax( $candidates, function ( $w ) use ( $that ) { | |
$that->nwords[ $w ]; | |
}); |
NewerOlder