This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Simple script to correctly round up 2 decimal numbers. | |
* Helpful in handling currencies that use 2 decimal place. | |
* Will ensure 2 decimal places, even when ending in zeros. | |
* v = value to be rounded. | |
*/ | |
function roundTwoDecimals (v) { | |
if (typeof(v) !== 'number') { | |
return alert('v must be a number!'); | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@property | |
def update_price(self): | |
""" | |
Return a rounded price using the quantity and rate. | |
This utilizes the Decimal object to get around the strange | |
rounding behavior in Python with Base 10. The logic converts | |
both operands to Decimal objects, multiplies them, then | |
performs a ROUND_UP method using 2 decimal places. | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="control-group{% if form.name.errors %} error{% endif %}"> | |
<label class="control-label" for="name">Name:</label> | |
<div class="controls"> | |
{{ form.name }} | |
{% if form.name.errors %}<span class="help-inline">{{ form.name.errors }}</span>{% endif %} | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Check all table rows when header checkbox is checked. | |
* Also add a class to the table row for highlighting. | |
*/ | |
// Set initial header checkbox state to false | |
var checkallEnabled = false; | |
// When checkbox in table header is clicked... | |
$("#check_all").click(function() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Highlight table rows when checkbox is checked. | |
*/ | |
$("tbody>tr").filter(":has(:checkbox:checked)").addClass("success").end().click(function(event) { | |
$(this).toggleClass("success"); | |
if (event.target.type !== "checkbox") { | |
$(":checkbox", this).attr("checked", function() { | |
return !this.checked; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FilterMixin(object): | |
""" | |
View mixin which provides filtering for ListView. | |
""" | |
filter_url_kwarg = 'filter' | |
default_filter_param = None | |
def get_default_filter_param(self): | |
if self.default_filter_param is None: | |
raise ImproperlyConfigured( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import string | |
import random | |
def password_generator(size=8, chars=string.ascii_letters + string.digits): | |
""" | |
Returns a string of random characters, useful in generating temporary | |
passwords for automated password resets. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
// the minimum version of jQuery we want | |
var v = "1.8.3"; | |
// check prior inclusion and version | |
if (window.jQuery === undefined || window.jQuery.fn.jquery < v) { | |
var done = false; | |
var script = document.createElement("script"); | |
script.src = "http://ajax.googleapis.com/ajax/libs/jquery/" + v + "/jquery.min.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a href="javascript:(function(){if(window.myBookmarklet!==undefined){myBookmarklet();}else{document.body.appendChild(document.createElement('script')).src='http://somewhere.com/script.js?';}})();">Bookmarklet</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Encodes a string containing HTML characters | |
// These include &, >, <, ". | |
function simpleHTMLEncoder(str) { | |
return str.replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, """); | |
} |
OlderNewer