Skip to content

Instantly share code, notes, and snippets.

@aconbere
aconbere / semi-groups-irc.mkd
Last active July 11, 2022 01:17
Abstract algebra applied to totally boring programming problems

The semigroup, or how a bunch of math snuck into my program

This is a story about an idea, an abstraction if you will. As software developers we deal in abstractions constantly, but I want to talk to you about one particular idea, the idea of +. Addition is pretty fundamental as a concept, so let's run through the basics. You'll be familiar with some common forms of addition like integer addition 1 + 2 = 3 and rational addition 1/2 + 2/3 = 7/6. But what does it mean to be able to add something? Could we add functions? What about optional values?

One answer to that question is provided by algebra a lot of algebra is spent defining sets of things and what operations can be performed on them. And what algebra will tell us is that the things we tend to think of as being addable are generally called Semigroups. A Semigroup is a set where all items in the set can be added together so that for every a, b, and c in the set (a + b) + c = a + (b + c). I

@aconbere
aconbere / gist:5543199
Created May 8, 2013 20:01
find the big files... dammit
find . -type f | xargs du -h | sort -h
@aconbere
aconbere / gist:5188516
Last active December 15, 2015 02:39
M-O-N-A-D-S

As software developers we use datastructures all the time Linked Lists, Hash Maps, Stacks. Most datastructures have a set of related operations that we can think of as the core pieces that define that structure in Scala we call the collection of those operations a Trait on in Java an Interface. A Hash Map exposes the Map interface and has an operations to add a key and value +, remove a key -, retrieve the value at key get and an operation like fold to operate over the List of keys and values.

We have certain expectations of these datastructures from our experiences, we expect Maps to be hash maps, and we expect queues to be stacks. But there's no law that requires that. A common replacement of as Hash Map is a Tuple List,

DBus failure! This is most likely caused by the wicd daemon stopping while wicd-curses is running. Please restart the daemon, and then restart wicd-curses.
Traceback (most recent call last):
File "/usr/share/wicd/curses/wicd-curses.py", line 921, in call_update_ui
self.update_ui(True)
File "/usr/share/wicd/curses/wicd-curses.py", line 88, in wrapper
return func(*args, **kargs)
File "/usr/share/wicd/curses/wicd-curses.py", line 932, in update_ui
self.handle_keys(input_data[1])
File "/usr/share/wicd/curses/wicd-curses.py", line 913, in handle_keys
self.diag.save_settings()
DBus failure! This is most likely caused by the wicd daemon stopping while wicd-curses is running. Please restart the daemon, and then restart wicd-curses.
Traceback (most recent call last):
File "/usr/share/wicd/curses/wicd-curses.py", line 921, in call_update_ui
self.update_ui(True)
File "/usr/share/wicd/curses/wicd-curses.py", line 88, in wrapper
return func(*args, **kargs)
File "/usr/share/wicd/curses/wicd-curses.py", line 932, in update_ui
self.handle_keys(input_data[1])
File "/usr/share/wicd/curses/wicd-curses.py", line 913, in handle_keys
self.diag.save_settings()
Traceback (most recent call last):
File "/usr/lib/pymodules/python2.7/django/core/handlers/base.py", line 101, in get_response
request.path_info)
File "/usr/lib/pymodules/python2.7/django/core/urlresolvers.py", line 252, in resolve
sub_match = pattern.resolve(new_path)
File "/usr/lib/pymodules/python2.7/django/core/urlresolvers.py", line 158, in resolve
return ResolverMatch(self.callback, args, kwargs, self.name)
File "/usr/lib/pymodules/python2.7/django/core/urlresolvers.py", line 164, in _get_callback
self._callback = get_callable(self._callback_str)
File "/usr/lib/pymodules/python2.7/django/utils/functional.py", line 124, in wrapper
@aconbere
aconbere / gist:971936
Created May 14, 2011 04:59
testing node-fake
fake = require("fake")
var namespace = { x: function () { this.whatever = "skimpy" } }
fakeX = fake.create()
fakeX.expects(namespace, "X")
.andReturns("AASDFASDF")
var y = new namespace.X()
assert.equal(y, "AASDFASDF")
package com.conbere.anders.escape;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.SurfaceView;
import android.view.SurfaceHolder;
@aconbere
aconbere / gist:910748
Created April 8, 2011 21:08
the callee of EscapeThread
public EscapeView(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
SurfaceHolder holder = getHolder();
holder.addCallback(this);
this.thread = new EscapeThread(holder, context);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
@aconbere
aconbere / gist:910742
Created April 8, 2011 21:05
setRunning symbol not found
class EscapeThread extends Thread {
public SurfaceHolder surfaceHolder;
public Context context;
private boolean running;
public EscapeThread(SurfaceHolder holder, Context cont) {
this.surfaceHolder = holder;
this.context = cont;
this.running = false;
}