Skip to content

Instantly share code, notes, and snippets.

View aaronksaunders's full-sized avatar

Aaron K Saunders aaronksaunders

View GitHub Profile
/**
* Define our parser class. It takes in some text, and then you can call "linkifyURLs", or one of the other methods,
* and then call "getHTML" to get the fully parsed text back as HTML!
* @param text that you want parsed
*/
function Parser(text) {
var html = text;
var urlRegex = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;
@aaronksaunders
aaronksaunders / app.js
Created February 10, 2012 21:06 — forked from pixelhandler/app.js
Develop a RESTful API Using Node.js With Express and Mongoose
var application_root = __dirname,
express = require("express"),
path = require("path"),
mongoose = require('mongoose');
var app = express.createServer();
// database
mongoose.connect('mongodb://localhost/ecomm_database');
/**
* @preserve
* Titanium Cloud Module
*
* This module is used across three distinct platforms (iOS, Android, and Mobile Web), each with their own architectural
* demands upon it.
*
* Appcelerator Titanium is Copyright (c) 2009-2010 by Appcelerator, Inc.
* and licensed under the Apache Public License (version 2)
*/
<!DOCTYPE html>
<head>
<title>HTML5 Camera Fun</title>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="http://www.nihilogic.dk/labs/exif/exif.js" type="text/javascript"></script>
<script src="http://www.nihilogic.dk/labs/binaryajax/binaryajax.js" type="text/javascript"></script>
<script type="text/javascript">
// Wrapper around MPL-licensed http://www.nihilogic.dk/labs/binaryajax/binaryajax.js
// to support JavaScript typed arrays since binary strings are not supported in IE 10
var createBinaryFile = function(uintArray) {

TiAgent

Ti Agent is light-weight progressive ajax API crafted for flexibility, readability, and a low learning curve after being frustrated with many of the existing request APIs.

 request
   .post('/api/pet')
   .data({ name: 'Manny', species: 'cat' })
   .set('X-API-Key', 'foobar')
   .set('Accept', 'application/json')

.end(function(res){

@aaronksaunders
aaronksaunders / app.js
Last active December 21, 2015 03:58 — forked from rborn/app.js
var get_file = function(url, callback) {
var xhr = Ti.Network.createHTTPClient({
onload: function(e) {
// this function is called when data is returned from the server and available for use
// this.responseText holds the raw text return of the message (used for text/JSON)
// this.responseXML holds any returned XML (including SOAP)
// this.responseData holds any returned binary data
console.log('downloaded '+ url);
callback({
function RateMe(ios_url, goog_url, usecount) {
if(!Ti.App.Properties.hasProperty('RemindToRate')) {
Ti.App.Properties.setString('RemindToRate', 0);
}
var remindCountAsInt = parseInt(Ti.App.Properties.getString('RemindToRate'), 10);
var newRemindCount = remindCountAsInt + 1;
if(remindCountAsInt === -1) {
// the user has either rated the app already, or has opted to never be
// reminded again.
var myApp = angular.module('myApp').service('CordovaNetwork', ['$rootScope', '$ionicPlatform', '$q', function($rootScope, $ionicPlatform, $q) {
// Get Cordova's global Connection object or emulate a smilar one
var Connection = window.Connection || {
'ETHERNET' : 'ethernet',
'WIFI' : 'wifi',
'CELL_2G' : 'cell_2g',
'CELL_3G' : 'cell_3g',
'CELL_4G' : 'cell_4g',
'CELL' : 'cell',
'EDGE' : 'edge',
config.json
reading-image.png

This is an example of how to scaffold API endpoints to list / get / create / update / delete Posts in a Keystone website.

It's a modification of the default project created with the yo keystone generator (see https://github.com/JedWatson/generator-keystone)

Gists don't let you specify full paths, so in the project structure the files would be:

routes-index.js        -->    /routes/index.js         // modified to add the api endpoints
routes-api-posts.js    -->    /routes/api/posts.js     // new file containing the Post API route controllers