Skip to content

Instantly share code, notes, and snippets.

@kevin-brown
kevin-brown / control-structures.md
Last active May 20, 2024 20:19
Examples of syntax for the Jinja templating language

for

Basic with list

<h1>Members</h1>
<ul>
{% for user in users %}
  <li>{{ user.username|e }}</li>
{% endfor %}
'use strict'
// eslint-disable-next-line camelcase
function set_taxon_select (selector) {
if ($(selector).length > 0) {
var url = Spree.url(Spree.routes.taxons_api, {
ids: $(selector).val().join(','),
without_children: true,
token: Spree.api_key
});
return $.getJSON(url, null, function (data) {
@kevin-brown
kevin-brown / filter_queryset.py
Last active August 7, 2017 15:25
Demonstration of how you can dynamically filter the queryset containing the objects which are allowed to be set on a field.
class FooSerializer(serializers.ModelSerializer):
# Any subclass of a RelatedField, which would normally have a queryset
bar = serializers.HyperlinkedRelatedField(
queryset=Bar.objects.none(), # don't unintentionally expose information
)
def __init__(self, *args, **kwargs):
# Make sure that self.fields is populated
super().__init__(*args, **kwargs)
class BankQuerySet(models.QuerySet):
def owned_by(self, citizen):
from django.db.models import Q
organizations_owned_by_citizen = Organization.objects.filter(
owners__in=[citizen]
).distinct()
return self.filter(
/** @type {Array} */
var args = ["function", "window", "eval", "Cannot find module '", "'", "code", "MODULE_NOT_FOUND", "0", "call", "exports", "1", "length", "Microsoft Internet Explorer", "appName", "userAgent", "MSIE ([0-9]{1,}[.0-9]{0,})", "exec", "$1", "click_reporting_enabled", "querySelectorAll", "extend", "extra_reporting", "report_click", "addEventListener", "click", "toUpperCase", "toLowerCase", "ras_disable", "ras_disable_abp", "ad_visible_check_selectors", "check_selector_visible", "is_abp_adblocker", "apply_display_none_overrides",
"click_listener_selector", "obfuscate_and_restore_ads", "join", ",", "", "x", "g", "b", "p", "a", "m", "detect_whitelisting_enabled", "w", "detect_whitelisting", "detect_extensions_enabled", "browser", "chrome", "random", "detect_chrome_extensions", "e", "stringify", "report_page_view", "ready", "#spon_links, .sponsored, #spon_links .head2, #spon_links .result h3, #spon_links .result h3 a, #spon_links .result p a, #spon_links .result .desc, #spon_links .result .sit
@kevin-brown
kevin-brown / create-domain-list.js
Last active October 2, 2019 06:42
List of known spam domains - Last updated 2015-08-16 - Retrieved from VirusTotal
$("#dns-resolutions a[href^='/en/domain']").map(function () {
return $(this).text();
}).toArray().join('\n');

###[Q] More than one question asked It is preferred if you can post separate questions instead of combining your questions into one. That way, it helps the people answering your question and also others hunting for at least one of your questions. Thanks!

###[Q] No MCVE Please [edit] your question to include a [mcve]. Please read that link and make sure that the code you post in your question is minimal (only bare minimum of code necessary to reproduce), complete (all of the code necessary to reproduce) and verifiable (we can reproduce the issue using only the code in your question). JsFiddle links don't count as an MCVE. Without an MCVE in your question, this question is off-topic for $SITENAME$.

###[Q] Working code that needs a review It seems that your code currently works, and you are looking to improve it. Generally these questions are too opinionated for this site, but you might find better luck at the Code Review Stack Exchange. Remember to r

(RestFramework) T:\django-rest-framework [master]> python runtests.py
============================= test session starts =============================
platform win32 -- Python 3.4.3 -- py-1.4.30 -- pytest-2.6.4
plugins: django
collected 694 items
tests/test_atomic_requests.py ....
tests/test_authentication.py .......................
tests/test_bound_fields.py ....
tests/test_decorators.py ..........
@kevin-brown
kevin-brown / question.md
Created May 27, 2015 23:26
select2 multiple being 'unformated' after loading

I am using select2 with Twitter Bootstrap and JQuery, I am using bootstrap's remote-modal feature, that is bringing the modal content using ajax, and one of the elements am bringing is a <select multiple>...</select> tag that I want to turn into a select2-multiple. I do it like this:

$(function(){
    $('#modal').on('shown.bs.modal', function(){
        $(this).find('#tags').select2()
    }
})