Skip to content

Instantly share code, notes, and snippets.

View jacoor's full-sized avatar
💭
Building Community: https://pymasters.pl

Jacek Ostański jacoor

💭
Building Community: https://pymasters.pl
View GitHub Profile
@jacoor
jacoor / admin.py
Created February 18, 2014 10:06
basic django user account model + tests + admin
# -*- coding: utf-8 -*-
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.utils.translation import ugettext_lazy as _
from earnest.accounts.models import Account, AccessHistory
from earnest.accounts.forms import AdminPasswordChangeForm, AdminRegisterUserFullForm
class ReadonlyTabularInline(admin.TabularInline):
@jacoor
jacoor / ajax_base.html
Last active August 29, 2015 13:56
foundation reveal forms with ajax submit support
{% block main_section_content %}
{% endblock %}
<a class="close-reveal-modal">&#215;</a>
AnimatedTransitionRegion = Backbone.Marionette.Region.extend({
show: function(view){
this.ensureEl();
view.render();
this.close(function() {
if (this.currentView && this.currentView !== view) { return; }
this.currentView = view;
this.open(view, function(){
@jacoor
jacoor / ajax_setup.js
Created March 4, 2014 21:11
Django ajax csrf configuration
// using jQuery
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
@jacoor
jacoor / zendesk.py
Created March 20, 2014 19:30
django zendesk ticket
# -*- coding: utf-8 -*-
from django.conf import settings
from django.core.mail import EmailMessage
def zendesk_ticket(subject, form, request, form_type='email'):
email = form.cleaned_data['email']
if form_type == 'email':
message = """
Email: %s
var gulp = require('gulp');
var compass = require('gulp-compass');
var path = require('path');
var paths = {
styles: {
src: 'nutrimom/static/scss/*',
dest: 'nutrimom/static/.sass-cache'
}
};
/* jslint browser: true, undef: true, newcap: true, forin: true, sub: true, white: true, indent: 4, unused: false */
/* globals define: true */
define(
[
'angularAMD',
'angular-mm-foundation',
'selectize-ng'
], function (angularAMD) {
$.noConflict();
@jacoor
jacoor / fix_local.sh
Created July 16, 2014 06:49
Simple script to get local django dev up to date. Mac version. Paste it into your local repository, just make sure to set file to be ignored by git.
#!/bin/bash
git pull
ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install -r requirements.txt
./manage.py migrate
sh ./scripts/bind_solr.sh
./manage.py rebuild_index --noinput
@jacoor
jacoor / angular_preloader.html
Created August 12, 2014 22:00
Shows preloader on page load and hides when JS starts. Why hides? Because there is no showPreloader variable in $scope.
{% block preloader %}
{% if user.is_authenticated %}
<div data-ng-if="showPreloader">
{% assign name="loadingText" %}{% trans "Loading..." %}{% endassign %}
{% include 'inc/preloader.html' %}
</div>
{% endif %}
{% endblock %}
@jacoor
jacoor / contenteditable
Created August 14, 2014 18:25
clearing clipboard contents from everything except <a href="*">*</a> on paste
elm.bind('paste', function(e) {
//console.log(e);
e.preventDefault();
var text = (e.originalEvent || e).clipboardData.getData("text/html");
if (!text){
console.log('no html');
text = (e.originalEvent || e).clipboardData.getData("text/plain");
}
var temp = $('<div />');
$(temp).html(text);