Skip to content

Instantly share code, notes, and snippets.

View d2fn's full-sized avatar
🐢

Dietrich Featherston d2fn

🐢
View GitHub Profile
@d2fn
d2fn / equibin.scala
Created October 1, 2010 03:28
partition set of numbers into subsets of equal size
def equibin(a:Seq[Double], depth:Int) = {
val d = a.size/depth
(0 until a.size) // ordered set of indexes of all values
.groupBy(i=>i/d).values.toList.sortBy(s=>s(0)) // split set into 'd' separate lists
.map { group => group.map( i => a(i) ) } // map onto value set
.map { values => ( (min(a),max(a)), values ) }// each bin gets min-max metadata
}
@d2fn
d2fn / equalSizeBins.erl
Created February 14, 2011 07:03
partition set of numbers into subsets of equal size
% produce a list, the elements of which are each lists of
% length 'Depth' of less forming sorted, equally sized bins
% of the numeric input list L
% the last bin will be of size (Depth rem length(L))
equal_size_bins (L,Depth) ->
[tuple_to_list(X) || X <- equal_size_bins_sorted(lists:sort(L),Depth)].
equal_size_bins_sorted (L,Depth)
when Depth >= length(L)
-> [list_to_tuple(L)];
@d2fn
d2fn / gist:834627
Created February 18, 2011 23:50
bitsets, use them for everything!
import euler.Functions._
import scala.math._
val q = "What is the smallest positive " +
"number that is evenly divisible by " +
"all of the numbers from 1 to 20?"
def hasDivisors(n:Long, divisors:Seq[Long]) = {
divisors.filter(n%_ > 0).isEmpty
}
@d2fn
d2fn / hemingway-happiness.md
Last active December 14, 2015 11:28
Happiness in intelligent people is the rarest thing I know

Happiness in intelligent people is the rarest thing I know.- Ernest Hemingway, author and journalist, Nobel laureate (1899-1961)

Hemingway, who took his own life in 1961, knew his share of both intelligent people and of unhappiness. He lived through two world wars, the Great Depression, four wives and an unknown number of failed romantic relationships, none of which would help him to develop happiness if he knew how.

As Hemingway's quote was based on his life experience, I will base the following speculation on both my personal and my professional experience as a sociologist. Not enough study exists to quote on this subject.

Western society is not set up to nurture intelligent children and adults, the way it dotes over athletes and sports figures, especially the outstanding ones. While we have the odd notable personality such as Albert Einstein, we also have many extremely intelligent people working in occupations that are considered among the lowliest, as may be attested by a review of the membership list

@d2fn
d2fn / man-eating-cats_haruki-murakumi_en.md
Last active November 2, 2023 23:47 — forked from thoward/man-eating-cats_haruki-murakumi_en.md
Man Eating Cats, Haruki Murakami

Man-Eating-Cats

by Haruki Murakami
Translated by Philip Gabriel

Source

I bought a newspaper at the harbor and came across an article about an old woman who had been eaten by cats. She was seventy years old and lived alone in a small suburb of Athens -- a quiet sort of life, just her and her three cats in a small one-room apartment. One day, she suddenly keeled over face down on the sofa -- a heart attack, most likely. Nobody knew how long it had taken for her to die after she collapsed. The old woman didn't have any relatives or friends who visited her regularly, and it was a week before her body was discovered. The windows and door were closed, and the cats were trapped. There wasn't any food in the apartment. Granted, there was probably something in the fridge, but cats haven't evolved to the point where they can open refrigerators. On the verge of starvation, they were forced to devour their owner's flesh.

I read this articl

@d2fn
d2fn / gist:9572322
Last active August 29, 2015 13:57
Get Bird Sounds
curl http://web4.audubon.org/news/pressroom/bacc/imagessounds.html | grep wav | cut -d \' -f2 | sed 's/ /%20/' | xargs -I{} curl -O http://web4.audubon.org/news/pressroom/bacc/\{\}
@d2fn
d2fn / index.html
Last active August 29, 2015 14:03
Scatter Plot
<!DOCTYPE html>
<meta charset="utf-8">
<style type="text/css">
.axis path,
.axis line {
fill: none;
stroke: black;
shape-rendering: crispEdges;
}
.axis text {
@d2fn
d2fn / README.md
Last active August 29, 2015 14:03
Uniform Random Point Distribution

Demonstration of unevenness of uniform random distributions for point scattering.

@d2fn
d2fn / README.md
Last active August 29, 2015 14:03
Dendrite Growth - nearest neighbor search using d3 quadtree

Dendrite growth using d3 quadchart nearest neighbor search.

@d2fn
d2fn / README.md
Last active August 29, 2015 14:03
Dendrite Growth with Cracks

Dendrite growth using d3 quadchart nearest neighbor search. A point is chosen at random and joined to its nearest neighbor. Each node keeps track of the node to which it was adjoined via a parent reference. As each node is attached the child count of each parent in the chain is incremented. The child count is used directly to determine rendering width of lines between nodes.