Skip to content

Instantly share code, notes, and snippets.

@timanglade
timanglade / gist:7341925
Created November 6, 2013 18:51
Saving/restoring Usergrid objects from localStorage
projects = new Usergrid.Collection({
"client": client,
"type": "books",
"qs": { ql:'order by title asc', limit: 999}
});
projects.fetch(function() {
// Save to local storage
localStorage.setItem('books', projects.serialize());
})
var express = require('express');
var request = require('request')
var app = express();
app.all('/books*', function(req, res) {
request('https://api.usergrid.com/tim/sandbox'+req.url, function(err, result, usergridBody) {
try {
usergridObject = JSON.parse(usergridBody)
isbn = usergridObject.entities[0].isbn;
@timanglade
timanglade / cameras.js
Created June 22, 2013 22:25
Camera Access with PhoneGap + upload with Apigee
<!DOCTYPE html>
<html>
<head>
<title>Camera Example</title>
<script src="cordova.js"></script>
<script src="https://apigee.com/usergrid/sdk/usergrid.0.10.5.js"></script>
<script type="text/javascript">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
@timanglade
timanglade / create.js
Created June 22, 2013 19:11
Geolocation Examples
var apigee = new Usergrid.Client({
orgName:'YOUR APIGEE.COM USERNAME',
appName:'sandbox'
});
navigator.geolocation.getCurrentPosition(locationAcquired);
function locationAcquired (whatever) {
new_book = { "title":$("#title-field").val(),
Something
Using rake (0.8.7)
Using abstract (1.0.0)
Using activesupport (3.0.5)
Using builder (2.1.2)
Using i18n (0.4.1)
Using activemodel (3.0.5)
Using erubis (2.6.6)
Using rack (1.2.1)
Using rack-mount (0.6.14)
Using rack-test (0.5.7)
require 'couchrest_model'
module RcmEngine
class Organization < CouchRest::Model::Base
use_database CouchRest.database('http://<LOGIN>:<PASSWORD>@<ACCOUNT>.cloudant.com/rcm_engine_remix_rcm/')
property :description, String
property :name, String
property :remix_organization, Integer
require 'rubygems'
require 'activesupport'
def days_in_month(year, month)
(Date.new(year, 12, 31) << (12-month)).day
end
f = File.new("items.csv", "r")
@timanglade
timanglade / gist:356951
Created April 5, 2010 21:56
A Morse decoder/encoder
# Morse Decoder / Encoder
#
# Originally from http://refactormycode.com/codes/513-morse-code-encoder-decoder
# With modifications.
# Uploaded & shared for the purpose of a class at UMLV.
module Morse
$LETTER = Hash[*%w/
A .- N -.