Skip to content

Instantly share code, notes, and snippets.

View guillaumepiot's full-sized avatar

Guillaume Piot guillaumepiot

View GitHub Profile
@guillaumepiot
guillaumepiot / gist:5391722
Created April 15, 2013 22:15
DJANGO - ADMIN TOOLS - Dashboard default class
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from admin_tools.dashboard import Dashboard, AppIndexDashboard
from admin_tools.dashboard import modules
# to activate your index dashboard add the following to your settings.py:
#
# ADMIN_TOOLS_INDEX_DASHBOARD = 'test_proj.dashboard.CustomIndexDashboard'
@guillaumepiot
guillaumepiot / urls.py
Last active December 16, 2015 06:29
DJANGO - CMS Base - Default URLs
"""
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.8/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
@guillaumepiot
guillaumepiot / gist:5442196
Last active December 16, 2015 13:29
SOCIAL - Twitter share
// We bind a new event to our link
$('a.tweet').click(function(e){
//We tell our browser not to follow that link
e.preventDefault();
//We get the URL of the link
var loc = $(this).attr('href');
//We get the title of the link
@guillaumepiot
guillaumepiot / gist:5442391
Last active December 16, 2015 13:29
SOCIAL - Facebook share
// In you page header, add the open graph meta tags
// <meta property="og:title" content="title" />
// <meta property="og:description" content="description" />
// <meta property="og:image" content="thumbnail_image" />
// We bind a new event to our link
$('a.facebook').click(function(e){
//We tell our browser not to follow that link
e.preventDefault();
// HTML for the share on Tumblr link:
//
//<a href="http://onefoolishact.com" title="Website title" data-description="The description goes here" class="tumblr" style="display:inline-block; text-indent:-9999px; overflow:hidden; width:31px; height:31px; background:url('http://platform.tumblr.com/v1/share_3.png') top left no-repeat transparent;" target="_blank">Share on Tumblr</a>
//
// and before the </body> add:
//
// <script type="text/javascript" src="http://platform.tumblr.com/v1/share.js"></script>
$('a.tumblr').click(function(e){
@guillaumepiot
guillaumepiot / gist:5460846
Last active December 16, 2015 16:09
JQUERY - Trail navigator
// HTML
<div id="mattress_slider">
<div class="mattress_container">
<div class="mattress_slider">
<div class="product-list-item"></div>
<div class="product-list-item"></div>
<div class="product-list-item"></div>
...
</div>
@guillaumepiot
guillaumepiot / gist:5509760
Last active December 16, 2015 22:49
PYTHON - Decorator with no arguments
def wrap(f):
def wrapped_f(*args):
return f(*args)
return wrapped_f
# Example
# @wrap
# def my_function():
# pass
#
@guillaumepiot
guillaumepiot / gist:5509777
Last active December 16, 2015 22:49
PYTHON - Decorator with arguments
def wrapWithArgs(arg1, arg2, arg3):
def wrap(f):
def wrapped_f(*args):
print arg1, arg2, arg3
return f(*args)
return wrapped_f
return wrap
# Example
# @wrap(1,2,3)
@guillaumepiot
guillaumepiot / gist:5583149
Created May 15, 2013 10:54
DJANGO - Admin custom list filter
class CategoryListFilter(SimpleListFilter):
# USAGE
# In your admin class, pass trhe filter class as tuple for the list_filter attribute:
#
# list_filter = (CategoryListFilter,)
# Human-readable title which will be displayed in the
# right admin sidebar just above the filter options.
@guillaumepiot
guillaumepiot / gist:5585590
Last active December 5, 2016 09:25
jQuery - YouTube video play/stop on modal open/hide
$('.close').click(function(){
$('#video').modal('hide');
})
$('#open-video').click(function(){
$('#video').modal({'show':true}).on('hidden', function () {
toggleVideo('hide');
});
toggleVideo();
})