Skip to content

Instantly share code, notes, and snippets.

@namklabs
namklabs / rgba2hex.js
Created June 19, 2014 18:02
rgb/a color to hex color
// Partial credit for this goes to the broken script I found at http://www.sitepoint.com/jquery-convert-rgb-hex-color/
function rgb2hex(rgb){
rgb = rgb.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*(\d*)\.?(\d*)\s*)?\)$/);
return "#" +
("0" + parseInt(rgb[1],10).toString(16)).slice(-2) +
("0" + parseInt(rgb[2],10).toString(16)).slice(-2) +
("0" + parseInt(rgb[3],10).toString(16)).slice(-2);
}
[
{ "keys": ["ctrl+tab"], "command": "next_view" },
{ "keys": ["ctrl+shift+tab"], "command": "prev_view" }
]
@namklabs
namklabs / bookmarklet
Created March 5, 2014 00:49
random game from thegamesdb
javascript:window.location="http://thegamesdb.net/game/"+Math.floor(Math.random()*18000);
@namklabs
namklabs / checkjQuery.js
Created March 4, 2014 14:57
run code to check when jQuery is ready
function checkjQuery() {
if (window.jQuery) {
$(function() {
//your code here
});
} else {
window.setTimeout(checkjQuery, 100);
}
}
checkjQuery();
$.fn.equalheight = function( remove ) {
// Reset heights from the last viewport resize so that values do not get wacky-large.
this.height('auto');
// if remove is true, just reset the heights and return
if ( remove ) {
return;
}
@namklabs
namklabs / equal-height.js
Created February 20, 2014 16:46
jQuery Equal Height
$.fn.equalheight = function( remove ){
if( remove == false ){
$.each( this, function(){
this.css('height','auto');
});
return;
}
// Reset heights from the last viewport resize so that values do not get wacky-large.
@namklabs
namklabs / equalheight.js
Last active June 8, 2016 18:44
Force sibling columns with .equal-height class to size to the largest height of the group.
$.fn.equalheight = function(){
var $selection = this;
var $groups = [];
while( $selection.length > 1 ){// If $selection.length is greater than 1, then it must be 2, meaning there are at least 2 equal-height divs left. This will prevent an infinite loop if there is an equal-height div without a partner equal-height div.
// Find an equal-height group.
$groups.push( $selection.eq(0).siblings('.equal-height').addBack() );
// Reduce selection by the latest equal-height group.
$selection = $selection.not( $groups[ $groups.length - 1 ] );
// Drop groups that only have 1 element - it doesn't make any sense to have a lone equal-height element.
// https://github.com/mikebranski/jquery-nospam
// implementation
$(function(){
function reverse(s){
return s.split("").reverse().join("");
}
var tld = addr.substring( addr.lastIndexOf('.') + 1 );
@namklabs
namklabs / .gitignore
Last active December 29, 2015 01:09
WordPress .gitignore
.DS_Store
Thumbs.db
dwsync.xm
_notes/
*.svn
*.swo
*.swp
~
*~
~*
@namklabs
namklabs / copyright.js
Created October 30, 2013 21:48
Puts current year into a <span> in the footer of your website