Skip to content

Instantly share code, notes, and snippets.

View KoryNunn's full-sized avatar

Kory Nunn KoryNunn

View GitHub Profile
$.fn.colorToday = function(property){
var now = new Date(),
color = '#',
day = now.getDate(),
month = now.getMonth() + 1,
year = now.getFullYear().toString().slice(2);
day < 10 && (day = '0' + day);
month < 10 && (month = '0' + month);
color += day.toString() + month.toString() + year;
@KoryNunn
KoryNunn / Map
Last active December 10, 2015 20:39
A Sorta Kinda Map object. Use anything as a key, retrieves the associated value. Not as fast as a real map, but faster than an array.
(function(){
//***********************************************
//
// A Sorta Kinda Map object
//
//***********************************************
function fastEach(array, callback) {
for (var i = 0; i < array.length; i++) {
@KoryNunn
KoryNunn / gist:4518395
Created January 12, 2013 14:57
Add to Chrome custom style-sheet to make all webpages darker (if your screen is too bright.)
html:after{
content:'';
position:fixed;
top:0;
bottom:0;
left:0;
right:0;
background: black;
opacity:0.8;
pointer-events:none;
@KoryNunn
KoryNunn / gist:4531223
Created January 14, 2013 16:21
Gets the users position, caching requests between position checks. Solves huge lag issue in chrome for android.
var requestCallbacks = [],
ready = true;
function getPosition(callback){
requestCallbacks.push(callback);
if(ready){
ready = false;
navigator.geolocation.getCurrentPosition(function(position){
while(requestCallbacks.length){
requestCallbacks.pop()(position);
@KoryNunn
KoryNunn / checkbox.css
Last active December 11, 2015 05:29
Pretty checkboxes.
.checkbox{
border-radius:2px;
border:1px solid rgba(0,0,0,0.3);
display:inline-block;
width:40px;
height:20px;
background:rgba(50,50,50,0.7);
box-shadow:inset 0 2px 5px rgba(0,0,0,0.3);
}
@KoryNunn
KoryNunn / gist:5194180
Last active December 15, 2015 03:29
Simple closest element.
function closest(target, selector){
while(target && target.parentNode && Array.prototype.slice.apply(target.parentNode.querySelectorAll(selector)).indexOf(target)<0){
target = target.parentNode;
}
return target === document ? null : target;
}
@KoryNunn
KoryNunn / fastEach.js
Last active December 16, 2015 19:50
A simplified forEach loop that's faster than Array.forEach
function fastEach(items, callback) {
for (var i = 0; i < items.length && !callback(items[i], i, items);i++) {}
return items;
}
module.exports = fastEach;
// Module A does events
module.exports = function DoEventStuff(){
/*
Do DOM event things like A.on('event')
Stores info about bindings in an array.
*/
@KoryNunn
KoryNunn / count subobjects
Created February 21, 2014 06:43
Counts the number of unique object instances within an object. It's slow.
function countObjChildren(thing){
var visited = [];
function count(thing){
for(var key in thing){
var prop = thing[key];
if(prop != null && typeof thing[key] === 'object'){
if(visited.indexOf(prop)<0){
visited.push(prop);
count(prop);
@KoryNunn
KoryNunn / gist:9202155
Created February 25, 2014 03:32
SSL certificate checking function, inspired by apple.
function checkSSL(){
return 'lol probably';
}