Skip to content

Instantly share code, notes, and snippets.

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

Alexandr Shurigin phpdude

🏠
Working from home
View GitHub Profile
@phpdude
phpdude / example.js
Last active June 9, 2018 20:14
PhantomJS: hellper for writing scripts waiting full page load (DOMContentLoaded event)
var system = require("system");
var url = system.args[1];
require('./phantom-full-load')(phantom, url, function (page, logs) {
logs.forEach(function (i) {
console.log('> ' + i);
});
result = page.evaluate(function () {
return $('body *').attr('class');
@phpdude
phpdude / docker-compose.yml
Created March 9, 2016 15:27
Docker Composer Django \w NGINX \w uWSG \w PostgreSQL In Production
version: '2'
services:
db:
restart: always
image: postgres
environment:
- POSTGRES_USER=project
- POSTGRES_PASSWORD=project
volumes:
@phpdude
phpdude / Git hook sync modification time to last commit time
Last active May 20, 2018 23:56
Git post-merge & post-checkout hook for sync changed files timestamps with last commit time (Linux, FreeBSD, Mac OS)
Git hook post-merge and post-checkout for sync modification time to last commit time.
You can download scripts manually and install them yourself, or you can install it with command
> curl -s https://gist.githubusercontent.com/phpdude/9464925/raw/install | sh
This command will download post-merge script, chmod it, and create post-checkout symlink to post-merge hook.
You can also start this script manually with environment variable $GIT_MERGE_LIMIT=100 to updated timestamp of last 100 commits for example.
@phpdude
phpdude / apiblueprint.cson
Created March 1, 2018 23:40
API Blueprint fix for syntax highlighting in Request and extra coloring for better reading documentation files (~/.atom/packages/language-api-blueprint/grammars/apiblueprint.cson)
fileTypes: [
"apib"
]
foldingStartMarker: '''
(?x)
(<(?i:head|body|table|thead|tbody|tfoot|tr|div|select|fieldset|style|script|ul|ol|form|dl)\\b.*?>
|<!--(?!.*-->)
|\\{\\s*($|\\?>\\s*$|//|/\\*(.*\\*/\\s*$|(?!.*?\\*/)))
)
'''
@phpdude
phpdude / asyncemail.py
Created March 9, 2014 14:54
Django Simple asynchronous email backend (Celery 3.1+)
from celery import shared_task
from celery.contrib.methods import task_method
from django.core.mail.backends.smtp import EmailBackend as BaseEmailBackend
class FakeLock(object):
__enter__ = lambda x: None
__exit__ = lambda a, b, c, d: None
@phpdude
phpdude / middleware.py
Last active October 11, 2017 13:50
Django LocaleByDomainMiddleware - Locale By Domain Middleware
from django.conf import settings
from django.utils import translation
class LocaleByDomainMiddleware():
def process_request(self, request):
host = request.META['HTTP_HOST'].lower()
locales = dict(settings.LOCALE_DOMAINS)
if not host in locales:
@phpdude
phpdude / download.py
Last active September 12, 2016 13:40
import os
import sys
import requests
import re
from json import loads
from HTMLParser import HTMLParser
import shutil
from lxml.html import fromstring
from time import sleep
@phpdude
phpdude / pre-commit
Created April 6, 2016 17:31 — forked from wolfhechel/pre-commit
Auto add Django migrations before commit
find . -type d -name migrations -not -exec git check-ignore -q {} \; -exec git add {} \;
@phpdude
phpdude / Result.example.log
Last active March 17, 2016 19:59
Find used python packages list needed to be installed (or used in requirements.txt)
GcsManager
Robot
WitInterface
WitResponse
XmppReporter
cjson
cloudsql
cloudsql.beans
cloudsql.dao
cloudsql.dao.dialogdao
@phpdude
phpdude / wkhtmltopdf.tablesplit.js
Created January 17, 2016 16:03 — forked from niflostancu/wkhtmltopdf.tablesplit.js
WkHtmlToPdf Table Splitting Hack
/**
* WkHtmlToPdf table splitting hack.
*
* Script to automatically split multiple-pages-spanning HTML tables for PDF
* generation using webkit.
*
* To use, you must adjust pdfPage object's contents to reflect your PDF's
* page format.
* The tables you want to be automatically splitted when the page ends must
* have a class name of "splitForPrint" (can be changed).