Skip to content

Instantly share code, notes, and snippets.

View idettman's full-sized avatar

Isaac A. Dettman idettman

View GitHub Profile
@idettman
idettman / JavaScript - Get window coordinates
Last active August 29, 2015 14:01
Javascript function to get browser window dimensions
function getWindowSize() {
if (window.innerWidth || window.innerHeight) {
return [window.innerWidth,window.innerHeight];
}
else {
return [(document.documentElement.clientWidth||document.body.clientWidth||document.body.scrollWidth),(document.documentElement.clientHeight||document.body.clientHeight||document.body.scrollHeight)];
}
}
@idettman
idettman / sans-jquery
Last active August 29, 2015 14:01
Sans jQuery
document.addEventListener("DOMContentLoaded", start);
Array.prototype.slice.call(document.getElementsByTagName("p"));
function Each(obj, fn) {
if (obj.length) for (var i = 0, ol = obj.length, v = obj[0]; i < ol && fn(v, i) !== false; v = obj[++i]);
else for (var p in obj) if (fn(obj[p], p) === false) break;
};
document.getElementById("clickme").addEventListener("click", function(e) {
@idettman
idettman / js-read-write-delete-cookie
Created May 12, 2014 18:14
JS Read Write Delete Cookie
@idettman
idettman / js-timer-scope-fix
Created May 12, 2014 18:19
JS - Allow scope binding for timer and setInterval
/* JavaScript polyfill to fix scope issues with the setInterval */
var __nativeST__ = window.setTimeout, __nativeSI__ = window.setInterval;
window.setTimeout = function (vCallback, nDelay /*, argumentToPass1, argumentToPass2, etc. */) {
var oThis = this, aArgs = Array.prototype.slice.call(arguments, 2);
return __nativeST__(vCallback instanceof Function ? function () {
vCallback.apply(oThis, aArgs);
} : vCallback, nDelay);
};
@idettman
idettman / mysql-rename-db.sh
Last active August 29, 2015 14:27
Shell script to rename a MySQL database by creating a new database and importing the old database data. usage> ./mysql-rename-db olddbname newdbname
GNU nano 2.2.6 File: ./mysql-rename-db.sh
#!/bin/bash
# update username and password where mysql is executed in this file
mysqlconn="mysql -u 'root' -p ''"
# export the data for the old database name
mysqldump -u root --password="" $1 > $2".sql";
# create a database for the new database name
@idettman
idettman / remove-all-select-options.js
Created October 14, 2015 15:25
Remove All Select Options
/**
* @param {HtmlSelectElement} element
*/
function removeAllSelectOptions(element)
{
while (element.options.length)
{
element.remove(0);
}
}
@idettman
idettman / remove-dom-children.js
Last active October 14, 2015 15:28
Remove all DOM children
/**
* @param {HtmlElement} element
*/
function removeAllChildren(element)
{
while (element.firstChild)
{
element.removeChild(element.firstChild);
}
}
var Executor = (function()
{
var commands = {},
executor = {
handle: function(commandName, callback)
{
var commandHandler = {
ref: this,
callback: callback
};
@idettman
idettman / to-array-copy.html
Created March 1, 2016 19:00
Shortcut to copy array or array like objects
Array.toArray = Array.prototype.slice.call;
Array.copy = Array.prototype.slice.call;
@idettman
idettman / shell copy file content to variable
Created March 15, 2016 00:56
shell copy file content to variable
# Read input file
var str input ; cat "/folder/somefile.txt" > $input
# Remove everything before "foo"
stex "]^foo^" $input > null
# Remove everything after "foo"
stex "^foo^[" $input > null