Skip to content

Instantly share code, notes, and snippets.

@namklabs
namklabs / filetype-icon.css
Created February 27, 2012 22:37
Add filetype icon to all anchors
a[href$='.pdf'] {
display:inline-block;
padding-right:0;
padding-left:20px;
line-height:18px;
background:transparent url(/img/adobe.gif) center left no-repeat;
}
@namklabs
namklabs / placeholder.js
Created March 13, 2012 22:09
Input element placeholder text with older browser support
;
// attribute test by Jeremy Keith, http://www.abookapart.com/products/html5-for-web-designers
function elementSupportsAttribute( element, attribute ){
var test = document.createElement(element);
if (attribute in test){
return true;
} else {
return false;
}
@namklabs
namklabs / cookies.js
Created March 21, 2012 15:38
JS Cookies with jQuery alerts on pageload
;
//cookie functions
function setCookie(c_name,value,expiredays){
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}
function getCookie(c_name){
@namklabs
namklabs / mysql-database-import.bat
Last active January 23, 2018 04:29
database.mysql file import via command line
REM These commands allow you to dump a mysql database or import a database that is too large to be uploaded via PHPmyAdmin.
REM If importing, you should put your .sql file in your mysql bin dir ( for wamp: C:\wamp\bin\mysql\mysql15.5.20\bin\ )
REM If exporting, the mysql bin dir is where the exported file will show up.
REM export a mysql database
REM wamp's username is root, does not have a password
mysqldump -u username -p password(optional) databasename > databasename.sql
REM import a mysql database
mysql -u username -ppassword databasename < databasename.sql
@namklabs
namklabs / jquery.fouc.js
Created March 28, 2012 16:59
Prevent FOUC on an element or the whole body with jQuery
//From http://www.robertmullaney.com/2011/08/29/prevent-flash-of-unstyled-content-fouc-jquery/
//I have a project which uses jQuery UI for tables (formatting), buttons, tabs, etc. Even though my local resources and remotely hosted ones are saved in the browser’s cache, I still have situations where a FOUC (Flash of Unstyled Content) occurs.
//Here is a simple solution…
$(function() {
$('body').hide();
$(window).load(function(){
$('body').show();
});
});
@namklabs
namklabs / vim-html-closing-tag-linebreak.vim
Created March 28, 2012 18:12
Find all closing HTML tags and add a linebreak after each group
" Find all closing tags, add a linebreak after each grouping.
" This is useful when your whole HTML file has had the whitespace removed by a rogue WYSIWYG editor.
" NOTE: I don't think this .vim file would actually work in vim. I just gave it that extension for Gist's sake.
:%s@\(<\/\w\{1,10\}>\)\+@&\r@gc
" command explanation below
" : begin command
" % use all lines in file
" s search and replace
@namklabs
namklabs / disable-text-selection.css
Created April 10, 2012 19:16
Disable text selection - cross browser
/*
http://stackoverflow.com/a/4407335/448640
*/
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
@namklabs
namklabs / encodeURIComponent popup.js
Created April 24, 2012 16:09
quick js encodeURI script
alert( encodeURIComponent( prompt("Enter the URI:","") ) );
@namklabs
namklabs / form-testing.numbers.js
Created April 24, 2012 22:05
fill in number fields
$.each( $("input[type=text]:visible"), function(){
$(this).val() == "" ? $(this).val( Math.random() * 5000 ) : "";
});
@namklabs
namklabs / words-to-lowercase.vim
Created April 27, 2012 23:41
To Many Upper Case Words? This will fix it
" Find All Words That Have A Capital Letter In Front. Replace with lower case letters.
" NOTE: I don't think this .vim file would actually work in vim. I just gave it that extension for Gist's sake.
:1s/\<\w*\>/\l&/gc
" : begin search and replace
" 1 line number you are searching
" s/ begin search
" \< match the beginning of a word
" \w match a letter