Skip to content

Instantly share code, notes, and snippets.

View troystribling's full-sized avatar

Troy Stribling troystribling

  • San Francisco, CA
View GitHub Profile
@troystribling
troystribling / gist:42ec640f10317267139f
Created March 23, 2014 17:47
BlueCap Characteristic Profile Xcode Snippet
[serviceProfile createCharacteristicWithUUID:<#UUID#>
name:<#name#>
andProfile:^(BlueCapCharacteristicProfile* characteristicProfile) {
characteristicProfile.properties = CBCharacteristicPropertyRead | CBCharacteristicPropertyWrite;
[characteristicProfile serializeObject:^NSData*(id data) {
return nil;
}];
[characteristicProfile afterDiscovered:^(BlueCapCharacteristic* chararacteristic) {
}];
[characteristicProfile deserializeData:^NSDictionary*(NSData* data) {
@troystribling
troystribling / eeprom_objects.h
Created March 23, 2014 17:06
Simple CRUD for storing objects using Arduino EEPROM library.
#include <EEPROM.h>
#include <Arduino.h>
#include "log.h"
template <class T> class EEPROMObject {
public:
EEPROMObject(uint16_t _offset, uint8_t _maxObjects) : offset(_offset), maxObjects(_maxObjects){};
uint16_t create(uint8_t& index, const T& value);
uint16_t update(uint8_t index, const T& value);
uint16_t read(uint8_t index, T& value);
@troystribling
troystribling / gist:95811ad507dc877d98ee
Created July 31, 2014 02:52
Find all paths to climb a digital mountain
(ns climbing
(:require [clojure.string :as string])
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; part a ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Each mountain block has 2 children it follows that for a mountain of size n
; the total paths will equal total number of block sequences from top to base
; taking one from each row which is given by p=2^(n-1)
(defn simple-path-count
@troystribling
troystribling / Notify.swift
Created November 23, 2014 16:53
UIAlertControllerExtensions and Notification handler
import UIKit
class Notify {
class func resetEventCount() {
eventCount = 0;
UIApplication.sharedApplication().applicationIconBadgeNumber = 0
}
class func withMessage(message:String) {
@troystribling
troystribling / agent_xmpp_examples.rb
Created August 3, 2009 02:42
Agent XMPP Example Application
##########################################################################################################
require 'rubygems'
require "#{File.dirname(__FILE__)}/../../lib/agent_xmpp"
##########################################################################################################
# before filters
#.........................................................................................................
# only online contacts can send command messages
before :command => :all do
jid = params[:from]
xmpp_pubsub_messages.xml
*** get user disc#info
<iq to='noone@somewhere.com' id='disco1' type='get'>
<query xmlns='http://jabber.org/protocol/disco#info'/>
</iq>
*** create user@somewhere.com pubsub root node (sent from account user@somewhere.com)
<iq id='29293' to='pubsub.somewhere.com' type='set' xmlns='jabber:client'>
@troystribling
troystribling / ebs_snap.rb
Created December 30, 2011 16:57
Take snaps of EBS volumes with Fog
#!/usr/bin/env ruby
require 'rubygems'
require 'fog'
config = YAML.load(File.read(ARGV[0]))
volumes_to_snap = YAML.load(File.read(ARGV[1]))
time = Time.now
puts "\nCreating snaps #{time.to_s}"
@troystribling
troystribling / symbolize_keys.rb
Created January 11, 2012 20:43
Recursive symbolize_keys
def symbolize_keys!(thing)
case thing
when Array
thing.each{|v| symbolize_keys!(v)}
when Hash
thing.symbolize_keys!
thing.values.each{|v| symbolize_keys!(v)}
end
end
@troystribling
troystribling / gist:2491439
Created April 25, 2012 17:18
Objective C Array Map
@interface NSArray (Extensions)
- (NSArray *)mapObjectsUsingBlock:(id (^)(id obj, NSUInteger idx))block;
@end
@implementation NSArray (Extensions)
- (NSArray *)mapObjectsUsingBlock:(id (^)(id obj, NSUInteger idx))block {
NSMutableArray *result = [NSMutableArray arrayWithCapacity:[self count]];
@troystribling
troystribling / gist:2603108
Created May 5, 2012 15:01
Objective C Class Name as String
#import <objc/runtime.h>
@interface NSObject (Extensions)
- (NSString*)className;
@end
@implementation NSObject (Extensions)