Skip to content

Instantly share code, notes, and snippets.

mrjjwright / gist:218405
Created Oct 26, 2009
Select first row in NSTableView on focus
View gist:218405
//put this in subclass of NSTableView
//select the first row or blue highlights already selected rows
//in a NSTableView when we gain focus if there are rows in the table
-(BOOL) becomeFirstResponder {
if ([self numberOfRows] > 0 && [self numberOfSelectedRows] == 0) {
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:NO];
[self setNeedsDisplay];
return YES;
mrjjwright / maskNSImage.c
Created Jul 26, 2011
Fill opaque parts of NSImage with color
View maskNSImage.c
+ (NSImage *)maskImageNamed:(NSString *)name color:(NSColor *)color
NSImage *image = [NSImage imageNamed:name];
CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
CGContextRef c = MyCreateBitmapContext(image.size.width, image.size.height);
[image drawInRect:rect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
CGContextSetFillColorWithColor(c, [color CGColor]);
CGContextSetBlendMode(c, kCGBlendModeSourceAtop);
CGContextFillRect(c, rect);
CGImageRef ciImage = CGBitmapContextCreateImage(c);
mrjjwright / gist:3240020
Created Aug 2, 2012
Extract largest image thumbnail from url using node and cheerio
View gist:3240020
cheerio = require('cheerio')
Shred = require('shred')
shred = new Shred()
http = require('http')
URL = require('url')
server = http.createServer (request, response) ->
url = URL.parse(request.url, true)
urlToDiscover = url.query['url']
startDiscovery urlToDiscover, (theImageURL) ->
mrjjwright / styed_component.js
Created Jan 19, 2017
Simple Styled Component
View styed_component.js
const TeamSelectionContainer = styled.div`
height: 100%;
display: flex;
flex-direction: column;
color: white;
font-size: 25px;
mrjjwright / mobservable-vidom.js
Last active Jan 12, 2016
Make vidom components reactive using mobservable
View mobservable-vidom.js
(function() {
function mrFactory(mobservable, vidom) {
if (!mobservable)
throw new Error("mobservable-vidom requires the Mobservable package.")
if (!vidom)
throw new Error("mobservable-vidom requires vidom to be available");
var isTracking = false;
// WeakMap<Node, Object>;
mrjjwright / gist:3029371
Created Jul 1, 2012
AppPlay - an app developer's logic tool
View gist:3029371
- AppPlay is an interactive logic tool for app developers. Your app
manages lots of related logic:
- States
- Events
- Simple Conditional logic
- Stories
- User Actions
- Screenshots of how things should look.
- This logic is independent of how you technically implement it and
should be maintained outside your code.
mrjjwright / ExampleAppDelegate.m
Created Apr 10, 2012
Modify TUIKit example to show textview inside of a scrollview
View ExampleAppDelegate.m
/* TUINSView is the bridge between the standard AppKit NSView-based heirarchy and the TUIView-based heirarchy */
TUINSView *tuiScrollViewContainer = [[TUINSView alloc] initWithFrame:b];
[scrollViewWindow setContentView:tuiScrollViewContainer];
scrollExample = [[TUIScrollView alloc] initWithFrame:b];
scrollExample.backgroundColor = [TUIColor redColor];
TUITextView *textView = [[TUITextView alloc] initWithFrame:scrollExample.bounds];
textView.text = @"hellodfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddf
View TUILayout.h
// TUILayout.h
// Crew
// Created by John Wright on 11/13/11.
// Copyright (c) 2011 AirHeart. All rights reserved.
#define kTUILayoutViewHeight @"kTUILayoutViewHeight"
mrjjwright / hyperlinkString.m
Created Aug 24, 2011
TUIAttributedString as hyperlink
View hyperlinkString.m
+(id)hyperlinkFromString:(NSString*)inString withURL:(NSURL*)aURL
TUIAttributedString* attrString = [TUIAttributedString stringWithString:inString];
NSRange range = NSMakeRange(0, [attrString length]);
[attrString beginEditing];
[attrString addAttribute:NSLinkAttributeName value:[aURL absoluteString] range:range];
// make the text appear in blue
NSColor *blueColor = [TUIColor colorWithHexString:@"#3B5998"].nsColor;
mrjjwright / calculate.m
Created Aug 20, 2011
Calculate height for a given row
View calculate.m
- (CGFloat)tableView:(TUITableView *)tableView heightForRowAtIndexPath:(TUIFastIndexPath *)indexPath
CGFloat calcuatedHeight = 55.0;
NSDictionary *post = [_posts objectAtIndex:indexPath.row];
NSString *type = [post valueForKey:@"type"];
NSString *message = [post valueForKey:@"message"];
if (!message) message = type;
TUIAttributedString *s = [TUIAttributedString stringWithString:message];
[s setAlignment:TUITextAlignmentLeft lineBreakMode:TUILineBreakModeWordWrap];
s.color = [TUIColor blackColor];