Skip to content

Instantly share code, notes, and snippets.

View JeromeParadis's full-sized avatar

Jerome Paradis JeromeParadis

View GitHub Profile
@JeromeParadis
JeromeParadis / redis_delete_keys_pattern.sh
Created September 25, 2011 06:22
Redis: How delete keys matching a pattern?
redis-cli KEYS "prefix:*" | xargs redis-cli DEL
@JeromeParadis
JeromeParadis / drop_tables.sh
Created September 26, 2011 16:05
Efficiently drop all tables from MySQL
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 / caching_tools.py
Created September 27, 2011 18:51
Django get or set Cache pattern
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 / strip_url_tracking.py
Created October 30, 2011 22:38
Strip Google Analytics tracking codes from URL query parameters
DISCARD = [
'utm_source',
'utm_medium',
'utm_campaign',
'utm_term',
'utm_content',
]
def strip_url_tracking(url):
"""
Removes Google Analytics codes from URLs
@JeromeParadis
JeromeParadis / merge_mine_theirs.sh
Created June 22, 2012 14:27
git merge: keep ours our theirs
git checkout --theirs filename_path
git checkout --ours filename_path
@JeromeParadis
JeromeParadis / mysqlslap.sh
Last active December 28, 2015 10:29
Stress test a MySQL database to create more read locks on a specific table
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 / string_logger.py
Created January 8, 2014 18:05
How to generate a logger that logs to a string.
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()
"""