Skip to content

Instantly share code, notes, and snippets.

View nufaylr's full-sized avatar
👋

Nufayl Razick nufaylr

👋
View GitHub Profile

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;
@nufaylr
nufaylr / sps-getlistitems
Created August 2, 2013 09:28
sp-getlist
$().SPServices({
operation: "GetListItems",
async: false,
listName: '{FBD720B1-5DBB-4864-930A-5B76FE0C6D51}',
CAMLQuery:'<Query><OrderBy><FieldRef Name="Title" Ascending="True" /></OrderBy></Query>',
CAMLViewFields: "<ViewFields><FieldRef Name='LinkTitle' /></ViewFields>",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
//$(this).attr('ows_LinkTitle')
@nufaylr
nufaylr / sps-update
Created August 2, 2013 09:30
sp-updatelist
$().SPServices({
operation: "UpdateListItems",
async: false,
batchCmd: "New",
listName: '{FBD720B1-5DBB-4864-930A-5B76FE0C6D51}',
valuepairs: [["Title", title], ["Types", type]],
completefunc: function (xData, Status) {
}
});
@nufaylr
nufaylr / JS utilities
Last active December 21, 2015 22:29
JS utilities
function removeHash(value)
{
if(value != undefined)
{
if(value.indexOf('#') != -1)
{
value = value.split('#');
value = value[1];
return value;
}
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;
@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);