Skip to content

Instantly share code, notes, and snippets.

View joshuatbrown's full-sized avatar

Josh Brown joshuatbrown

View GitHub Profile
@joshuatbrown
joshuatbrown / LinkedStack.swift
Created May 29, 2015 20:50
Stack in Swift, implemented with a linked list
class Element<T> {
let value: T
var next: Element<T>? = nil
init(value: T, next: Element<T>?)
{
self.value = value
self.next = next
}
}
@joshuatbrown
joshuatbrown / toomanylines.sh
Created November 11, 2014 14:55
Print the number of lines for any file that's over 400 lines
#!/bin/bash
for file in $*; do
if [ -d $file ]
then
echo "it's a directory"
else
count=`wc -l < $file`
if [ $count -gt 400 ]
then
-(BOOL)appIsPresentInLoginItems
{
NSString *bundleID = @"blah";
NSArray *jobDicts = (__bridge NSArray *)SMCopyAllJobDictionaries( kSMDomainUserLaunchd );
NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
return [[evaluatedObject valueForKey:@"Label"] isEqualToString:bundleID] && [[evaluatedObject valueForKey:@"OnDemand"] boolValue];
}];
return [[jobDicts filteredArrayUsingPredicate:predicate] count] >= 1;
@joshuatbrown
joshuatbrown / rgbmacro.txt
Created April 14, 2011 05:42 — forked from sween/rgbmacro.txt
Macro for converting from hex to UIColor
#define UIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
cell.textColor = UIColorFromRGB(0x333333);
@joshuatbrown
joshuatbrown / xdist.sh
Created May 6, 2010 17:24
Builds the iPhone project in the current directory for ad-hoc distribution
if [[ $# == 0 ]]; then
echo "ERROR: Please supply target name"
echo "Required usage: xdist <target-name>"
echo "Optional usage: xdist <target-name> <destination-directory> (defaults to Desktop)"
exit 1
elif [[ $# == 1 ]]; then
target="$1"
dest=~/Desktop
elif [[ $# == 2 ]]; then
target="$1"
@joshuatbrown
joshuatbrown / list_add_if_not_null.groovy
Created October 27, 2009 21:17
A method for list that only adds the object if it's not null
List.metaClass.addIfNotNull = {
if (it != null) add(it)
}
def list = []
list.addIfNotNull(null)
assert 0 == list.size()
list.addIfNotNull("foo")
@joshuatbrown
joshuatbrown / Fibonacci.clj
Created July 2, 2009 00:12
Fibonacci in Clojure
(defn fib [x]
(if (= x 0) 0
(if (= x 1) 1
(+ (fib (- x 1)) (fib (- x 2)))))
)