Posts

Showing posts from 2013

POSTing ajax data in query-string format to Django

1. Sending query-string formatted data with jQuery.ajax() The ' data' setting of jQuery.ajax() setting may either contain a String or a PlainObject . In case of a string, the data is sent 'as-is'. See example 1: $.ajax({    type: 'POST',    data: "test,1,2,3"); -> data will be sent as "test,1,2,3" In case of an object, it is automatically converted to a query-string, no matter what the 'contentType' setting is. See example 2: $.ajax({    type: 'POST',    data: {"test": 1, "test2"="two"}); -> data will be sent as "?test=1&test2=two" Objects must be a set of key/value pair(s). If any value is an array, the conversion depends on the traditional setting. If 'traditional ' is set to true , the ajax() method will only be able to send shallow objects: a value can be an indexed array, but not an associative array ( use json instead ). The conversion looks l...

POSTing json data to Django (ajax)

1. jQuery.ajax() doesn't automatically encode data to JSON Your client code is responsible for encoding its data into a json string, otherwise jQuery.ajax() will try to send it as a query-string. Even if you set the 'contentType' to "application/json" and provide an object that can be serialized into json, the ajax() function will turn it into a query-string. $.ajax({    type: 'POST',     contentType: "application/json",     data: {"test": 1}); -> data will be sent as "?test=1" Note: as long as you don't need to send (complex) objects, it may be easier to send query-string formatted data to Django. See this post for more details. So, your client code will need to turn its data into a json string, before passing it to ajax() . $.ajax({    type: 'POST',     contentType: "application/json",     data: JSON.stringify({"test": 1})); This also works on objects: var tmpObject = ne...

Getting started with Google APIs and Python

General Docs oAuth2 overview : https://developers.google.com/accounts/docs/OAuth2 more oAuth2 : https://developers.google.com/accounts/docs/OAuth2Login YouTube APIs : https://developers.google.com/youtube   For service accounts, Google APIs use JWT instead of oAuth2. However, not all API resources are available using this type of authentication.  Tools API overview : https://developers.google.com/apis-explorer/  API discovery service : https://developers.google.com/discovery/   oAuth2 API playground : https://developers.google.com/oauthplayground/ Mgmt Apps API console (old-style) : https://code.google.com/apis/console/b/0/?noredirect API Cloud console (new) : https://cloud.google.com/console Developer Keys (YouTube API v2) : https://code.google.com/apis/youtube/dashboard/gwt/index.html Python Guides YouTube API getting started (api v3), with samples: https://developers.google.com/youtube/v3/ overview : https://developers.google.com...

bootstrap form with single text input

http://stackoverflow.com/questions/15239236/bootstrap-modal-dialogs-with-a-single-text-input-field-always-dismiss-on-enter-k

Optimize saving FK and M2M relationships in django

See also http://stackoverflow.com/questions/2846029/django-set-foreign-key-using-integer     employee = Employee ( first_name = "Name" , last_name = "Name" )     employee . type_id = 4     employee . save (update_fields = ["type",]) ForeignKey and M2M fields store their value in an attribute with _id at the end, which you can access directly to avoid visiting the database.

Django field, form and model validation process

Django's form and field validation process can be best understood by looking at the code in django's BaseForm class (in django.forms.forms) - see below. See also this blog post for a graphic overview. The form.full_clean() method is called by django at the start of the validation process (by form.is_valid(), usually immediately after the view receives the posted data). full_clean() performs a 3 phase validation , with each phase corresponding to a call of one of the protected methods below: self._clean_fields() : Field validation This method iterates over the form fields: For each field, it calls the Widget's value_from_datadict() method, passing the complete post data in a QueryDict. The Widget's task is to retrieve its own value from this QueryDict and return it. The returned value is then passed to the Field's own clean() method. This method does the initial validation (e.g. checking if the value is not empty), without touching the db. If the Field's...

DjangoCon EU 2013: Russell Keith-Magee - Class-Based Views: Untangling t...

Image
Slides: https://speakerdeck.com/freakboy3742/class-based-views-untangling-the-mess

Getting started with redis

Start with http://openmymind.net/2012/1/23/The-Little-Redis-Book/ Browse the redis docs More: Using Redis instead of memcached: http://oldblog.antirez.com/post/redis-as-LRU-cache.html   https://developer.mozilla.org/en-US/docs/Mozilla/Redis_Tips Redis failover: http://stackoverflow.com/questions/9223840/redis-fail-over  

Managing & Monitoring Redis

http://stackoverflow.com/questions/8614737/what-are-some-recommended-tools-to-monitor-a-redis-database http://snmaynard.com/2013/01/22/redis-masterclass-part-two-monitoring-redis/ https://github.com/antirez/redis-sampler http://www.quora.com/Redis/What-are-5-mistakes-to-avoid-when-using-Redis : on using redis as a db-replacement

Add feedly to chrome RSS readers

Name: Feedly URL: http://www.feedly.com/home#subscription/feed/%s

Importing photos and videos into mac

Camcorder Movies (iMovie) Connecting External Movie camera * make sure iPhoto -> preferences -> General: "Connecting camera opens" is set to 'No Application'. * if iMovie asks to create thumbnails for iPhoto on startup -> allow it do so  (otherwise it won't detect the camcorder) Plugin camcorder to iMovie (and create disc on camcorder) -> import videos from camera window which will pop up in iMovie Saving Videos select 'Share' -> 'Export Movie...' (= better quality than quicktime exports) Saving Photos from Video select 'Share' -> 'Export Movie using Quicktime' : * Export: 'Movie to Image Sequence' * Options: JPEG, frames per second = 30 iPhone Movies and Pictures open the 'Image Capture' application: * select a folder and press import or import all -> imports both videos and pictures

memcached stats

http://blog.elijaa.org/index.php?post/2010/12/24/Understanding-Memcached-stats-cachedump-command

Memcached Internals

http://martinfitzpatrick.name/article/control-memcached-from-the-command-line http://work.tinou.com/2011/04/memcached-for-dummies.html : "Memcached is LRU per slab class, but not globally LRU" "Which brings me to another point, items/chunks are not actively reclaimed/expired.  Memached does not have a background thread that explicitly expires items, reclaiming used chunks for new items.  When a slab needs a chunk and there are no more pages, Memcache will look at the queue tail for items to evict.  Memcache will make a best effort to evict expired items (items you've explicitly set to expire after some time).  In scenario 1, item 2, an expired item, is evicted.  However, in scenario 2, item 1, which has not yet expired, will be evicted, even though item 4 would seem like the better candidate.  But since item 4 is not near the tail, Memcached stops looking and just expires item 1." http://highscalability.com/strategy-break-memcache-dog-pile...

Drupal Translated Menu's

http://hojtsy.hu/blog/2011-nov-19/drupal-7s-new-multilingual-systems-part-8-menu-languages-and-translation

PJAX & caching

PJAX & caching http://albertoconnor.ca/blog/2013/Jan/22/pjax-vs-json https://github.com/defunkt/jquery-pjax http://37signals.com/svn/posts/3112-how-basecamp-next-got-to-be-so-damn-fast-without-using-much-client-side-ui