Skip to content

Instantly share code, notes, and snippets.

View nkryptic's full-sized avatar

Jacob Radford nkryptic

  • New York, NY, USA
View GitHub Profile
@nkryptic
nkryptic / functions.php
Created September 17, 2023 17:21
functions/hook to remove physical files of Wordpress subimages that PressThumb will generate dynamically (Pagely specific)
<?php
/**
* Remove the phsyical files created for the intermediate image sizes but
* after they're created to ensure the metadata is generated and saved for
* the attachment. The PressThumb service dynamically creates these images
* outside of Wordpress, so we can save disk space by removing them.
*
* Note: will interfere with any thumbnail regeration attempts
*/
require 'facter'
Facter.add(:esxi_version) do
confine :virtual => :vmware
confine :kernel => :Linux
setcode do
dmi_path = Facter::Util::Resolution.exec('which dmidecode 2> /dev/null')
if dmi_path.nil?
'unknown:no_dmidecode'
else
# Activate tab
# $ osascript set_tab.scpt 1, 2
on run argv
set window_index to item 1 in argv
set target_index to item 2 in argv
tell application "Google Chrome" to set active tab index of first window to target_index
tell application "Google Chrome" to activate
end run
@nkryptic
nkryptic / django-filter qs requirements.txt
Last active December 15, 2015 14:39
different variations for django-filter's qs method. all require the new 'strict' attribute for the FilterSet class
all implementations ensure that:
non-empty querysets are always ordered. either by submitted value when bound,
the order field's initial value or the value of the first ordering choice
when filterset is strict and bound:
* the form is validated, so errors are available
* returns empty queryset when form is invalid
* returns fully filtered queryset otherwise
from django import template
register = template.Library()
@register.simple_tag(takes_context=True)
def pager(context, page_number):
"""
for doing simple pagination with querystrings::
<a href="?{% pager page.next_page_number %}">Next page</a>
"""
@nkryptic
nkryptic / index-base.html
Last active December 14, 2015 23:39
A conditional block templatetag which outputs it's nodelist only when a sub-template declares a child block with the same name. The child block's output will be available in a context variable, "blockoutput", when inside the "ifblock".

The expected output when rendering index.html is:

<!doctype html>
<head>
  <title>example</title>
</head>
<body>
  <h2>before</h2>
  <h2><span>start</span> <span>the middle</span> <span>end</span></h2>
  <h2>after</h2>
language: python
python:
- "2.6"
- "2.7"
- "3.2"
- "3.3"
env:
- DJANGO=https://github.com/django/django/archive/master.tar.gz
import operator
from django.db import models
from django.contrib.auth.models import User
from myapp.models import License
or_list = []
values = User.objects.values_list('id').annotate(models.Max('licenses__created_at'))
for pk, dt in values:
from django.template.base import Node, Library
register = Library()
class UnindentNode(Node):
def __init__(self, nodelist):
self.nodelist = nodelist
def render(self, context):
@nkryptic
nkryptic / charfilter_overriding.py
Created February 16, 2013 02:30
example of how to override a charfilter which will be used for all charfields on a model in a filterset
from django.db import models
from django.contrib.auth.models import User
from django_filters import CharFilter, FilterSet
class ICharFilter(CharFilter):
def __init__(self, *args, **kwargs):
super(ICharFilter, self).__init__(*args, **kwargs)
self.lookup_type = 'icontains'