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 / restrict-bootstrap-menu.scss
Created March 8, 2017 20:04
Restricting Bootstrap's (3.x.x) mobile menu in mobile form no matter the window size.
// Restricting Bootstrap's navigation to the mobile view
@media (min-width: 768px) {
.navbar-header {
float: none;
}
.navbar-left,.navbar-right {
float: none !important;
}
.navbar-toggle {
display: block;
/**
* Fisher–Yates Shuffle - https://bost.ocks.org/mike/shuffle/
* @param array - {array} - The array to shuffle
* @returns {array} - The shuffled array
*/
function shuffleItems(array) {
var m = array.length, t, i;
// While there remain elements to shuffle…
while (m) {
// Pick a remaining element…
@KryptikOne
KryptikOne / generate-uuid.js
Last active March 1, 2017 01:59 — forked from kaizhu256/gist:4482069
Very fast and simple uuid4 generator benchmarked on http://jsperf.com/uuid4/8
/*jslint bitwise: true, indent: 2, nomen: true, regexp: true, stupid: true*/
(function () {
'use strict';
var exports = {};
exports.uuid4 = function () {
//// return uuid of form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
var uuid = '', ii;
for (ii = 0; ii < 32; ii += 1) {
switch (ii) {
case 8:
@KryptikOne
KryptikOne / package.json
Last active April 17, 2017 23:53 — forked from addyosmani/package.json
npm run-scripts boilerplate
{
"name": "my-app",
"version": "1.0.0",
"description": "My test app",
"main": "src/js/index.js",
"scripts": {
"jshint:dist": "jshint src/js/*.js",
"jshint": "npm run jshint:dist",
"jscs": "jscs src/*.js",
"browserify": "browserify -s Validating -o ./dist/js/build.js ./lib/index.js",
@KryptikOne
KryptikOne / get-siblings.js
Last active December 5, 2016 19:31
Get element siblings
/**
* Get all siblings of an element
* @param {Node} elem The element
* @return {Array} The siblings
*/
var getSiblings = function (elem) {
var siblings = [];
var sibling = elem.parentNode.firstChild;
for (; sibling; sibling = sibling.nextSibling) {
if (
@KryptikOne
KryptikOne / javascript aspect ratio calculation (with GCD)
Created August 23, 2016 18:51 — forked from phobeo/javascript aspect ratio calculation (with GCD)
javascript aspect ratio calculation algorithm (take the GCD and divide both elements of resolution)
/* euclidean GCD (feel free to use any other) */
function gcd(a,b) {if(b>a) {temp = a; a = b; b = temp} while(b!=0) {m=a%b; a=b; b=m;} return a;}
/* ratio is to get the gcd and divide each component by the gcd, then return a string with the typical colon-separated value */
function ratio(x,y) {c=gcd(x,y); return ""+(x/c)+":"+(y/c)}
/* eg:
> ratio(320,240)
"4:3"
> ratio(360,240)
@KryptikOne
KryptikOne / DropZone.jsx
Created August 22, 2016 15:15 — forked from pizzarob/01_DropZone.jsx
HTML5 Drag and Drop React Component
import React, {PropTypes} from 'react';
import classNames from 'classnames';
class BatchDropZone extends React.Component {
static propTypes = {
// function that recieves an array of files
receiveFiles: PropTypes.func.isRequired,
/**
* A function to determine if an array contains an item
* @param needle - [Number||String] - The array to search through
* @returns [boolean] - Returns true or false
*/
function arrContainsItem(needle) {
var findNaN = needle !== needle; // Per spec, the way to identify NaN is that it is not equal to itself
var indexOf;
if(!findNaN && typeof Array.prototype.indexOf === 'function') {
@KryptikOne
KryptikOne / change-obj-keys.js
Last active July 15, 2016 19:45
Change the keys of an object within an array.
// TODO - Only operates on a single object at the moment.
// TODO - would be nice to be able to operate on more than one key at a time
function changeKey(oldKey, newKey, arr) {
// Create a temporary array
var newArr = [];
// Loop through everything in the original array
for (var i = 0; i < arr.length; i++) {
// Create a reference to the current object that you're operating on within the array
var obj = arr[i];
@KryptikOne
KryptikOne / css-js-puns.txt
Last active May 25, 2016 18:23
CSS & JS Puns
#bermuda-triangle {
display: none;
}
#chuck-norris {
color: #BADA55;
}
.push-up-bra {
margin-top: -25%; overflow: visible;
}
#wife {