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 / 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);
@jacoor
jacoor / dates.py
Created August 25, 2014 13:39
Django template dates functions - template tags.
from datetime import datetime
from dateutil.relativedelta import relativedelta
from django.template import Library
from django.template import Node, TemplateSyntaxError
from django.utils.timezone import get_current_timezone
from django.template.defaultfilters import date
from django.conf import settings
register = Library()
@jacoor
jacoor / aa-input.html
Last active August 29, 2015 14:06
angular simple aa-field directive for generating form fields from django options response
<li class="form-field" ng-class="{invalid: errors[name], error: errors[name]}">
<input ng-model="model" ng-init="model" type="{[{field.type}]}" ng-required="{[{field.required}]}" placeholder="{[{field.label}]}" ng-maxlength="{[{field.max_length}]}" name="{[{name}]}"/>
<ng-include ng-if="errors[name]" src="'templates/directives/aa-forms/error_list.html'"></ng-include>
</li>
@jacoor
jacoor / aa-ios-statusbar.js
Created November 24, 2014 14:37
ios status bar ngcordova directive
/* jslint browser: true, undef: true, newcap: true, forin: true, sub: true, white: true, indent: 4, unused: false */
/* globals define: true, Settings: true, console: true */
define([
'app/app',
'ngCordova',
], function(
App
) {
"use strict";
@jacoor
jacoor / pylintrc
Last active August 29, 2015 14:15
pylintrc file used by ArabellaTech to find missing translations in python source code. Usage: pylint --rcfile=pylintrc module. Requires: http://www.technomancy.org/python/pylint-i18n-lint-checker/ and pylint 1.4.1
[MASTER]
# Specify a configuration file.
#rcfile=
# Python code to execute, usually for sys.path manipulation such as
# pygtk.require().
#init-hook=
# Profiled execution.
@jacoor
jacoor / zipcode.py
Created June 10, 2015 20:20
Django rest framework uszipcode field
from rest_framework.fields import RegexField
from localflavor.us.forms import USZipCodeField as FormUSZipCodeField
class USZipCodeField(RegexField):
""""
A form field that validates input as a U.S. ZIP code. Valid formats are
XXXXX or XXXXX-XXXX.
.. note::
If you are looking for a form field with a list of U.S. Postal Service
locations please use :class:`~localflavor.us.forms.USPSSelect`.
@jacoor
jacoor / DRFUSPhoneField.py
Created June 10, 2015 21:12
django rest framework us phone field
import re
from django.core.validators import EMPTY_VALUES
from django.utils.encoding import smart_text
from rest_framework.fields import CharField
from localflavor.us.forms import USPhoneNumberField as FormUSPhoneNumberField, phone_digits_re
from django.core.exceptions import ValidationError
@jacoor
jacoor / JiraCopy.js
Last active December 18, 2020 17:33
Bookmarklet to copy jira ticket # + title for easier commit creation. Just install this as a bookmarklet in your browser (tested in chrome) and use.
javascript:!function(a){var b=document.createElement("textarea"),c=document.getSelection();b.textContent=a,document.body.appendChild(b),c.removeAllRanges(),b.select(),document.execCommand("copy"),c.removeAllRanges(),document.body.removeChild(b)}(document.title.split("]")[0].replace("[","")+" - "+document.getElementById("summary-val").textContent);