Skip to content

Instantly share code, notes, and snippets.

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

hernantz

🏠
Working from home
View GitHub Profile
@ojii
ojii / messages_test_mixin.py
Created October 7, 2011 10:01
django messages framework testing utilities
from contextlib import contextmanager
from django.contrib.messages.storage.base import BaseStorage, Message
from django.test.client import RequestFactory
from django.utils.decorators import method_decorator
class TestMessagesBackend(BaseStorage):
def __init__(self, request, *args, **kwargs):
self._loaded_data = []
super(TestMessagesBackend, self).__init__(request, *args, **kwargs)
@ragulka
ragulka / jquery.ui.popover.js
Created March 26, 2012 18:37
Popover widget for jQuery UI
(function($, undefined) {
var uiPopoverClasses = 'ui-popover ';
var openPopover = null;
$.widget("ui.popover", {
// Default options
options: {
offsetX: 0,
@blaix
blaix / settings.py
Created April 3, 2012 19:32
Stubbing django settings with Mock
SOME_SETTING = 'some value'
# list_detail.object_list replacement with all the things I need
def object_list(request, queryset, extra_context=None,
template_name='', paginate_by=None):
class ObjectList(ListView):
def post(self, request, *args, **kwargs):
return self.get(request, *args, **kwargs)
def get_context_data(self, **kwargs):
c = super(ObjectList, self).get_context_data(**kwargs)
@jonnyreeves
jonnyreeves / testrunner.html
Created June 2, 2012 13:32
Unit Testing Promises with Sinon.js
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css" type="text/css" media="screen" />
<!-- when.js Promises implementation -->
<script src="https://raw.github.com/cujojs/when/master/when.js"></script>
<!-- Unit testing and mocking framework -->
<script type="text/javascript" src="http://code.jquery.com/qunit/git/qunit.js"></script>
@lost-theory
lost-theory / gist:3005268
Created June 27, 2012 16:35
consume JSON REST API blueprint inside flask app
from flask import Flask, jsonify, Blueprint, current_app
import json
## REST api ###################################################################
api = Blueprint('api', __name__)
@api.route("/users")
def users():
return jsonify(users=[
@furf
furf / _.deep.js
Created July 30, 2012 17:06
underscore.js mixin for plucking nested properties
_.mixin({
// Get/set the value of a nested property
deep: function (obj, key, value) {
var keys = key.replace(/\[(["']?)([^\1]+?)\1?\]/g, '.$2').replace(/^\./, '').split('.'),
root,
i = 0,
n = keys.length;
@epicserve
epicserve / factories.py
Created October 3, 2012 19:37
Example Factory-boy (https://github.com/dnerdy/factory_boy) factory that uses a file field.
from django.template.defaultfilters import slugify
from django.contrib.sites.models import Site
from django.core.files import File
from taggit.models import Tag
from .models import Photo
import factory
import os
TEST_MEDIA_PATH = os.path.join(os.path.dirname(__file__), 'tests', 'test_media')
TEST_PHOTO_PATH = os.path.join(TEST_MEDIA_PATH, 'test_photo.png')
@isochronous
isochronous / Application.root.js
Last active November 17, 2018 10:13
Root app for drop-in multi-app Marionette framework using requireJS and the subapprouter it works with
define([
"underscore",
"backbone",
"marionette",
"vent"
],
/**
* Creates the primary `Marionette.Application` object that runs the admin framework. Provides a central point
* from which all other sub-applications are started, shown, hidden, and stopped.
@mgaitan
mgaitan / git-integrate
Last active December 16, 2015 08:39
Integrate our branch into origin/develop
#!/bin/bash
#
# Integrate our branch into origin/develop
#
# It's a shortcut for :
#
# 1. pull for last changes on develop
# 2. rebase the target branch against develop
# 3. recheck if no changes happen in the meanwhile
# 4. merge --no-ff