Skip to content

Instantly share code, notes, and snippets.

View quevon24's full-sized avatar
🏠
Working from home

Kevin Ramirez quevon24

🏠
Working from home
View GitHub Profile
@quevon24
quevon24 / staticencoder.py
Created June 5, 2017 17:53 — forked from goldhand/staticencoder.py
Django template tag for encoding images in base64 and rendering with server
from django import template
from django.contrib.staticfiles.finders import find as find_static_file
from django.conf import settings
register = template.Library()
@register.simple_tag
def encode_static(path, encoding='base64', file_type='image'):
"""
@quevon24
quevon24 / pagination.html
Created August 7, 2017 15:51 — forked from oscarmcm/pagination.html
A Django template tag for pagination
{% load i18n %}
<div class="row">
<div class="col-xs-12">
<section class="paginator text-center">
<nav>
<ul class="pagination">
<li>
{% if page.has_previous %}
<a href="?page={{ page.previous_page_number }}" aria-label="Previous">
@quevon24
quevon24 / models.py
Created August 10, 2017 13:15 — forked from jacobian/models.py
An example of using many-to-many "through" to augment m2m relationships. See http://www.quora.com/How-do-you-query-with-a-condition-on-a-ManyToMany-model-in-Django for context.
from django.db import models
class Person(models.Model):
name = models.CharField(max_length=200)
groups = models.ManyToManyField('Group', through='GroupMember', related_name='people')
class Meta:
ordering = ['name']
def __unicode__(self):
@quevon24
quevon24 / verbatim_templatetag.py
Created August 29, 2017 23:30 — forked from paulsmith/verbatim_templatetag.py
verbatim Django template tag
"""
jQuery templates use constructs like:
{{if condition}} print something{{/if}}
This, of course, completely screws up Django templates,
because Django thinks {{ and }} mean something.
Wrap {% verbatim %} and {% endverbatim %} around those
blocks of jQuery templates and this will try its best
@quevon24
quevon24 / footer.js
Created October 22, 2017 03:10 — forked from daverogers/footer.js
Assign "active" class to navbar item based on current page URL with jQuery
def find(key, dictionary):
for k, v in dictionary.iteritems():
if k == key:
yield v
elif isinstance(v, dict):
for result in find(key, v):
yield result
elif isinstance(v, list):
for d in v:
for result in find(key, d):
@quevon24
quevon24 / gist:005020b2eb8e746f6477750d4ef8b043
Created November 17, 2017 20:21 — forked from josmera01/gist:18a2995018960c5d0bdb
Load field without Node_load
<?php
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'article')
->propertyCondition('status', 1)
->fieldCondition('field_image', 'fid', 'NULL', '!=')
->range(0, 1);
$result = $query->execute();
if (isset($result['node'])) {
@quevon24
quevon24 / AddCookiesInterceptor.java
Created December 19, 2017 18:44 — forked from tsuharesu/AddCookiesInterceptor.java
Handle Cookies easily with Retrofit/OkHttp
/**
* This interceptor put all the Cookies in Preferences in the Request.
* Your implementation on how to get the Preferences MAY VARY.
* <p>
* Created by tsuharesu on 4/1/15.
*/
public class AddCookiesInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
@quevon24
quevon24 / django-wkhtmltopdf-static-url-hack.py
Created December 22, 2017 04:10 — forked from renyi/django-wkhtmltopdf-static-url-hack.py
django-wkhtmltopdf STATIC_URL hack to make static files work on both local and remote hosting.
def render_to_response(self, context, **response_kwargs):
from django.conf import settings
STATIC_URL = settings.STATIC_URL
if 'http' not in STATIC_URL:
# wkhtmltopdf requires full uri to load css
from urlparse import urlparse
parsed = urlparse(self.request.META.get('HTTP_REFERER'))
parsed = '{uri.scheme}://{uri.netloc}'.format(uri=parsed)
context["STATIC_URL"] = "{}{}".format(parsed, settings.STATIC_URL)
@quevon24
quevon24 / FragmentPageAdapter
Created February 2, 2018 03:46 — forked from cesco89/FragmentPageAdapter
Add Fragments dynamically to ViewPager
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
public class MyFragmentPageAdapter extends FragmentPagerAdapter {