Skip to content

Instantly share code, notes, and snippets.

int main(int argc, char** argv) {
printf("hello world\n");
}
@evanlong
evanlong / UITableViewRace.m
Created January 31, 2011 08:13
infectmac.com blog post code sample about UITableView and GCD race condition
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
NSDictionary* pictObj = [self.pictures objectAtIndex:indexPath.row];
NSString* title = [pictObj objectForKey:@"title"];
@evanlong
evanlong / PhantomLines.m
Created February 3, 2011 00:57
Phantom lines appear on either the zero latitude or longitude axis if a point's latitude or longitudes settings are zero. Since both are zero in this case it will appear on both. This only occurs if the line width for the polyline is <= 1.
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
CLLocationCoordinate2D points[2];
points[0].latitude = 0;
points[0].longitude = 0;
points[1].latitude = -6;
points[1].longitude = 5;
MKPolyline* polyline = [MKPolyline polylineWithCoordinates:points count:2];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...code to dequeue and setup a UITableViewCell removed...
//retrieve our Core Data representation of the photo
Photo* photo = [Photo photoWithFlickrData:pictObj inManagedObjectContext:context];
if (photo.thumbnail) {
cell.imageView.image = [UIImage imageWithData:photo.thumbnail];
}
else {
@evanlong
evanlong / vtablefun.cpp
Created February 24, 2011 06:15
Showing off vtables for stackoverflow answer.
#include <iostream>
using namespace std;
class A
{
public:
int a1;
int a2;
virtual void A1() { cout << "A->A1" << endl; }
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DVTConsoleDebuggerInputTextColor</key>
<string>1 1 1 1</string>
<key>DVTConsoleDebuggerInputTextFont</key>
<string>Menlo-Bold - 11.0</string>
<key>DVTConsoleDebuggerOutputTextColor</key>
<string>1 1 1 1</string>
@evanlong
evanlong / webapi.py
Created June 7, 2011 00:50
Sample code for dealing with REST apis
import urllib
import re
class WebApiOpener(urllib.FancyURLopener):
'''
Provides a way for HTTP Basic authentication to take place without
prompting the user for a username and password like FancyURLopener
would.
'''
def __init__(self, username, password):
@evanlong
evanlong / tylerdb.c
Created July 29, 2011 07:14
Tyler DB
#include <stdio.h>
#include <socketshit.h>
int main(int argc, char** argv)
{
while(true) {
int fd = listen(internet);
superbuffer_t buff = read(fd);
write(dbfile, buff);
//fsync(dbfile); //took this out. was slowing me down
class MyClass1 {
private int _fastCounter = 0;
private int _slowCounter = 0;
public synchronized void methodSlow() {
System.out.println("slowCounter.start " + _slowCounter);
try {
Thread.sleep(5*1000);
}
catch(Exception e) {
@evanlong
evanlong / magic.m
Created October 10, 2011 22:14
makes stuff work
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
}
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {
}
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id<NSFetchedResultsSectionInfo>)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {
}