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
/* | |
Fixed positioning an element for as long as it's in the boundaries of its parent element. | |
Have an element stay in a particular position of the viewport, | |
but only inside a container element. | |
This is a function to extend jQuery. If you specify a parent element, the targeted | |
element will have `position: fixed` for as long as it is inside the parent's boundaries; | |
from then on, it switches over to `position: absolute`. |
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 | |
#! -*- coding: utf-8 -*- | |
__license__ = "GPL" | |
__version__ = "1.0" | |
import os | |
import re | |
import shutil | |
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 ForeignKeyCacheMixin(object): | |
""" | |
Cache foreignkey choices in the request object to prevent unnecessary queries. | |
""" | |
def formfield_for_foreignkey(self, db_field, request, **kwargs): | |
formfield = super(ForeignKeyCacheMixin, self).formfield_for_foreignkey(db_field, **kwargs) | |
cache = getattr(request, 'db_field_cache', {}) | |
if cache.get(db_field.name): | |
formfield.choices = cache[db_field.name] | |
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
<!doctype html> | |
<html class="no-js" lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<meta http-equiv="x-ua-compatible" content="ie=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title>Foundation Starter Template</title> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script> | |
<!-- Compressed CSS --> |
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
window.setTimeout(function () { throw Error("hello world") }, 10000); |
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 python3 | |
import argparse | |
from http.server import HTTPServer, BaseHTTPRequestHandler | |
class RequestHandler(BaseHTTPRequestHandler): | |
"""Print request headers/body and respond with empty JSON object.""" | |
def do_GET(self): | |
self.send_response(200) |
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
def form_data(response: HttpResponse, **kwargs) -> dict: | |
"""Read form data from an HTML response.""" | |
return parse_html_form(response.content, **kwargs) | |
def parse_html_form(html: str, **kwargs) -> dict: | |
"""Returns form data as a dict. | |
The form lookup can be narrowed down by using attributes to filter for | |
as `kwargs`. |