Skip to content

Instantly share code, notes, and snippets.

@netsuite
netsuite / clearfix.css
Created May 21, 2013 20:30
css: clearfix:after
.myDiv .clearfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
@netsuite
netsuite / boilerplate.js
Created May 21, 2013 16:17
js: boilerplate
//Filename: boilerplate.js
define([
// These are path alias that we configured in our bootstrap
'jquery', // lib/jquery/jquery
'underscore', // lib/underscore/underscore
'backbone' // lib/backbone/backbone
], function($, _, Backbone){
// Above we have passed in jQuery, Underscore and Backbone
// They will not be accessible in the global scope
{
"auto_complete_commit_on_tab": true,
"bold_folder_labels": true,
"caret_style": "phase",
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"draw_minimap_border": true,
"draw_white_space": "all",
"ensure_newline_at_eof_on_save": true,
"fade_fold_buttons": false,
"file_exclude_patterns":
@netsuite
netsuite / deferredWait.js
Created April 24, 2013 01:54
js: deferred wait
/**
* Use: $.wait(1000).then( goMakeTea );
**/
$.wait = function(duration) {
return $.Deferred(function(def){
setTimeout(def.resolve, duration);
});
}
@netsuite
netsuite / jsonObjFromURL.js
Created April 23, 2013 15:54
js: Get JSON object from a URL
// url = "http://localhost/index.php?module=search&param1=4";
function jsonObjFromURL (url){
var parameters = url.split("?"),
jsObject = {},
jsObjectParams = {},
paramPair;
jsObject.baseURL = parameters[0];
@netsuite
netsuite / parseQueryString.js
Created April 19, 2013 16:02
js: Parse Query String
/**
* Parse Query String
* @param {string} name of value
* @return {string}
* @uses : var year = parseQueryString("year"); // returns "2013"
*/
function parseQueryString ( name ) {
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
@netsuite
netsuite / isEmpty.js
Created April 18, 2013 18:32
js: is_empty object
// Speed up calls to hasOwnProperty
var hasOwnProperty = Object.prototype.hasOwnProperty;
function is_empty(obj) {
// null and undefined are empty
if (obj == null) return true;
// Assume if it has a length property with a non-zero value
// that that property is correct.
if (obj.length && obj.length > 0) return false;
@netsuite
netsuite / getBase64Image.js
Created April 18, 2013 15:43
js: getBase64Image for use inside .ss
function getBase64Image(img) {
// Create an empty canvas element
var canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.height;
// Copy the image contents to the canvas
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0);
@netsuite
netsuite / findById.js
Created April 17, 2013 22:16
ss: findById / findByName
function findById(source, id) {
for (var i = 0; i < source.length; i++) {
if (source[i].name === id) {
return source[i];
}
}
throw "Couldn't find object with id: " + id;
}
@netsuite
netsuite / observe.js
Last active December 16, 2015 08:09
js: observe input event
//Observe input events
// Do your stuff after 1 seconds of last user input
$(document).on('input keyup', '.observe', function () {
var $this = $(this);
var delay = 500; // 0.5 seconds delay after last input
clearTimeout($this.data('timer'));
$this.data('timer', setTimeout(function () {
$this.removeData('timer');
// Do your stuff after 0.5 seconds of last user input