Skip to content

Instantly share code, notes, and snippets.

View darthwade's full-sized avatar

Vadym Petrychenko darthwade

View GitHub Profile
@darthwade
darthwade / gist:9305669
Created March 2, 2014 12:11
Protractor toContainClass custom matcher
beforeEach(function() {
this.addMatchers({
toContainClass: function (expected) {
var self = this;
var deferred = protractor.promise.defer();
self.actual.getAttribute('class').then(function(classes) {
var result = classes && classes.search(new RegExp(expected, 'i')) > 0;
if (result) {
@darthwade
darthwade / gist:9310975
Created March 2, 2014 18:15
JS String.format, String.prototype.format
// "{0} is dead, but {1} is alive! {0} {2}".format("ASP", "ASP.NET")
if (!String.prototype.format) {
String.prototype.format = function() {
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
@darthwade
darthwade / gist:9466722
Created March 10, 2014 15:06
Angular HTTP statuses helper
'use strict';
angular.module('au.common')
.constant('httpStatus', {
isInformational: function(code) {
return code >= 100 && code <= 199;
},
isSuccess: function(code) {
return code >= 200 && code <= 299;
define([
'angular',
'restangular',
'../config'
], function (angular) {
'use strict';
angular.module('convertiser.common')
.service('systemService', function (Restangular) {
@darthwade
darthwade / gist:28806783bc5189a4ec43
Last active August 29, 2015 13:59
JS Module Template
/**
* Angular Fine Uploader
* @version 0.1.0
* @homepage https://github.com/darthwade/angular-fine-uploader
* @author Vadym Petrychenko https://github.com/darthwade
* @license The MIT License (http://www.opensource.org/licenses/mit-license.php)
* @copyright 2014 Vadym Petrychenko
*/
(function (factory) {
if (typeof define === 'function' && define.amd) {
@darthwade
darthwade / gist:41f3687510a70945a047
Created July 2, 2014 11:14
Delayed function, throttle
Function.prototype.delayed = function (delay) {
var timer = 0;
var callback = this;
return function() {
clearTimeout(timer);
timer = setTimeout(callback, ms);
};
};
document.getElementById('search').addEventListener('keyup',search.delayed(200));
@darthwade
darthwade / Element.getElementsByClassName.polyfill.js
Last active August 29, 2015 14:04
Polyfill for Element.getElementsByClassName(search)
if (!Element.prototype.getElementsByClassName) {
Element.prototype.getElementsByClassName = function (search) {
var d = this, elements, pattern, i, results = [];
if (d.querySelectorAll) { // IE8
return d.querySelectorAll("." + search);
}
if (d.evaluate) { // IE6, IE7
pattern = ".//*[contains(concat(' ', @class, ' '), ' " + search + " ')]";
elements = d.evaluate(pattern, d, null, 0, null);
while ((i = elements.iterateNext())) {
@darthwade
darthwade / Array.indexOf.polyfill.js
Created July 20, 2014 10:54
Polyfill for Array.indexOf(searchElement, fromIndex)
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (searchElement, fromIndex) {
var k;
if (this == null) {
throw new TypeError('"this" is null or not defined');
}
var O = Object(this);
var len = O.length >>> 0;
if (len === 0) {
return -1;
@darthwade
darthwade / settings.py
Last active August 29, 2015 14:04
S3BotoStorage subclass for media and static buckets.
from __future__ import unicode_literals
import os
from boto.s3.connection import SubdomainCallingFormat
# AWS S3
AWS_S3_ACCESS_KEY_ID = os.getenv('AWS_S3_ACCESS_KEY_ID')
AWS_S3_SECRET_ACCESS_KEY = os.getenv('AWS_S3_SECRET_ACCESS_KEY')
AWS_S3_BASE_URL = 's3.amazonaws.com'
# AWS_S3_FILE_BUFFER_SIZE = 5242880
>>> # Grab countries from https://github.com/umpirsky/country-list/blob/master/country/cldr
>>> LANG = 'uk'
>>> FIELD_SUFFIX = '_uk'
>>> DOWNLOAD_URL = 'https://raw.githubusercontent.com/umpirsky/country-list/master/country/cldr/{lang}/country.txt'
>>> from urllib2 import urlopen
>>> lines = urlopen(DOWNLOAD_URL.format(lang=LANG)).read().split('\n')
>>> from apps.gis.models import Country
>>> for l in lines:
>>> if not len(l): break
>>> l = l.decode('utf-8')