Skip to content

Instantly share code, notes, and snippets.

View hpux735's full-sized avatar

William Dillon hpux735

View GitHub Profile
@hpux735
hpux735 / quartzPixelAlign
Created February 27, 2012 23:14
Pixel aligning lines using Quartz (from the TreeView sample code)
// Compute the needed adjustment in x and y to align our lines for crisp, exact pixel coverage. (We can only do this if the lineWidth is integral, which it usually is.)
CGFloat adjustment = 0.0;
CGFloat lineWidth = [[self enclosingTreeView] connectingLineWidth];
NSSize lineSize = NSMakeSize(lineWidth, lineWidth);
NSSize lineSizeInPixels = [self convertSizeToBase:lineSize];
CGFloat halfLineWidthInPixels = 0.5 * lineSizeInPixels.width;
if (fabs(halfLineWidthInPixels - floor(halfLineWidthInPixels)) > 0.0001) {
// If line width in pixels is odd, lay our path segments along the centers of pixel rows.
NSSize adjustmentAsSizeInPixels = NSMakeSize(0.5, 0.5);
NSSize adjustmentAsSize = [self convertSizeFromBase:adjustmentAsSizeInPixels];
// The output at time 0 is the sum of the
// previous num_taps samples times the taps
int j;
for(j = 0; j < num_taps; j++) {
float2 sample = 0;
int sample_index = i - (num_taps - 1);
if (sample_index < 0) {
sample = lastBlock[2048+sample_index];
@hpux735
hpux735 / gist:2913436
Created June 11, 2012 23:38
Core Audio
struct AQPlayerState {
AudioStreamBasicDescription mDataFormat; // 2
AudioQueueRef mQueue; // 3
AudioQueueBufferRef mBuffers[kNumberBuffers]; // 4
SInt64 mCurrentPacket; // 7
UInt32 mNumPacketsToRead; // 8
AudioStreamPacketDescription *mPacketDescs; // 9
DAGAudioSinkNode *audioSink;
};
@hpux735
hpux735 / gist:9649071
Created March 19, 2014 19:13
Reverse geocache (pic18)
#include <pic18.h>
#include <htc.h>
#include <peripheral/usart.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "delay.h"
<?xml version='1.0' encoding='ASCII'?>
<flow_graph>
<timestamp>Sat Mar 22 10:54:05 2014</timestamp>
<block>
<key>options</key>
<param>
<key>id</key>
<value>top_block</value>
</param>
<param>
@hpux735
hpux735 / gist:9815330
Created March 27, 2014 18:57
OpenCL FIR
#define num_taps 150
__constant float taps[num_taps] = {
4.5528412686211801e-04, 4.7143479283810269e-04, 4.9265664783479932e-04, 5.1935133206458756e-04, 5.5190883344588668e-04, 5.9070568604295396e-04, 6.3610320042731044e-04, 6.8844573336344591e-04, 7.4805900411431905e-04, 8.1524846452430972e-04, 8.9029772986915878e-04, 9.7346707726454198e-04, 1.0649920181980451e-03, 1.1650819514941403e-03, 1.2739189027393427e-03, 1.3916563558860344e-03, 1.5184181824196682e-03, 1.6542976731164991e-03, 1.7993566770389934e-03, 1.9536248520151279e-03, 2.1170990304274768e-03, 2.2897427036999980e-03, 2.4714856284164220e-03, 2.6622235565360503e-03, 2.8618180916923654e-03, 3.0700966730691317e-03, 3.2868526878496000e-03, 3.5118457127290654e-03, 3.7448018844713667e-03, 3.9854143989781774e-03, 4.2333441378280190e-03, 4.4882204207321872e-03, 4.7496418818490762e-03, 5.0171774673990199e-03, 5.2903675515306690e-03, 5.5687251669092235e-03, 5.8517373460285097e-03, 6.1388665687948886e-03, 6.4295523114932876e-03, 6.7232126918258892e-03, 7.0192
@hpux735
hpux735 / rtl-formatter.swift
Last active August 29, 2015 14:13
RTL-SDR file formatter for GNURadio. Uses Swift and Accelerate framework. It's MUCH faster than the GRC on the rtlsdr website.
//
// main.swift
// rtl-formater
//
// Created by William Dillon on 1/21/15.
// Copyright (c) 2015 HouseDillon. All rights reserved.
//
import Foundation
import Accelerate
@hpux735
hpux735 / gist:53abdafbab9eeeeb0329
Created February 8, 2015 03:06
Writing a string to an i2c eprom with Arduino
/*
* Use the I2C bus with EEPROM 24LC64
*
*/
#include <Wire.h> //I2C library
void writeEEPROM(char *string, unsigned char block, unsigned char address);
void printEEPRIOM();
void eraseEEPROM();
[9/39] cd /Users/admin/swift-build/build/Ninja-ReleaseAssert/swift-linux-armv7/stdlib/private/SwiftPrivate && /opt/local/bin/cmake -E make_directory /Users/admin/swift-build/build/Ninja-ReleaseAssert/swift-linux-armv7/stdlib/private/SwiftPrivate/linux/armv7-unknown-linux-gnueabihf && /opt/local/bin/cmake -E make_directory /Users/admin/swift-build/build/Ninja-ReleaseAssert/swift-linux-armv7/./lib/swift/linux/armv7-unknown-linux-gnueabihf && /Users/admin/swift-build/swift/utils/line-directive /Users/admin/swift-build/swift/stdlib/private/SwiftPrivate/SwiftPrivate.swift /Users/admin/swift-build/swift/stdlib/private/SwiftPrivate/IO.swift /Users/admin/swift-build/swift/stdlib/private/SwiftPrivate/PRNG.swift /Users/admin/swift-build/swift/stdlib/private/SwiftPrivate/ShardedAtomicCounter.swift -- /Users/admin/swift-build/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin//swiftc -c -sdk / -target armv7-unknown-linux-gnueabihf -O -D INTERNAL_CHECKS_ENABLED -I /Users/admin/swift-build/build/Ninja-ReleaseAssert/swift-li
@hpux735
hpux735 / build.swift-build
Last active February 17, 2016 18:32
llbuild script for swiftpm
client:
name: swift-build
tools: {}
targets:
"": ["<target-PackageDescription>", "<target-libc>", "<target-POSIX>", "<target-sys>", "<target-dep>", "<target-swift-build>", "<target-XCTestCaseProvider>", "<target-PackageDescription-tests>", "<target-sys-tests>", "<target-dep-tests>", "<target-Functional-tests>"]
all: ["<target-PackageDescription>", "<target-libc>", "<target-POSIX>", "<target-sys>", "<target-dep>", "<target-swift-build>", "<target-XCTestCaseProvider>", "<target-PackageDescription-tests>", "<target-sys-tests>", "<target-dep-tests>", "<target-Functional-tests>"]
PackageDescription: ["<target-PackageDescription>"]
libc: ["<target-libc>"]