Skip to content

Instantly share code, notes, and snippets.

View sharpred's full-sized avatar

Paul Ryan sharpred

View GitHub Profile
@valpackett
valpackett / dijkstra.clj
Created August 27, 2011 16:28
Dijkstra's algorithm in Clojure
; http://www.algolist.com/Dijkstra's_algorithm
(defn dijkstra [g src]
(loop [dsts (assoc (zipmap (keys g) (repeat nil)) src 0)
curr src
unvi (apply hash-set (keys g))]
(if (empty? unvi)
dsts
(let [unvi (disj unvi curr)
nextn (first (sort-by #(% dsts) unvi))
@sharpred
sharpred / getMongoAttachment.php
Created May 23, 2012 12:00
retrieve mongo attachment data, iterate through and retrieve each file
<?php
$mongoDB = new Mongo();
$database = $mongoDB->selectDB("BVS");
$collection = $database->createCollection('fs.files');
//to get the attachments metadata back
$query = array("metadata.formdata.claimid" => "SUS14052012-001");
// $items is a cursor of mongodata
$items = $collection->find($query);
//iterate through the collection and retrieve the named file
$grid = $database->getGridFS();
@sharpred
sharpred / updateFilesMetadata.php
Created July 18, 2012 13:23
mongo update attachments metadata
<?php
$mongoDB = new Mongo();
$database = $mongoDB->selectDB("BVS");
$collection = $database->createCollection('fs.files');
$search = array("metadata.formdata.claimid" => "4");
$replace = array('$set'=>array("metadata.formdata.mynewfield" => "wibble")); // note use of single quotes around $set. This is compulsory
$multiple = array("multiple" => true); // used to update all records that match default is false (update first record only)
$collection->update($search, $replace, $multiple);
?>
@jeffatstepup
jeffatstepup / passwalletIntent.js
Created February 17, 2015 10:18
How to open pkpass files in PassWallet from Appcelerator Titanium
/**
*
* Save pkpass to PassWallet
* See http://passwallet.attidomobile.com/PassWallet%20Developer%20Guide.pdf
*
*/
function shareToPassWallet () {
var pkpassFile,
intent,
@edwardmp
edwardmp / gist:a0ffb3ace02ce4392b26
Created June 13, 2015 15:58
Working example of accepting self-signed SSL certificate in Swift
import UIKit
import Foundation
class ViewController: UIViewController, NSURLSessionDelegate {
override func viewDidLoad() {
super.viewDidLoad()
httpGet(NSMutableURLRequest(URL: NSURL(string: "https://example.com")!))
}