Skip to content

Instantly share code, notes, and snippets.

@chris-martin
chris-martin / 0-python-pragmatism.py
Last active December 15, 2015 01:59
"Python’s Pragmatism: This example showcases the ease in which arrays can be created and manipulated. Define a list, print an item in that list, or replace an item with simple methods." - from http://preview.python.org/ 2013-03-17
>>> l = ['spam', 'ham', 314, 23]
>>> l
['spam', 'ham', 314, 23]
>>> l[0]
'spam'
>>> l[0] = 'monkey'
>>> l
['monkey', 'ham', 314, 23]

Tony Hoare, 1981

At first I hoped that such a technically unsound project would collapse but I soon realized it was doomed to success. Almost anything in software can be implemented, sold, and even used given enough determination. There is nothing a mere scientist can say that will stand against the flood of a hundred million dollars. But there is one quality that cannot be purchased in his way - and that is reliability. The price of reliability is the pursuit of the utmost simplicity. It is a price which the very rich find most hard to pay.

sealed trait Sigma
case class Lit(s: String) extends Sigma
case class Concat(s: Sigma, t: Sigma) extends Sigma
case class Ext extends Sigma
def eval1(sig: Sigma): Sigma = sig match {
case Concat(s, t) => {
val Lit(e1) = eval1(s)
val Lit(e2) = eval1(s)
Lit(e1 + e2)
@chris-martin
chris-martin / brew-patent.md
Last active December 15, 2015 08:49
A little story about the fake future history of Beer™.

If humanity's discovery of brewing had been delayed...

Beer was a food product manufactured during the early 21st century. PepsiCo's 2013 press release stated:

Beer, made with our patented Brewing Technology, comes in four exciting flavors.

The wild commercial success of Beer led the company to expand its lineup in 2018 with the addition of a new Blueberry Blast flavor. PepsiCo also briefly experimented with Cream Cheese Salad Beer, a low-calorie variety marketed to women.

United States-Mexico border relations tensed as officials, under pressure from PepsiCo, strengthened efforts to block importing of the increasing number of knockoff beverages brewed in violation of US patent law. PepsiCo v Gonzales (2017) established that most off-brand "Beers", although not corn-based like genuine Beer, still fell within the purview of the Brewing patent.

interface Optional<T> {
T get();
boolean isPresent();
void ifPresent(Consumer<? super T> consumer);
T orElse(T other);

Scala Number Conversion Chart

From → To Expression

I mostly agree with the notion that a university's role is to teach you theory, not to make you employable, but it's hard for me to reconcile that belief with my disappointment when students aren't ready to be hired upon graduation. As enjoyable as learning about computing can be, there is little sense in studying it unless you plan to apply it in some way. This means programming. There's no way around that. It is the tool we have. So if you're going through all the trouble of getting a degree in computation, you ought to be doing your best to also become a damn good programmer. If software practice truly falls outside of the school's purview, then I can't blame its curriculum for neglect. Academia does fulfill its role, but at too great an opportunity cost. Degree programs fill the lives and consume the energy of students who ought to be programming, programming, programming, and pausing to take some theory classes on the side.

import akka.actor._
package object akkautil {
/** Switches the implicit `ActorContext`'s receive behavior to `behavior`
* until one message is handled, then returns to the previous behavior.
*/
def temporarilyBecome(behavior: Actor.Receive)(implicit context: ActorContext) {
import context.unbecome
select count(*) as numtimes, sql.sql_text
from v$open_cursor c, v$sql sql
where c.sql_id=sql.sql_id and c.user_name = 'username' group by sql.sql_text;