Skip to content

Instantly share code, notes, and snippets.

View nufaylr's full-sized avatar
👋

Nufayl Razick nufaylr

👋
View GitHub Profile
window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, gotFS, fail);
function fail(error) {
console.log(error)
}
function gotFS(fileSystem) {
fileSystem.root.getDirectory("data", {create: true, exclusive: false}, gotDir, fail);
}
/*
* adds "remove" event triggered when a DOMNode is removed,
* allowing to register DOM elements to be removed when a
* given other element is removed from dom.
*
* (last tested with jQuery 1.4.4)
*/
(function($,undefined){
// register node to be removed when the base node is removed
/**
* Prepare the App Folder
*/
(function(){
window.appRootDirName = ".myapp";
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log("device is ready");
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
<?php
/**
* Convert a multi-dimensional array into a single-dimensional array.
* @author Sean Cannon, LitmusBox.com | seanc@litmusbox.com
* @param array $array The multi-dimensional array.
* @return array
*/
function array_flatten($array) {
if (!is_array($array)) {
@nufaylr
nufaylr / fileTransfer.js
Last active October 13, 2015 08:16 — forked from coryjthompson/0.js
var fileTransfer = new FileTransfer();
fileTransfer.onprogress = function(result){
var percent = result.loaded / result.total * 100;
percent = Math.round(percent);
console.log('Downloaded: ' + percent + '%');
};
fileTransfer.download(remoteFile, localPath, successCallback, errorCallback);
@nufaylr
nufaylr / mobileOS
Created July 15, 2014 13:47
get mobile OS and version
function getOSInfo(){
var userOS;
var userOSver;
var ua = navigator.userAgent;
var uaindex;
// determine OS
if ( ua.match(/iPad/i) || ua.match(/iPhone/i) ){
userOS = 'iOS';
uaindex = ua.indexOf( 'OS ' );
@nufaylr
nufaylr / sqlite.js
Last active October 26, 2015 09:52
SQLite with ngCordov Code Examples
angular.module("starter").controller('userController', [ '$rootScope', '$cordovaSQLite'
function( $rootScope, $cordovaSQLite ) {
// Opening the database
$rootScope.db = $cordovaSQLite.openDB({ name: "databaseName.db" });
// Create tabel if not existing
$cordovaSQLite.execute($rootScope.db,
"CREATE TABLE IF NOT EXISTS user_tabel (id integer primary key, user_name text, email text)",
[ "john", "john@who.com" ]).then(function(res) {

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@nufaylr
nufaylr / download.jquery.js
Last active December 14, 2015 00:08
Push Download file
jQuery.download = function(url, data, method){
//url and data options required
if( url && data ){
//data can be string of parameters or array/object
data = typeof data == 'string' ? data : jQuery.param(data);
//split params into form inputs
var inputs = '';
jQuery.each(data.split('&'), function(){
var pair = this.split('=');
inputs+='<input type="hidden" name="'+ pair[0] +'" value="'+ pair[1] +'" />';
@nufaylr
nufaylr / console
Created June 19, 2013 09:48
Fallback if the console doesn't exist. IE
if (!console) {
var console = {},
func = function () { return false; };
console.log = func;
console.info = func;
console.warn = func;
console.error = func;