Skip to content

Instantly share code, notes, and snippets.

@jcromartie
jcromartie / gist:5541754
Created May 8, 2013 16:41
SAX Machine/Nokogiri attribute decoding???
require 'sax-machine'
class Foo
include SAXMachine
attribute :bar
end
class FooDoc
include SAXMachine
elements :foo, :as => :foos, :class => Foo
- (IBAction)btnConvert:(id)sender {
NSString *urlString = urlField.text;
answerData = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]];
html = [[NSString alloc] initWithData:answerData encoding:NSUTF8StringEncoding];
NSLog(@"Source: %@", html);
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"ansMap\\[\\d+\\] = '(\\w+)'" options:0 error:NULL];
[regex enumerateMatchesInString:html options:0 range:NSMakeRange(0, [html length]) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
@jcromartie
jcromartie / plet.clj
Created April 25, 2013 12:32
parallel let in Clojure
(defmacro plet [bindings & forms]
(let [pairs (partition 2 bindings)
names (map first pairs)
vals (map second pairs)]
`(let [[~@names] (pvalues ~@vals)] ~@forms)))
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
[titleLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
[titleLabel setNumberOfLines:0];
[titleLabel setLineBreakMode:NSLineBreakByWordWrapping];
[self addSubview:titleLabel];
UILabel *dateLabel = [[UILabel alloc] initWithFrame:CGRectZero];
@jcromartie
jcromartie / nope.mm
Last active December 16, 2015 04:08
self.currentItem.pubDate = [[[formats map:^id(id fmt) {
[formatter setDateFormat:fmt];
return option([formatter dateFromString:text]);
}] find:^BOOL(id maybeDate) {
return ![maybeDate isEmpty];
}] getOrElse:nil];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
[titleLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
[titleLabel setNumberOfLines:0];
[titleLabel setLineBreakMode:NSLineBreakByWordWrapping];
[titleLabel setFont:[USNTheme smallTitleFont]];
[self addSubview:titleLabel];
[self setTitleLabel:titleLabel];
UILabel *summaryLabel = [[UILabel alloc] initWithFrame:CGRectZero];
@jcromartie
jcromartie / foo.web.util.clj
Created March 29, 2013 16:47
An example of generic HTTP CRUD operations over a ref holding a simple map-based data model
(ns foo.web.util
"Utilities shared by various web namespaces"
(:use compojure.core)
(:require [foo.json :as json]
[foo.model :refer (uuid)]))
(defn json-response
"Return a Ring response with the appropriate JSON content type
header and a JSON representation of obj in the body."
[obj & flags]
@jcromartie
jcromartie / deck.core.clj
Created March 22, 2013 13:57
A tiny database that records and replays events in a repository on a piece of state.
(ns deck.core
(:require [clojure.java.io :as io])
(:import java.io.PushbackReader
java.io.File
java.util.Date))
(defn- dispatch-play
[state [event-name & rest]]
(keyword event-name))
<div class="page-header">
<h1>>Navy Feeds</h1>
</div>
<table class="table table-striped">
<thead>
<tr>
<th>Name></th>
<th>URL</th>
<th>Tags</th>
<th>Actions</th>
@jcromartie
jcromartie / power.sh
Last active December 15, 2015 05:09 — forked from anonymous/power.sh
#!/bin/bash
# Please supply your own audio file...
audiofile="$1"
if [[ ! -f "$audiofile" ]]
then
echo "USAGE: $(basename ${0}) audio_file"
exit 1