Skip to content

Instantly share code, notes, and snippets.

View MaraScott's full-sized avatar
🇪🇺
Maras IT

MaraScott MaraScott

🇪🇺
Maras IT
View GitHub Profile
@MaraScott
MaraScott / htmlEncode.js
Last active May 19, 2020 18:26
Name : htmlEncode("text"), htmlDecode("text") - Language : JavaScript, jQuery - type : function - platform : generic
// http://stackoverflow.com/questions/1219860/javascript-jquery-html-encoding?answertab=votes#tab-top
function htmlEncode(value){
"use strict";
//create a in-memory div, set it's inner text(which jQuery automatically encodes)
//then grab the encoded contents back out. The div never exists on the page.
return $('<div/>').text(value).html();
}
function htmlDecode(value){
"use strict";
@MaraScott
MaraScott / length.js
Last active December 11, 2015 08:09
Name : length(obj) - Language : JavaScript - type : function - platform : generic - description : count number of item in an object - tag : length, object
// isOneOf() : see https://gist.github.com/davask/4571536
function length(obj) {
"use strict";
var count = 0;
if (isOneOf(obj, 'Object')) {
for (var k in obj) {
if (obj.hasOwnProperty(k)) {
++count;
}
}
@MaraScott
MaraScott / isOneOf.js
Last active December 11, 2015 08:09
Name : isOneOf(obj, types) - Language : JavaScript - type : function - platform : generic
// http://stackoverflow.com/questions/8525206/javascript-the-most-efficient-way-to-check-if-a-variable-is-a-function-an-arra?answertab=votes#tab-top
function isOneOf(obj, types) {
"use strict";
var type;
type = Object.prototype.toString.call(obj);
return types.split(' ').some(function (t) {
return type.indexOf(t) > -1;
});
}
@MaraScott
MaraScott / installRubbyGem.txt
Created January 30, 2013 03:57
How to : new gem with command prompt ruby - type : tutorial - platform : sass, compass, scss
http://stackoverflow.com/questions/11259140/sass-not-recognised-using-windows-command-shell
find folder like
C:\Program Files (x86)\custom\web\Ruby193\bin
where "gem" and "gem.bat" file exists
@MaraScott
MaraScott / is_empty.js
Last active December 13, 2015 18:49
Name : is_empty(obj) - Language : JavaScript - type : function - platform : generic
function is_empty(obj) {
"use strict";
// assign object type
var objType = Object.prototype.toString.call(obj);
// is type === object
if (objType === '[object Object]') {
// 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; }
@MaraScott
MaraScott / jsonConcat.js
Created February 15, 2013 02:05
Name : jsonConcat(arrayjson) - Language : Javascript, json - type : function - Platform : generic - tag : concatenation
// concat multiple json in one
function jsonConcat(arrayjson) {
"use strict";
var o = {};
for(var i=0; i<arrayjson.length; i++) {
o = concat2json(o, arrayjson[i]);
}
return o;
}
@MaraScott
MaraScott / getBrowserLanguage.js
Created February 15, 2013 02:11
Name : getBrowserLanguage() - Language : Javascript - type : function - Platform : generic - tag : browser, lang
// get browser language in this format US, FR, ...
var getBrowserLanguage = function (){
"use strict";
// navigator.userLanguage for IE, navigator.language for others
var lang = navigator.language || navigator.userLanguage;
lang = lang.split('-');
return lang[1];
}; // END FUNC
// example
@MaraScott
MaraScott / BrowserDetect.js
Created February 15, 2013 02:20
Name : BrowserDetect() - Language : Javascript - type : function - Platform : generic - tag : browser, version, OS
// see : http://www.quirksmode.org/js/detect.html
var BrowserDetect = {
init: function() {
"use strict";
this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version";
this.OS = this.searchString(this.dataOS) || "an unknown OS";
},
searchString: function(data) {
"use strict";
@MaraScott
MaraScott / checkloadjscssfile.js
Last active December 13, 2015 18:49
Name : checkloadjscssfile(filename, filetype) - Language : JavaScript - type : function - platform : generic
// see : http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml
// Load a js or a css file
var filesadded = "", //list of files already added
fileref = "";
function checkloadjscssfile (filename, filetype) {
"use strict";
if (filesadded.indexOf("[" + filename + "]") === -1) {
if (loadjscssfile(filename, filetype)) {
filesadded += "[" + filename + "]"; //List of files added in the form "[filename1],[filename2],etc"
@MaraScott
MaraScott / filterTable.sql
Last active December 13, 2015 23:39
Name : filterTable - Language : Sql - type : Select - platform : geniric - tag : filter, table
/* Filter table from a database */
/* see : http://stackoverflow.com/questions/6528531/mysql-show-tables-sort-by-table-name?answertab=votes#tab-top */
/* string $filter = filter */
/* string $dbn = database name */
SELECT table_name
FROM information_schema.tables
WHERE table_type = 'BASE TABLE' AND table_schema='$dbn' AND table_name LIKE '$filter'
ORDER BY table_name ASC;