Skip to content

Instantly share code, notes, and snippets.

View madebyjeffrey's full-sized avatar

Jeffrey Drake madebyjeffrey

View GitHub Profile

I think that folks are finally showing up to the Elixir party and (for the most part) liking what they see :)

I have only a small handful of criticisms after playing with Elixir for a while (which so far all seem like "Haskell is better in these areas," although I seem to still like Elixir better overall!)

  1. you can't define/override (per lexical scope) arbitrary infix operators, you are restricted to a small set. (In Haskell, for example, you can call any prefix function as an infix function.)

  2. you don't have any automatic currying. That's more Erlang's fault. Haskell has this, of course. In Elixir's defense, it's probably possible to define a curryable function definer using macros, like "defcurryable". Because, you know, what the hell CAN'T you do with macros? :) And Elixir has them.

  3. there is no clear distinction made between code with side effects and code without side effects. This is yet another thing I think Haskell gets right, because you can prove determinism when you can prove no side effe

/*
This code present a way to implement textView:doCommandBySelector, as sent by an NSTextView to its delegate, and implement the method as - (BOOL) method: (NSTextView*)aTextView and avoid the need for if statement chaining.
*/
- (BOOL)textView:(NSTextView *)aTextView doCommandBySelector:(SEL)aSelector {
if ([self respondsToSelector: aSelector]) {
BOOL (*method)(id, SEL, NSTextView*);
method = (BOOL (*)(id, SEL, NSTextView*))[self methodForSelector: aSelector];
return method(self, aSelector, aTextView);
} else {
// The Controller:
// The controller is created:
viewDidLoad:
CGRect starsize = CGRectMake(0, 0, 2048, 2048);
self.starmap.scrollView.bounds = starsize;
self.starmap.frame = starsize;
[self.starmap setNeedsDisplay];
@madebyjeffrey
madebyjeffrey / NSColor+CGColor
Created November 16, 2010 06:30
CGColor property for NSColor
// Version 3: Simplified, but still can have an exception thrown in the case of a non-floating point colour space.
@implementation NSColor (CGColor)
@dynamic CGColor;
- (CGColorRef) CGColor
{
CGColorSpaceRef colorspace = [[self colorSpace] CGColorSpace];
const NSInteger nComponents = [self numberOfComponents];
@madebyjeffrey
madebyjeffrey / CABasicAnimation
Created November 16, 2010 20:31
Adapting an example, doesn't work fully yet
- (void) present
{
CABasicAnimation *a;
a = [CABasicAnimation animationWithKeyPath: @"transform.scale"];
a.duration = 6;
a.repeatCount = 0;
a.autoreverses = NO;
a.fromValue = [NSNumber numberWithFloat: 0];
@madebyjeffrey
madebyjeffrey / pyglet3
Created February 22, 2011 00:49
displays a mesh
from __future__ import division
from pyglet import clock, font, image, window, text
from pyglet.gl import *
import numpy
SIZE = 64
TWO_PI = 2.0 * 3.1415926535
class World(object):
def __init__(self):
self.verts_id = GLuint()
glGenBuffers(1, self.verts_id)
self.mesh = []
for x in xrange(SIZE):
for z in xrange(SIZE):
self.mesh.extend((float(SIZE//2 - x), 0.0, float(SIZE//2 - z)))
data = (GLfloat*len(self.mesh))(*self.mesh)
glBindBuffer(GL_ARRAY_BUFFER, self.verts_id)
Take:
1 2 3
4 5 6
7 8 9
Turn Into:
0 0 0 0 0
program euler002
implicit none
integer :: i = 0
integer :: f = 0
integer :: s = 0
do
i = i + 1
f = fib(i)
@madebyjeffrey
madebyjeffrey / gist:980971
Created May 19, 2011 15:08
Printf FileHandle
@implementation NSFileHandle (print)
- (void) printf: (NSString*) format, ...
{
NSString *output;
va_list ap;
va_start(ap, format);