Skip to content

Instantly share code, notes, and snippets.

View rossmartin's full-sized avatar

Ross Martin rossmartin

View GitHub Profile
@rossmartin
rossmartin / AppDelegate.m
Created November 27, 2012 05:53
Don't forget the code needed for Dropbox in your didFinishLaunchingWithOptions method. You can likely copy & paste the handleOpenURL function to your AppDelegate.m
/**
* This is main kick off after the app inits, the views and Settings are setup here. (preferred - iOS4 and up)
*/
- (BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
// there will be more code in this method for your PhoneGap application
// code needed for Dropbox - Do not forget this
DBSession* dbSession =
/********* PhoneGapDropbox.m Cordova Plugin Implementation *******/
#import "PhoneGapDropbox.h"
#import <Cordova/CDV.h>
#import <DropboxSDK/DropboxSDK.h> // import the DropboxSDK
#import "AppDelegate.h"
/********* PhoneGapDropbox.h Cordova Plugin Header *******/
#import <Cordova/CDV.h>
#import <DropboxSDK/DropboxSDK.h>
DBRestClient *restClient; // declare REST client instance var to use file upload/download methods
NSString* restoreJavaScript = nil; // declare restoreJavaScript instance var for restore JavaScript callback
@interface PhoneGapDropbox : CDVPlugin
@rossmartin
rossmartin / dropbox.js
Last active October 13, 2015 06:18
Inlucde this JavaScript file in your iOS Apps index.html and call the linkDropbox() function to start the Dropbox link process.
function linkDropbox(){ // start the Dropbox link process, make a button call this function on click
cordova.exec(linkDropboxCB, linkDropboxFail, "PhoneGapDropBox", "link", [""]);
}
function linkDropboxCB(){ // this callback fires if the link method in PhoneGapDropbox.m is successful
console.log("link method in PhoneGapDropbox.m executed successfully");
}
function linkDropboxFail(err){ // this fail callback fires if the link method in PhoneGapDropbox.m fails
console.log("linkDropboxFail() - error message is below");
@rossmartin
rossmartin / dropbox.js
Last active October 13, 2015 16:08
dropbox.js - Android Version
//start the Dropbox authentication process, "link" this app to your Dropbox account
function linkDropbox(){
cordova.exec(linkDropboxCB, linkDropboxFail, "PhoneGapDropBox", "link", [""]);
//exec(<successFunction>, <failFunction>, <service>, <action>, [<args>]);
//This will marshall a request from the WebView to the Android native side, more or less boiling down to
//calling the action method on the service class, with the arguments passed in the args Array.
}
var dropBoxAuthAttempt = false; // set this global var so authDropbox() is only called once
function linkDropboxCB(){ // this callback is only ran if the native Java call in linkDropbox() was successful
@rossmartin
rossmartin / PhoneGapDropBox.java
Last active October 5, 2017 13:28
PhoneGapDropBox.java
package com.xyz.xyz; // your package name here
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
// import everything needed for Dropbox functionality
import android.content.Context;
@rossmartin
rossmartin / SocketServerDelegate.m
Created December 30, 2012 23:32
This is the server socket's didAcceptNewSocket delegate method.
// GCDAsyncSocket delegate, called when the server (device receiving JSON) accepts an incoming client connection. another socket is spawned to handle it.
- (void)socket:(GCDAsyncSocket *)sender didAcceptNewSocket:(GCDAsyncSocket *)newSocket
{
// The "sender" parameter is the listenSocket we created.
// The "newSocket" is a new instance of GCDAsyncSocket.
// It represents the accepted incoming client connection.
// Do server stuff with newSocket...
NSLog(@"Accepted new socket from %@:%hu", [newSocket connectedHost], [newSocket connectedPort]);
@rossmartin
rossmartin / SocketServerDelegate.m
Created December 31, 2012 00:33
GCDAsyncSocket delegate. This shows how to queue a read in AsyncSocket.
// GCDAsyncSocket delegate, this occurs when the server has sent the message asking the client to send JSON
- (void)socket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag
{
if (tag == TAG_ASK_FOR_JSON) {
NSLog(@"didWriteDataWithTag tag (TAG_ASK_FOR_JSON) in SocketServerDelegate.m - First Request sent from server to device sending JSON, asking it to send JSON data");
// Now start the queue to read in the JSON stream from the client
[sock readDataToData:[GCDAsyncSocket CRLFData] withTimeout:-1 tag:TAG_READ_JSON_DATA]; // parse all the way to CRLF
// You can even specify what should be used as a terminator for a byte stream
@rossmartin
rossmartin / MySQL UNION with LIMITs
Last active December 11, 2015 19:39
MySQL Combine Two Statements With LIMITs using UNION
(SELECT 'lab' AS table_name, id FROM table1
WHERE organizerClassId = '4013-5' LIMIT 1)
UNION
(SELECT 'rad' AS table_name, id FROM table2
WHERE organizerClassId = '4013-5' LIMIT 1);
@rossmartin
rossmartin / WebSQL UNION with LIMITs
Created January 27, 2013 20:19
Web SQL UNION with multiple LIMITs
SELECT * FROM (
SELECT 'lab' AS table_name, id FROM table1
WHERE organizerClassId = '4013-5' LIMIT 1)
UNION
SELECT * FROM (
SELECT 'rad' AS table_name, id FROM table2
WHERE organizerClassId = '4013-5' LIMIT 1);