Skip to content

Instantly share code, notes, and snippets.

@fronx
fronx / ping log
Created May 28, 2014 08:16
I left the console open over night and you can see how the network connection gets dropped and ping times go up.
~ $ ping 92.225.156.181
PING 92.225.156.181 (92.225.156.181): 56 data bytes
64 bytes from 92.225.156.181: icmp_seq=0 ttl=64 time=4.691 ms
64 bytes from 92.225.156.181: icmp_seq=1 ttl=64 time=2.607 ms
64 bytes from 92.225.156.181: icmp_seq=2 ttl=64 time=2.581 ms
64 bytes from 92.225.156.181: icmp_seq=3 ttl=64 time=2.901 ms
64 bytes from 92.225.156.181: icmp_seq=4 ttl=64 time=5.160 ms
64 bytes from 92.225.156.181: icmp_seq=5 ttl=64 time=2.768 ms
64 bytes from 92.225.156.181: icmp_seq=6 ttl=64 time=2.600 ms
64 bytes from 92.225.156.181: icmp_seq=7 ttl=64 time=2.691 ms
@fronx
fronx / find.js
Last active August 29, 2015 13:57
function find (ary, fn) {
var match = undefined;
for (var i = 0; !match && i < ary.length; i++)
if (fn(ary[i])) match = ary[i];
return match;
}
find([1,2,3,4], function(x) { return x > 2; })
// This technique is very old. It's based on Church pairs.
// http://en.wikipedia.org/wiki/Church_encoding#Church_pairs
cons = function (a, b) {
return function (f) {
return f(a, b);
}
}
first = function (a, b) {
data Type = T String
| Type :-> Type -- infix! (must start with `:`)
deriving Show
int = T "Int"
main = do
print (int :-> int)
-- T "Int" :-> T "Int"
print ((int :-> int) :-> int :-> int)

Schemalessness and types

Attempt to discuss the question: does the tendency towards schemaless data transfer make type systems less relevant? The question came up in a conversation on twitter.

Short answer: No. Data transfer, data serialization, schemas, and type systems are all independent from each other.

Schemaless means schema-delayed

Given a datastore with no schema, what can you know about the shape and meaning of the data stored in it? Barely anything. You may know that valid values can be represented using some particular serialization format, such as JSON. Maybe you even know that values can only be JSON objects, as opposed to arrays or primitive values. Those are constraints that a system may apply to data. (In my tweet I called that a "meta-schema", but I realize that that's not actually a fitting term.) They allow for concrete expectations about the shape of the data that can possibly be stored in and retrieved from the system.

if (reader == NULL) {
for (i=0; i < n_frames; i++) {
*writer++ = SAMPLE_SILENCE; } }
else {
for (i=0; i < n_frames; i++) {
*writer++ = *reader++; } }
// HAHAHA
@fronx
fronx / scope.md
Last active December 28, 2015 23:39

Scope of Names

For each of the following programs: what is the return value of the last expression? Why?

def a(a)
  a
end
HTTP:
GET /some/path?a=b&c=d
Sinatra, inside 'get' block:
params == {:a => 'b', :c => 'd'}
HTTP:
GET /blog/post-123?page=1
Sinatra, inside 'get' block:
module FunctorComposition where
import Prelude hiding ( Functor
, fmap
)
data Tree a = Leaf a | Branch (Tree a) (Tree a) deriving Show
class Functor f where
fmap :: (a -> b) -> f a -> f b
data Unit a = Kilogram a
| Meter a
| Second a
-- 1 N = 1kg * m/s^2
-- lalala pseudo-code here!!!
type Newton a = Div (Div (Mul (Kilogram a) (Meter a))
(Second a))
(Second a)