This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from MySQLdb import connect | |
conn = connect(user="[USER]", passwd= "[PASSWORD]") | |
cur = conn.cursor() | |
cur.execute("show databases;") | |
dbs_to_update = filter( | |
lambda db: db not in ('information_schema', 'mysql', 'performance_schema'), | |
[dbname[0] for dbname in cur.fetchall()]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
from os import mkdir | |
from os import walk | |
from os import popen | |
from os.path import join | |
from os.path import exists | |
from os.path import getsize | |
from os.path import basename |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
class DbNotFound(Exception): | |
pass | |
def copy(src_conn, src_dbname, dst_conn, dst_dbname=None, drop_table=True, | |
drop_db=True, silent=False, tables_to_copy=None): | |
""" (<lurker connection>, str, <lurker connection>, dst_dbname=str, drop_table=bool | |
drop_db=bool, silent=bool, tables_to_copy=list) -> bool |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def list_to_dict(l): | |
""" | |
This method converts tuple groups (that has no constant length) into | |
dict object. | |
>>> l = ((1, 'foo', 'bar'), (2, 'ta', 'ran', 'ti', 'no')) | |
>>> list_to_dict(l) | |
..: {'1': (foo, bar), 2: ('ta', 'ran', 'ti', 'no')} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var s = document.createElement('style');s.innerHTML = 'body {transform:rotate(90deg);-webkit-transform:rotate(90deg);}';document.getElementsByTagName('head')[0].appendChild(s); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf import settings | |
from django.http.request import validate_host | |
from django.middleware.csrf import _sanitize_token, constant_time_compare | |
from tastypie.authorization import ReadOnlyAuthorization | |
from tastypie.authentication import Authentication | |
from urlparse import urlparse | |
class InternalResourceAuthentication(Authentication): | |
def is_authenticated(self, request, **kwargs): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db.models import (get_models, ManyToManyField, ForeignKey, Count) | |
from django.contrib.contenttypes.generic import GenericRelation | |
from django.core import serializers | |
from django.contrib.auth.models import User | |
from sets import Set | |
def foreign_keys_to(model_class): | |
models = {} | |
for model in get_models(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alpha = 'ABC\xc3\x87DEFG\xc4\x9eHI\xc4\xb0JKLMNO\xc3\x96PRS\xc5\x9eTU' \ | |
'\xc3\x9cVYZabc\xc3\xa7defg\xc4\x9fh\xc4\xb1ijklmno\xc3' \ | |
'\xb6prs\xc5\x9ftu\xc3\xbcvyz'.decode('utf-8') | |
def invalid_chars(text, charset=alpha): | |
return set(filter(lambda c: c not in charset, list(text))) | |
invalid_chars(u'üğüğüp0*2') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def issubset(text, list_of_text): | |
""" | |
>>> msgs = ["abc", "def", "efg"] | |
>>> issubset("ab", msgs) # is subset of first item in msgs | |
True | |
>>> issubset("az", msgs) | |
False | |
>>> issubset("ef", msgs) | |
True | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
__author__ = "Mirat Can Bayrak" | |
__email__ = "[email protected]" | |
__copyright__ = "Copyright 2015, Planet Earth" | |
ENTRIES_PER_PAGE = 100 | |
import re | |
import logging |