This file contains hidden or 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 memoize(fn) { | |
| return function() { | |
| var args = Array.prototype.slice.call(arguments), | |
| hash = "", | |
| i = args.length; | |
| currentArg = null; | |
| while (i--) { | |
| currentArg = args[i]; | |
| hash += (currentArg === Object(currentArg)) ? | |
| JSON.stringify(currentArg) : currentArg; |
This file contains hidden or 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
| for ( | |
| var start = new Date().getTime(), | |
| iterationCount = 0, | |
| millisec = 0; | |
| millisec < 1000; | |
| iterationCount++ | |
| ) { | |
| // Your profiled code | |
| // goes here |
This file contains hidden or 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 throttle(fn, delay) { | |
| var timer = null; | |
| return function () { | |
| var context = this, | |
| args = arguments; | |
| clearTimeout(timer); | |
| timer = setTimeout(function () { | |
| fn.apply(context, args); | |
| }, delay); |
This file contains hidden or 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
| for( | |
| var sum = 0, f1 = 1, f2 = 2, next; | |
| f2 < 4E6; | |
| f2 & 1 || (sum += f2), next = f1 + f2, f2 = (f1 = f2, next) | |
| ); | |
| console.log(sum); |
This file contains hidden or 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
| // Do the maths | |
| for( | |
| var sum = 0, i = 1; | |
| i < 1000; | |
| !(i % 3 && i % 5) && (sum += i), i++ | |
| ); | |
| // Log the result | |
| console.log(sum); |
This file contains hidden or 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
| Date.prototype.getUTCDateTime = function() { | |
| var zf = function(num) { | |
| return ((num + 100) + '').substr(1); | |
| }; | |
| return [ | |
| this.getUTCFullYear(), | |
| '-', | |
| zf(this.getUTCMonth() + 1), | |
| '-', |
This file contains hidden or 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
| import urllib | |
| try: | |
| from urlparse import parse_qs | |
| except ImportError: | |
| from cgi import parse_qs | |
| def url_params(url, **kwargs): | |
| bits = url.split('?') | |
| query_vars = {} | |
| if len(bits) > 1: |
This file contains hidden or 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
| from django.conf.urls.defaults import * | |
| from blog.models import Category, Post | |
| post_info_dict = { | |
| 'queryset': Post.pub.all(), | |
| 'date_field': 'pub_date', | |
| } | |
| urlpatterns = patterns('blog.views', |
NewerOlder