Skip to content

Instantly share code, notes, and snippets.

javascript:location.href=%27riposte://x-callback-url/createNewPost?text=%27+encodeURIComponent(document.title)+%27%20%27+encodeURIComponent(window.location.href)
@NachoSoto
NachoSoto / AnyValidator.swift
Last active December 3, 2015 14:21
Type-erased ValidatorType
protocol ValidatorType {
typealias ValidatedType
func isValid(object: ValidatedType) -> Bool
}
// You might want to make it a reference type, depending on your case.
struct AnyValidator<T>: ValidatorType {
private let validatorBlock: (T) -> Bool
init<V: ValidatorType where V.ValidatedType == T>(validator: V) {
@mbriggs
mbriggs / gist:4429104
Created January 1, 2013 18:17
Bruce Tognazzini - 2005

First of all, i grew up on mac os 6 and 7, and I would like to thank you for contributing to one of the most enjoyable experiences i have ever had from a computer. to this day, with dozen other operating systems under my belt, i still look back fondly to my days on os 7.

the unix editor vi flys in the face of every usability guideline on the planet. yet it has enjoyed widespread use and popularity, even amoung people who arnt forced to learn it. wouldnt new users want something that doesnt send their brain into tailspins when they operate it? wouldnt we get a natural selection effect, where given the

anonymous
anonymous / gist:4430394
Created January 1, 2013 22:04

As I've worked with Scheme, I've encountered some troubles which I'd like to resolve. Oddly, even with a 50-page specification, the troubles I've encountered still have much more to do with features of the language which can be simplified rather than features which are missing or too simple.

As a result, I'd like to propose these changes:

  1. Identifiers made case-sensitive.

Rationale: This makes integration with other langauges easier. Since

@puffnfresh
puffnfresh / ConstructorProperty.cljs
Created March 9, 2013 20:23
Instantiating a constructor from an object's property.
(ns constructor-property)
; I have a library with a constructor as a property.
(def library
(js-obj "Constructor" js/String))
; Only way I know is to extract the constructor out.
(def String
(.-Constructor library))
@puffnfresh
puffnfresh / getinstance.js
Created March 29, 2013 02:04
Two nice helper functions for creating constructors in JavaScript.
// Polyfill for Object.create
function create(proto) {
function Ctor() {}
Ctor.prototype = proto;
return new Ctor();
}
// Always returns an instance of constructor
function getInstance(self, constructor) {
return self instanceof constructor ? self : create(constructor.prototype);
@indygreg
indygreg / hgrc
Last active December 16, 2015 23:09
Mercurial config
[extensions]
color =
graphlog =
histedit =
mq =
pager =
progress =
purge =
rebase =
transplant =
@mchakravarty
mchakravarty / Exp.hs
Created August 25, 2013 05:20
Functorial approach to defining expressions.
data PreExp exp = Val Int
| Add exp exp
newtype Exp = Exp (PreExp Exp) -- this is just a normal expression
data AttrExp = AttrExp Attr (PreExp AttrExp) -- an attributed expression
data Attr = ...
@kisom
kisom / gtgov.sh
Created August 31, 2013 18:57
Go test code coverage.
#!/bin/sh
if [ -z "$1" ]; then
PKG=$(pwd)
PKG=${PKG##${GOPATH}/src/}
else
PKG=$1
fi
OUTBASE=${PKG##*/}
SLOC=$(gofmt -comments=false $(find ${GOPATH}/src/${PKG} -iname \*.go | xargs)\
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define BUFFER_SIZE 5
struct reqdata
{
char *data;
size_t len;