Skip to content

Instantly share code, notes, and snippets.

@Macagare
Macagare / gist:4344082
Created December 20, 2012 09:20
Javascript: check Textarea max length
$("textarea[maxlength]").keydown( function(e) {
var key = e.which; // backspace = 8, delete = 46, arrows = 37,38,39,40
if ( ( key >= 37 && key <= 40 ) || key == 8 || key == 46 ) return;
return $(this).val().length < $(this).attr( "maxlength" );
});
@Macagare
Macagare / gist:4225778
Created December 6, 2012 16:26
Terminal: curl username password
curl -u username:password http://example.com
@Macagare
Macagare / gist:4201930
Created December 4, 2012 08:49
PHP: Social Media Links
<!-- bookmark on Delicious -->
<a rel="nofollow" href="http://delicious.com/post?url=<?php the_permalink(); ?>&amp;title=<?php echo urlencode(get_the_title($id)); ?>" title="Bookmark this post at Delicious">Bookmark at Delicious</a>
<!-- submit to Digg -->
<a rel="nofollow" href="http://digg.com/submit?phase=2&amp;url=<?php the_permalink(); ?>" title="Submit this post to Digg">Digg this!</a>
<!-- tweet on Twitter -->
<a rel="nofollow" href="http://twitter.com/home?status=<?php echo urlencode("Currently reading: "); ?><?php the_permalink(); ?>" title="Share this article with your Twitter followers">Tweet this!</a>
<!-- submit to StumbleUpon -->
@Macagare
Macagare / gist:4201925
Created December 4, 2012 08:48
Javascript: Function - is_empty(obj)
function is_empty(obj) {
"use strict";
// Assume if it has a length property with a non-zero value
// that that property is correct.
if (obj.length && obj.length > 0){ return false; }
if (obj.length && obj.length === 0){return true; }
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) { return false; }
}
@Macagare
Macagare / gist:4160860
Created November 28, 2012 12:22
Jquery: Find is a checkbox is checked
// Find out if a single checkbox is checked or not.
// The function will returns true or false:
$('#checkBox').attr('checked');
@Macagare
Macagare / gist:4160859
Created November 28, 2012 12:22
Javascript: Prevent multiple submit of your form
$(document).ready(function() {
$('form').submit(function() {
if(typeof jQuery.data(this, "disabledOnSubmit") == 'undefined') {
jQuery.data(this, "disabledOnSubmit", { submited: true });
$('input[type=submit], input[type=button]', this).each(function() {
$(this).attr("disabled", "disabled");
});
return true;
}
else
@Macagare
Macagare / gist:4160867
Created November 28, 2012 12:24
Jquery: Disable “Enter” key in forms
$("#form").keypress(function(e) {
if (e.which == 13) {
return false;
}
});
@Macagare
Macagare / gist:4160856
Created November 28, 2012 12:21
Javascript: mooth scrolling to an anchor
$(document).ready(function() {
$("a.topLink").click(function() {
$("html, body").animate({
scrollTop: $($(this).attr("href")).offset().top + "px"
}, {
duration: 500,
easing: "swing"
});
return false;
});
@Macagare
Macagare / session_test.cfm
Created November 22, 2012 13:14
Coldfusion: session test on multiple servers
<cfscript>
writeOutput("You are on server: " & cgi.local_host & "<br/>");
if( structKeyExists(url, "action") ) {
if ( url.action eq "new" ) {
createSessionTest();
}
} else {
if( not structKeyExists(session, "test") ){
writeOutput("Sorry, but there is no session test");
}
@Macagare
Macagare / gist:4129901
Created November 22, 2012 08:01
Javascript: Check if jquery exists
if (jQuery) {
// jQuery is loaded
} else {
// jQuery is not loaded
}
if (typeof jQuery == 'undefined') {
// jQuery is not loaded
} else {
// jQuery is loaded