Skip to content

Instantly share code, notes, and snippets.

View dhruvg's full-sized avatar

Dhruv Garg dhruvg

View GitHub Profile

Keybase proof

I hereby claim:

  • I am dhruvg on github.
  • I am dhruvg (https://keybase.io/dhruvg) on keybase.
  • I have a public key whose fingerprint is E9D6 8B95 15B9 59C5 E2BE C729 A522 3BCE 0FA2 B432

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am dhruvg on github.
  • I am dhruvg (https://keybase.io/dhruvg) on keybase.
  • I have a public key ASCjz0NZ8yZmB8P2J9QYFqqH036RXKIasTCD0MXv7yAwIwo

To claim this, I am signing this object:

@dhruvg
dhruvg / session_tracker.py
Last active November 23, 2016 05:00
Keep track of model changes across different sessions in SQLAlchemy
from sqlalchemy import event, orm
from sqlalchemy.inspection import inspect
from sqlalchemy.orm import object_mapper
from sqlalchemy.orm.properties import ColumnProperty
from test_project.storage import Session
class SessionTracker(object):
def __init__(self, sessionmaker):
@dhruvg
dhruvg / connection_fix.rb
Created March 18, 2014 17:59
Reconnect to Mysql 2 when server goes away
# If your workers are inactive for a long period of time, they'll lose
# their MySQL connection.
#
# This hack ensures we re-connect whenever a connection is
# lost. Because, really. why not?
#
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar)
#
# Adapted from:
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/