Skip to content

Instantly share code, notes, and snippets.

View ryanbaldwin's full-sized avatar

Ryan Baldwin ryanbaldwin

  • Toronto, Canada
View GitHub Profile
@ryanbaldwin
ryanbaldwin / UIButtonTypeRoundedRectInAnnotationView
Last active December 24, 2015 20:59
Trying to add a UIButtonTypeRoundedRect to an annotation view. Everything shows up fine (title and subtitle), and there's space to the right of the details where you'd expect the button to be, but the actual button itself never shows up. Any ideas?
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
MKPinAnnotationView *annotationView = nil;
if(annotation != mapView.userLocation) {
static NSString *reuseId = @"annotationView";
annotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseId];
if(!annotationView) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseId];
}
[2014-11-08T21:07:20.579+0000] [glassfish 4.0] [SEVERE] [AS-WEB-CORE-00108] [javax.enterprise.web.core] [tid: _ThreadID=209 _ThreadName=admin-listener(8)] [timeMillis: 1415480840579] [levelValue: 1000] [[
ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: java.lang.IllegalArgumentException: javax.servlet.ServletException: java.lang.ExceptionInInitializerError
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5864)
at com.sun.enterprise.web.WebModule.start(WebModule.java:691)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1041)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:1024)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:747)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2278)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1924)
@ryanbaldwin
ryanbaldwin / tree
Created November 20, 2014 13:28
Outputs the directory tree in your terminal, all pretty like.
find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
@ryanbaldwin
ryanbaldwin / user_validator.clj
Last active August 29, 2015 14:10
hipstr.validators.user-validator
(ns hipstr.validators.user-validator
(:require [noir.validation :as v]
[validateur.validation :refer :all]))
(defn validate-signup [signup]
"Validates teh incoming map of values from our signup form,
and returns a set of error messages for any invalid key.
Expects signup to have :username, :email, and :password."
(let [v (validation-set
(presence-of #{:email :password}
@ryanbaldwin
ryanbaldwin / user_validator_refactored.clj
Created November 29, 2014 21:57
The refactored user-validator namespace
(ns hipstr.validators.user-validator
(:require [noir.validation :as v]
[validateur.validation :refer :all]))
(def email-validator
(validation-set
(validate-with-predicate :email
#(v/is-email? (:email %))
:message-fn (fn [validation-map]
(if (v/has-value? (:email validation-map))
@ryanbaldwin
ryanbaldwin / user_validator_test.clj
Last active August 29, 2015 14:10
The full hipstr.test.validators.user-validator-test namespace
(ns hipstr.test.validators.user-validator-test
(:require [hipstr.validators.user-validator :as uv])
(:use clojure.test))
(defn validate-email [email]
"Validates the provided email for us, and returns the
set of validation messages for the email, if any."
(:email (uv/email-validator {:email email})))
(defn validate-username [username]
@ryanbaldwin
ryanbaldwin / refactored_user_validator.clj
Last active August 29, 2015 14:10
Illustrates the impact on refactoring writing tests can have on a namespace.
(ns hipstr.validators.user-validator
(:require [noir.validation :as v]
[validateur.validation :refer :all]))
(def email-blank-msg
"Email is a required field")
(def email-format-msg
"The email's format is incorrect")
@ryanbaldwin
ryanbaldwin / mergesort.clj
Last active October 2, 2015 22:34
A mergesort implemented in Clojure; Takes any number of unordered lists and merges them into a single merged list.
(ns ward.mergesort
(:refer-clojure :exclude [merge]))
(defn merge
"Merges two sorted lists into a single sorted list."
[right left]
(flatten (loop [r right, l left, results []]
(let [rhead (first r)
lhead (first l)]
(cond (nil? rhead) (conj results l)
(ns ward.applied-mergesort
(:refer-clojure :exclude [merge]))
(defn merge
"Merges two sorted lists into a single sorted list."
[right left]
(flatten (loop [r right, l left, results []]
(let [rhead (first r)
lhead (first l)]
(cond (nil? rhead) (conj results l)
@ryanbaldwin
ryanbaldwin / index_of.clj
Last active October 2, 2015 21:31
A solution to the classic "Find the index-of the first occurrence of substring in a string" problem, written in Clojure.
(ns ward.index-of)
(defn index-of
"Returns the first index where needle is found in haystack.
Returns -1 if the needle is not found in haystack."
[needle haystack]
(loop [n needle h haystack index 0]
(let [n-length (count n)
h-length (count h)]
(cond