Skip to content

Instantly share code, notes, and snippets.

Avatar

Jerome Paradis JeromeParadis

View GitHub Profile
@JeromeParadis
JeromeParadis / string_logger.py
Created Jan 8, 2014
How to generate a logger that logs to a string.
View string_logger.py
import logging
def get_string_logger(logger_name, level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", debug_db=False):
"""
Gets you what you need to log to a string. Returns a pair of StringIO, logger variables.
>>> output, logger = get_string_logger('my_app_logger', level=logging.DEBUG)
>>> call_stuff_to_debug_with_logger(logger=logger)
>>> print output.getvalue()
"""
@JeromeParadis
JeromeParadis / mysqlslap.sh
Last active Dec 28, 2015
Stress test a MySQL database to create more read locks on a specific table
View mysqlslap.sh
mysqlslap --delimiter=";" --create-schema=my_db --user=root --query="SELECT * FROM app_table" --concurrency=100 --iterations=20
# Ref: http://serverfault.com/questions/285547/how-can-artificially-create-a-slow-query-in-mysql
# Ref: http://dev.mysql.com/doc/refman/5.1/en/mysqlslap.html
@JeromeParadis
JeromeParadis / merge_mine_theirs.sh
Created Jun 22, 2012
git merge: keep ours our theirs
View merge_mine_theirs.sh
git checkout --theirs filename_path
git checkout --ours filename_path
@JeromeParadis
JeromeParadis / strip_url_tracking.py
Created Oct 30, 2011
Strip Google Analytics tracking codes from URL query parameters
View strip_url_tracking.py
DISCARD = [
'utm_source',
'utm_medium',
'utm_campaign',
'utm_term',
'utm_content',
]
def strip_url_tracking(url):
"""
Removes Google Analytics codes from URLs
@JeromeParadis
JeromeParadis / caching_tools.py
Created Sep 27, 2011
Django get or set Cache pattern
View caching_tools.py
from django.core.cache import cache
# Here, you can centralize sanitation of cache key.
# There was a python memcache bug were spaces in keys were generating exceptions, so we replace it
# You could add any other code to fix keys here
def sanitize_cache_key(cache_key):
key = cache_key
if key and len(key) >0:
key = key.replace(' ','%20')
return key
@JeromeParadis
JeromeParadis / drop_tables.sh
Created Sep 26, 2011
Efficiently drop all tables from MySQL
View drop_tables.sh
mysqldump -u user_name -p password --no-data --add-drop-table database_name | grep ^DROP | mysql -u user_name -p password database_name
@JeromeParadis
JeromeParadis / redis_delete_keys_pattern.sh
Created Sep 25, 2011
Redis: How delete keys matching a pattern?
View redis_delete_keys_pattern.sh
redis-cli KEYS "prefix:*" | xargs redis-cli DEL