Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris dennda

View GitHub Profile
View gist:9cab1de2816080839953
func nilAndPrintError<T>(errorMessage: String) -> T? {
println(errorMessage)
return nil
}
// usage:
func myFunc() -> SomeType? {
return nilAndPrintError("myFunc failed, O the embarrassment!")
}
View gist:821864c529b1f10020b4
class PDFViewBitmapCacheKey: Hashable {
let name: String
let width: Int
let height: Int
let scaleMode: PDFImage.ScaleMode
let page: PDFImage.Page
init(name: String, size: CGSize, scaleMode: PDFImage.ScaleMode, page: PDFImage.Page) {
self.name = name
// Note that we want to make sure we're using integer values for the size, or we might fall prey to float imprecisions
View gist:500986
diff --git a/Library/Formula/opencv.rb b/Library/Formula/opencv.rb
index 8249202..94da337 100644
--- a/Library/Formula/opencv.rb
+++ b/Library/Formula/opencv.rb
@@ -22,7 +22,9 @@ class Opencv <Formula
# There are other optional dependencies but they don't currently exist in Homebrew.
def install
- system "cmake -G 'Unix Makefiles' -DCMAKE_INSTALL_PREFIX:PATH=#{prefix} ."
+ makefiles = "cmake -G 'Unix Makefiles' -DCMAKE_INSTALL_PREFIX:PATH=#{prefix} ."
View gist:811351
#!/usr/bin/env python
# Import VTK with special EmbedOpenGL renderer
import os
os.environ['VTK_RENDERER'] = 'EmbedOpenGL'
import vtk
import time
from pymt import *
from OpenGL.GL import *
View gist:1198272
- (void) setupSockets {
void* info = (__bridge void*) self;
readsock = CFSocketCreate(kCFAllocatorDefault, PF_INET, SOCK_DGRAM,
IPPROTO_UDP, kCFSocketReadCallBack |
kCFSocketAcceptCallBack | kCFSocketDataCallBack |
kCFSocketConnectCallBack | kCFSocketWriteCallBack,
(CFSocketCallBack)readSockCallBack, info);
....
}
View gist:1202327
GLfloat* createSlices(unsigned int num_slices) {
// Each slice has 4 vertices (GL_TRIANGLE_STRIP)
unsigned long total_verts = num_slices * 4;
// Each vertex has 3 coordinates
unsigned long total_elements = total_verts * 3;
// We have 4 verts * 3 coords = 12 elements per slice
const GLfloat one_slice[12] = {
// x, y, z
1., 1., 0.,
View gist:1202405
// Vertices drawn as GL_TRIANGLE_STRIP:
GLfloat d = 0.5f;
// We have 4 verts * 3 coords = 12 elements per slice
const GLfloat one_slice[12] = {
// x, y, z
-d, d, 0.,
d, d, 0.,
-d, -d, 0.,
d, -d, 0.,
};
View gist:1204675
{
float rotstep = ((M_PI / 2.) / 9.) / 2.;
GLKVector2 ndir = GLKVector2Normalize(direction);
_rx += ndir.y * rotstep;
if (_rx > M_PI_2)
_rx = M_PI_2;
if (_rx < -M_PI_2)
_rx = -M_PI_2;
_ry += ndir.x * rotstep;
@dennda
dennda / gist:1212172
Created Sep 12, 2011
setupSocket -- no callback
View gist:1212172
- (void) setupSocket {
struct sockaddr_in addr;
bzero(&addr, sizeof(addr));
addr.sin_len = sizeof(addr);
addr.sin_family = AF_INET;
// Ask kernel to randomly assign port
addr.sin_port = 0;
void* info = (__bridge void*) self;
@dennda
dennda / gist:1212363
Created Sep 12, 2011
This is how not to do callbacks / resolveWithTimeout
View gist:1212363
- (void)netServiceBrowser:(NSNetServiceBrowser *)netServiceBrowser
didFindService:(NSNetService *)netService
moreComing:(BOOL)moreServicesComing {
netService.delegate = self;
[netService scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[netService resolveWithTimeout:3.0];
}