Skip to content

Instantly share code, notes, and snippets.

Avatar

Sean Codes sean-codes

View GitHub Profile
View JavaScript Array Sort
function sortArr(arr, func){
var sortedArr = []
for(var i in arr){
for(var o in sortedArr){
if(func ? func(arr[i], sortedArr[o]) < 0 : arr[i] < sortedArr[o]){ break }
o++
}
sortedArr.splice(o, 0, arr[i])
}
@sean-codes
sean-codes / AddCommasToNumber.js
Created Sep 15, 2017
Testing Speed of Adding Commas to a number
View AddCommasToNumber.js
var testNumber = 3453453453434
var tests = 10000;
//Test 1
setTimeout(function(){
var time = performance.now()
for(var i = 0; i < tests; i++)
numberAddComma(testNumber)
console.log('Function: ' + (performance.now() - time))
@sean-codes
sean-codes / Fira Code Cursive
Last active Aug 6, 2017 — forked from MattMcFarland/styles.less
Ligature fonts for atom
View Fira Code Cursive
/*
* Your Stylesheet
*
* This stylesheet is loaded when Atom starts up and is reloaded automatically
* when it is changed and saved.
*
* Add your own CSS or Less to fully customize Atom.
* If you are unfamiliar with Less, you can read more about it here:
* http://lesscss.org
*/
@sean-codes
sean-codes / Faster Background Patterns
Last active May 31, 2017
Rendering a texture before drawing it to the canvas
View Faster Background Patterns
var canvas = document.querySelectorAll('canvas')[0]
canvas.width = 400;
canvas.height = 400;
var ctx = canvas.getContext('2d')
var img=document.getElementById("texture");
//var pat=ctx.createPattern(img,"repeat");
//var time = performance.now()
//for(var i = 0; i < 1000; i++){
@sean-codes
sean-codes / arrayChunks.js
Last active Sep 15, 2017
Javascript Split Array into Chunks
View arrayChunks.js
function splitArrayIntoChunks(arr, chunkLen){
var chunkList = []
var chunkCount = Math.ceil(arr.length/chunkLen)
for(var i = 0; i < chunkCount; i++){
chunkList.push(arr.splice(0, chunkLen))
}
return chunkList
}
var testArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
View Video Game Spell System
var spells = {
shield: {
buff: {
type: 'reflect',
duration: 60
},
castTime: 30,
mana: -20
},
@sean-codes
sean-codes / Resizable Contianer Script
Created Feb 7, 2017
Javascript Resizable Container
View Resizable Contianer Script
var responsive = document.querySelector('.responsive');
var resize = document.querySelector('.resize');
var content = document.querySelector('.content');
var mousedown = false;
var locX = 0;
var locY = 0;
var side = "";
resize.addEventListener('mousedown', function(event){
@sean-codes
sean-codes / gist:cc81441621234001d4bd2b449f03521b
Last active Feb 5, 2017
Button select random from array
View gist:cc81441621234001d4bd2b449f03521b
//Vanilla
button = document.getElementsByTagName('button')[0];
button.addEventListener('click', function(){
rotate();
});
var rotate = function(){
var sides = ['show-front', 'show-back', 'show-left', 'show-right', 'show-top', 'show-bottom'];
var side = sides[Math.floor(Math.random()*sides.length)];
@sean-codes
sean-codes / gist:2248a0f76e3287cccd6b8a3a61141ba5
Created Feb 1, 2017
Convert Milliseconds to a HH:MM:SS string
View gist:2248a0f76e3287cccd6b8a3a61141ba5
var milliseconds = 101000;
console.log(convertMillToString(milliseconds));
function convertMillToString(milliseconds){
var totalSeconds = milliseconds/1000;
var totalMinutes = Math.floor(totalSeconds/60);
//Return Values
var hours = Math.floor(totalMinutes/60);
var minutes = totalMinutes - (hours*60);
View ColdFusion Recursion Function
<cfsetting showdebugoutput='no'>
<cfscript>
var string = '{
"title":"Test Discount",
"code":"boomshaka",
"type":"by_percent",
"discountValue":"10",
"dateStart":"01/01/2017",
"dateEnd":"01/31/2017",
"aggregator":"any",