Skip to content

Instantly share code, notes, and snippets.

View dmozzy's full-sized avatar

Daniel Moscufo dmozzy

  • Perth, Western Australia
View GitHub Profile
@dmozzy
dmozzy / project.clj
Created May 17, 2012 13:49
project.clj showing the new :aot outpur
(defproject GeoTaskList "1.0.0-SNAPSHOT"
:description "Geolocated Tasklist mobile application"
:dependencies [[org.clojure/clojure "1.3.0"] [cheshire "2.2.0"] [compojure "1.0.1"]]
:dev-dependencies [[appengine-magic "0.4.7"]]
:aot [GeoTaskList.app_servlet GeoTaskList.core GeoTaskList.persistence])
@dmozzy
dmozzy / persistence.clj
Created May 11, 2012 14:22
Adding user to the persistence.clj file
;Loads all locations. Retrieves the location field map for all locations
; and then adds in the locationId key value pair for each location.
(defn get-all-locations [user]
(map
(fn [k]
(assoc (:location k) :locationId (ds/key-id k)));This line sets the id onto the map at load time
(ds/query :kind Location :filter (= :user user))))
;Deletes a location by locationId, note we need to check that the user is the one who owns the location
(defn delete-location [user locationId]
@dmozzy
dmozzy / core.clj
Created May 11, 2012 14:17
Adding User to the Application
; Get Email function
(defn getEmail []
(.getEmail (aeu/current-user)))
;Example of adding user to the routes
(GET "/locations" []
(json-response {:locations (persist/get-all-locations (getEmail))}))
@dmozzy
dmozzy / core.clj
Created May 11, 2012 14:10
Adding Google Authentication
;Middleware to add authentication
(defn require-login [application]
(fn [request]
(if
(aeu/user-logged-in?)
(application request)
(ring-response/redirect
(aeu/login-url))
)))
@dmozzy
dmozzy / CalcDistance.js
Created April 16, 2012 13:00
Calculate Distance using google.maps.geometry.spherical.computeDistanceBetween
<script src="http://maps.google.com/maps/api/js?sensor=false&libraries=geometry" type="text/javascript"></script>
<script type="text/javascript">
function calcDistance (fromLat, fromLng, toLat, toLng) {
return google.maps.geometry.spherical.computeDistanceBetween(
new google.maps.LatLng(fromLat, fromLng), new google.maps.LatLng(toLat, toLng));
}
</script>
@dmozzy
dmozzy / Locations.html
Created April 16, 2012 12:53
Task List Div
<!-- Task Page -->
<div data-role="page" id="task-page">
<div data-role="navbar">
<ul>
<li><a href="#location-page" >Location</a></li>
<li><a href="#task-page" class="ui-btn-active ui-state-persist">Tasks</a></li>
</ul>
</div>
<div data-role="content">
@dmozzy
dmozzy / Locations.js
Created April 16, 2012 12:50
Task List javascript
function getTasks() {
$.mobile.showPageLoadingMsg("a", "Loading Tasks", false);
$.getJSON( '/tasks',
function(data) {
$('#tasks-list').empty();
navigator.geolocation.getCurrentPosition(function(position) {
$.each( data.tasks, function(i, task) {
var distance = calcDistance(position.coords.latitude, position.coords.longitude, task.taskLat, task.taskLng)/1000.0;
@dmozzy
dmozzy / Locations.js
Created April 14, 2012 14:42
Task Edit Submit function
$("form[name='task-edit-form']").submit(function() {
if ($("form[name='task-edit-form']").validate().numberOfInvalids()==0) {
$.post("/task", $("form[name='task-edit-form']").serializeArray(), function(){
$.mobile.changePage($("#task-page"), { transition: "pop", role: "page", reverse: false } );
});
}
return false;
});
@dmozzy
dmozzy / Locations.html
Created April 14, 2012 14:39
Task Edit Page
<!-- Edit Task Popup-->
<div data-role="page" id="task-edit-page">
<div data-role="header">
<h1>Task</h1>
</div>
<div data-role="content">
<form name="task-edit-form">
<input id="taskId" name="taskId" type="hidden"/>
<label for="taskName">Task Name</label>
<input id="taskName" name="taskName" type="text" class="required" minlength="2"/>
@dmozzy
dmozzy / persistence.clj
Created April 11, 2012 14:22
Blog #3 Task persistence changes Defentity
(ds/defentity Task [^:key taskId, locationId, ^:clj task])