Skip to content

Instantly share code, notes, and snippets.

View KryptikOne's full-sized avatar
:octocat:
Slaying Code Dragons ⚔️🐲🧑🏽‍💻

Jason KryptikOne

:octocat:
Slaying Code Dragons ⚔️🐲🧑🏽‍💻
View GitHub Profile
@KryptikOne
KryptikOne / xml-to-json.js
Last active November 30, 2016 15:42
Convert XML to JSON
/**
* A function that takes XML and converts it to JSON
* @param {xml} Input valid XML
* @returns {object} Output valid JSON
*/
function xmlToJson(xml) {
// Create the return object
var obj = {};
if (xml.nodeType == 1) { // element
.styled-ol {
counter-reset: li; // Initiate a counter
margin-left: 0; // Remove the default left margin
padding-left: 0; // Remove the default left padding
& > li {
position: relative; // Create a positioning context
padding: 0 0 0 3em; // Give each list item a left margin to make room for the numbers
//padding: 4px 8px; // Add some spacing around the content
list-style: none; // Disable the normal item numbering
border-top: 2px solid #666;
function on(elSelector, eventName, selector, fn) {
var element = document.querySelector(elSelector);
element.addEventListener(eventName, function(event) {
var possibleTargets = element.querySelectorAll(selector);
var target = event.target;
for (var i = 0, l = possibleTargets.length; i < l; i++) {
var el = target;
var p = possibleTargets[i];
@KryptikOne
KryptikOne / new-blank-window.js
Created January 22, 2016 15:37
Open new window with JS
function openNewWindow(src) {
var src = (src) ? src : 'http://google.com';
var params = [
'location=0',
'status=1',
'toolbar=1',
'scrollbars=1',
'resizable=1',
'height=' + (screen.height * .7),
'width=' + (screen.width * .7),
@KryptikOne
KryptikOne / get-index-by-key-value.js
Created January 12, 2016 22:53
Get the index of an object in an array, based on the value of a certain key
/**
* Function to Search an Array of Objects
* @param arr --- What array you're searching in
* @param key --- What key you should be looking at in each object
* @param val --- What value you're looking for
* @returns {*} - Returns you the found object that has the matching key or null if not found
*/
function getArrIndexByKeyValue(arr, key, val) {
for (var i = 0; i < arr.length; i++) {
if (arr[i][key] == val) {
@KryptikOne
KryptikOne / loading-spinner.scss
Created January 11, 2016 20:34
Loading Spinner, just requires a div with a class of spinner.
.loading-spinner {
$color: #3386d6;
position: absolute;
top: 50%;
left: 50%;
width: 30px;
height: 30px;
margin-top: -15px;
margin-left: -15px;
&:before {
@KryptikOne
KryptikOne / titles-select-menu.html
Last active January 10, 2017 20:02
Select Menu of Titles
<select name="title_select" id="title_select" class="title-select">
<optgroup label="Traditional">
<option value="mr">Mr</option>
<option value="sir">Sir</option>
<option value="miss">Miss</option>
<option value="mrs">Mrs</option>
<option value="ms">Ms</option>
<option value="madam">Madam</option>
<option value="dr">Dr</option>
<option value="professor">Professor</option>
@KryptikOne
KryptikOne / default-gitignore
Last active May 13, 2020 15:27
A default .gitignore file that I use on just about every project. It of course gets modified per project, but this is the base starting point. #git
### Packages ###
#####################################
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
@KryptikOne
KryptikOne / timezone-select-menu.html
Created September 25, 2015 19:25
Time Zones Select Menu
<select id="timezone" class="timezone" name="timezone">
<option value="-12">(GMT -12:00) Eniwetok, Kwajalein</option>
<option value="-11">(GMT -11:00) Midway Island, Samoa</option>
<option value="-10">(GMT -10:00) Hawaii</option>
<option value="-9">(GMT -9:00) Alaska</option>
<option value="-8">(GMT -8:00) Pacific Time (US &amp; Canada)</option>
<option value="-7">(GMT -7:00) Mountain Time (US &amp; Canada)</option>
<option value="-6" selected="selected">(GMT -6:00) Central Time (US &amp; Canada), Mexico City</option>
<option value="-5">(GMT -5:00) Eastern Time (US &amp; Canada), Bogota, Lima</option>
<option value="-4.5">(GMT -4:30) Caracas</option>
@KryptikOne
KryptikOne / context-menus.js
Created August 19, 2015 19:31
Context Menus
if (document.addEventListener) {
document.addEventListener('contextmenu', function(evt) {
alert("You've tried to open context menu"); // here you draw your own menu
evt.preventDefault();
}, false);
} else {
document.attachEvent('oncontextmenu', function() {
alert("You've tried to open context menu");
window.event.returnValue = false;
});