Skip to content

Instantly share code, notes, and snippets.

implicit class RichAny[A](x: A) {
def K(f: A => Unit): A = { f(x); x }
}
$('<tr/>').append(
$('<td class="key"/>').text('Subject:'),
$('<td/>').append(
message.isStarred ? $('<span class="star"/>'): $(),
$('<span class="value"/>').text(message.subject)
)
)
⟶xxx
x⟶xx
xx⟶x
xxx⟶
xxxx
⟶xxx
⟶⟶xx
⟶⟶⟶x
⟶⟶⟶⟶
enum EnumBullshit {
A(5), B(6), C(-4);
public final int i;
private static final Map<Integer, EnumBullshit> map = new HashMap<>();
static {
for (EnumBullshit bullshit : values()) {
map.put(bullshit.i, bullshit);
}

Suppose f : R → R is continuous and that there is a point c such that f(f(c))=c. Show that f has a fixed point.


Let g(x) = f(x) - x. Note that g is continuous. Consider two points on g:

  • g(c) = f(c) - c

  • g(f(c)) = f(f(c)) - f(c) = c - f(c)

http://jazzy.id.au/default/2012/10/16/benchmarking_scala_against_java.html

You're comparing an in-place sorting algorithm to an out-of-place one. You can't just say that the "idiomatic scala" uses a different style for implementing the same algorithm. The third benchmark has a different method signature. You're comparing algorithms that solve different problems. I'm not sure that an out-of-place quicksort would be considered idiomatic in any context anyway. Especially since the data structure you're using is a cons list (which I think was a goofy choice for a benchmark against arrays), wouldn't the "idiomatic scala programmer" be much more apt to

All programs must have side effects to be useful — can we please stop repeating this awful lie? Side effects are great, but they must not be observable from within the program. It is same with pencil-and-paper: writing out a calculation shortens the pencil lead, but the calculation isn't affected by that. If you believe programs can be proofs, you cannot think they must have side effects to be useful.


Words adapted from:
https://twitter.com/puffnfresh/status/363731296150753280
https://twitter.com/jonsterling/status/363736089334251520
https://twitter.com/kaleidic/status/363744960819888128
https://twitter.com/milessabin/status/363762121748004864

implicit def bigIntToLong(bi: BigInt): Long = bi.toLong
case class PrimeFactor(prime: Long, cardinality: Int) {
lazy val value: Long = BigInt(prime) pow cardinality
}
implicit val primeFactorOrdering: Ordering[PrimeFactor] = Ordering by (_.prime)
case class PrimeFactorization(factors: SortedSet[PrimeFactor]) {

Some Scala-related thoughts on this Python function:

def GetContourPoints(self, array):
    """Parses an array of xyz points and returns a array of point dictionaries."""
    return zip(*[iter(array)]*3)

The most straightforward approach would be to use Iterable.grouped:

/*
Wraps `f` such that the resulting function can be invoked at most once per `milliseconds`.
The first invocation has the same effect and return value as `f`. Subsequent invocations
within the buffer timeframe have the same return value as `f` but do not side effect.
Note that `f` should not be recursive. If `f` recurses, the return value of this function
will be `undefined`.
*/
function debounce(f, milliseconds) {