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 / gavnocode.php
Last active August 29, 2015 14:26
gavnocode.php
<?php
$query = $db->query("SELECT * FROM refer GROUP BY keyword ORDER BY date DESC LIMIT 0,10");
while($row = $db->get_row($query)){
preg_match_all('/([0-9]{4})\/([0-9]{2})\/([0-9]{2})\/(.+?).html/', $row['url'], $request_out);
$first = mb_substr($row['keyword'],0,1); // первая буква
$last = mb_substr($row['keyword'],1); // все кроме первой буквы
$first = mb_strtoupper($first);
$last = mb_strtolower($last);
$keyword = $first.$last;
@phpdude
phpdude / validate_email.py
Created November 9, 2015 22:28
Validate Email Address in Python (part of django framework)
import re
class ValidationError(ValueError):
def __init__(self, message, code=None):
super(ValidationError, self).__init__(message)
self.code = code
def __str__(self):
@phpdude
phpdude / delete-reposts.js
Last active November 18, 2015 18:32
Delete reposts from vk.com profile wall.
setInterval(function () {
var x = $('.post_copy .post_delete_button');
if(x)
{
x.click();
x.remove();
}
}, 500);
setInterval(function() {
[{"distance": "0.14 miles", "statezip": "New York, NY 10012", "name": "St. Anthonys School", "url": "http://www.greatschools.org/new-york/new-york-city/5320-St.-Anthonys-School/", "grade": "n/a", "address": "60 Mac Dougal Street", "type": "Private"}, {"distance": "0.17 miles", "statezip": "New York, NY 10013", "name": "Chelsea Career and Technical Education High School", "url": "http://www.greatschools.org/new-york/new-york-city/1948-Chelsea-Career-And-Technical-Education-High-School/", "grade": "9-12", "address": "131 Ave of the Americas", "type": "Public"}, {"distance": "0.17 miles", "statezip": "Manhattan, NY 10013", "name": "NYC Ischool", "url": "http://www.greatschools.org/new-york/manhattan/13270-NYC-Ischool/", "grade": "9-11", "address": "131 Ave of the Americas", "type": "Public"}, {"distance": "0.25 miles", "statezip": "New York, NY 10012", "name": "University Plaza Nursery School", "url": "http://pk.greatschools.org/new-york/new-york-city/preschools/University-Plaza-Nursery-School/11467/", "grade":
@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).
@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 / 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 / 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 / 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 / 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