Skip to content

Instantly share code, notes, and snippets.

;; factory factories, etc.
(def dbf (doto (DocumentBuilderFactory/newInstance)
(.setNamespaceAware true)))
(def doc-builder (.newDocumentBuilder dbf))
(defn namespace-map
"Returns an implementation of NamespaceContext ... actual usefulness TBD"
[mapping]
(let [prefixes (fn [uri] (map key (filter #(= uri (val %)) mapping)))]
@jcromartie
jcromartie / atom.cljs
Last active December 14, 2015 20:19 — forked from newsomc/atom.cljs
(defn make-ghost
[color]
{:get-tick 0, :eatable nil, :color nil, :eaten nil, :specs color, :position nil, :due nil, :map nil, :direction nil})
(def ghost-specs ["#00FFDE" "#FF0000" "#FFB8DE" "#FFB847"])
(def game-state (atom {:state nil
:audio []
:ghosts (mapv make-ghost ghost-specs)
:eaten-count 0
@jcromartie
jcromartie / navbar.rb
Last active December 14, 2015 15:38
Convert one super-sized (ideally iPad landscape @2x) image into the slew of images required to implement a non-repeating nav bar background at all sizes and resolutions for iOS.
#!/usr/bin/env ruby
# Takes one Retina iPad landscape nav bar image, and creates all of
# the requisite sizes for use on each device and orientation. Crops
# part of the image for iPhone portrait size.
#
# This is ONLY necessary for non-repeating or non-resizable (i.e. with
# cap insets) nav bar images. This program is an illustration of why
# you should discourage your designers from doing this.
#
NSDictionary *metrics = @{@"padding": @25};
NSDictionary *views = NSDictionaryOfVariableBindings(imageView, thumbnailsView, container, titleLabel);
void (^addConstraint)(NSString *) = ^(NSString *format) {
[mainView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:format options:0 metrics:metrics views:views]];
};
addConstraint(@"|-padding-[thumbnailsView]-padding-|");
addConstraint(@"V:[thumbnailsView(==100)]-padding-|");
addConstraint(@"|-padding-[imageView][thumbnailsView]");
@jcromartie
jcromartie / sha1.mm
Last active December 14, 2015 09:29
@implementation NSString (JPCSHA1)
- (NSString *)jpc_SHA1String
{
unsigned char md[CC_SHA1_DIGEST_LENGTH];
NSData *data = [self dataUsingEncoding:NSUTF8StringEncoding];
CC_SHA1([data bytes], [data length], md);
NSMutableString *result = [NSMutableString string];
for (int ii = 0; ii < CC_SHA1_DIGEST_LENGTH; ii++) {
[result appendFormat:@"%02x", md[ii]];
import Leap, sys
class SampleListener(Leap.Listener):
def on_init(self, controller):
print "Initialized"
def on_connect(self, controller):
self.last_fingers = 0
print "Connected"
- (void)showAlert
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"wut" message:@"really?" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
alert.show;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
BOOL success = NO;
int tries = 0;
while (!success && tries < 2)
{
if ([__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:error])
{
success = YES;
}
else
{
@implementation UIColor (strings)
+ (UIColor *)colorFromRGBHexString:(NSString *)colorString
{
if (colorString.length == 7) {
const char *colorUTF8String = [colorString UTF8String];
int r, g, b;
sscanf(colorUTF8String, "#%2x%2x%2x", &r, &g, &b);
return [UIColor colorWithRed:(r / 255.0) green:(g / 255.0) blue:(b / 255.0) alpha:1.0];
}
#define UIColor255(r, g, b, a) [UIColor colorWithRed:(r / 255.0) green:(g / 255.0) blue:(b / 255.0) alpha:a]