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
var bootmaps = bootmaps || {}; | |
bootmaps.InfoWindow = function(opts) { | |
opts = opts || {}; | |
google.maps.OverlayView.apply(this, arguments); | |
this.map_ = opts.map || ""; | |
this.content_ = opts.content || ""; | |
this.disableAutoPan_ = opts.disableAutoPan || false; | |
this.title_ = opts.title || ""; | |
this.position_ = opts.position || new google.maps.LatLng(0, 0); |
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
from django.core.exceptions import ImproperlyConfigured | |
class EditInPlaceMixin(object): | |
detail_template_name = None | |
def get_detail_template_names(self): | |
""" | |
Returns a list of template names to be used for the request. Must return | |
a list. May not be called if render_to_detail_response is overridden. |
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
var TastypieCollection = Backbone.Collection.extend({ | |
initialize: function(options) { | |
this.paginator = new models.Paginator({}, this); | |
}, | |
parse: function(response) { | |
this.paginator.set(response.meta); | |
return response.objects || response; | |
}, |
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
In : from onefinestay.geo.models import Place | |
In : p = Place.objects.prefetch_related('categories').get(id=1460) # Only prefetching categories | |
In : p.categories.all() | |
Out: [<Category: Miscellaneous>, <Category: For kids>] | |
In : p.regions.all() | |
Out: [<Region: Belgravia>, <Region: Bloomsbury>, <Region: Clerkenwell>, <Region: City of London>] | |
In : p.regions.clear() |
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 | |
from scapy.all import * | |
ap_list = [] | |
def PacketHandler(pkt) : | |
if pkt.haslayer(Dot11) and pkt.type == 0 and pkt.subtype == 8 and pkt.addr2 not in ap_list: | |
ap_list.append(pkt.addr2) |
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 socket | |
rawSocket = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(0x0003)) | |
rawSocket.bind(("mon0", 0x0003)) | |
ap_list = set() | |
while True: | |
pkt = rawSocket.recvfrom(2048)[0] | |
if pkt[26] == "\x80": | |
if pkt[36:42] not in ap_list and ord(pkt[63]) > 0: | |
ap_list.add(pkt[36:42]) |
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
Javascript gives us an option to do things a bit differently. Rather than wait around for a function to finish by returning a value, we can use callbacks to do it asynchronously. This is useful for things that take a while to finish, like making an AJAX request, because we aren’t holding up the browser. We can keep on doing other things while waiting for the callback to be called. In fact, very often we are required (or, rather, strongly encouraged) to do things asynchronously in Javascript. |
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
Two problems: | |
1) Individual annotations can't be filtered | |
2) `prefetch_related` doesn't allow for filtered relations | |
The `annotate()` method is currently used for calculating | |
aggregates for each result in a queryset, but it could be | |
used more generally as an API for attaching the result of | |
some calculation to each model in a queryset - whether it | |
be a single value (an aggregate calculation) or multiple |
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
from django.conf import settings | |
from django.core.files.storage import Storage | |
from django.utils import importlib | |
def load_class(class_string): | |
class_module, class_name = class_string.rsplit('.', 1) | |
class_module = importlib.import_module(class_module) | |
return getattr(class_module, class_name) |
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
from itertools import count | |
def migrate_children(tree_id, node, counter): | |
for index, child in enumerate(Region.objects.filter(parent=node).order_by('name')): | |
child.tree_id = tree_id | |
child.lft = counter.next() | |
migrate_children(tree_id, child, counter) | |
child.rgt = counter.next() | |
child.save() |