Skip to content

Instantly share code, notes, and snippets.

@chebee7i
chebee7i / statements.rst
Last active November 28, 2018 00:33
MySQL Locks

Metadata Locks

If an InnoDB table is being accessed at all via SELECT or DML (INSERT, UPDATE, DELETE), you should rightly expect a metadata lock.

According to the MySQL Documentation on MetaData Locking (http://dev.mysql.com/doc/refman/5.6/en/metadata-locking.html):

To ensure transaction serializability, the server must not permit one session to perform a data definition language (DDL) statement on a table that is used in an uncompleted transaction in another session. The server achieves this by acquiring metadata locks on tables used within a transaction and deferring release of those locks until the transaction ends. A metadata lock on a table prevents changes to the table's structure. This locking approach has the implication that a table that is being used by a transaction within one session cannot be used in DDL statements by other sessions until the transaction ends.

SELECTs will obtain a shared metadata lock, while DML and DDL will obtain an exclusive metadata lock. So an uncommitted

#!/usr/bin/env python
r"""
Module to generate a stand-alone PDF of a tikz picture.
Any lines in the TikZ fragment that begin with "%tikzpic " are preprocessor
directives to this file. Presently, only two preprocessor commands are
supported. They are detailed through the examples below.
1) To input code into the stand-alone LaTeX before compilation:
@chebee7i
chebee7i / multinomialci.py
Created June 8, 2015 16:27
Multinomial Confidence Intervals
from __future__ import division
import numpy as np
def multinomial_ci(counts, alpha):
"""
Calculate a simultaneous (1-alpha) * 100 percent confidence interval.
Parameters
----------
@chebee7i
chebee7i / findsubgraph.py
Created March 2, 2015 21:14
Using GraphMatcher to find a subgraph.
"""
Example demonstrating how to modify the GraphMatcher class so that
subgraph_is_isomorphic() will determine whether G2 is a subgraph (with
an identity isomorphism).
"""
import networkx as nx
G = nx.karate_club_graph()
@chebee7i
chebee7i / dt.py
Created February 23, 2015 08:31
Naive and Aware Datetime Deltas
from __future__ import print_function
import datetime
import pytz
paris = pytz.timezone('Europe/Paris')
utc = pytz.utc
before_naive = datetime.datetime(2013, 3, 31, 1, 59)
before_paris = paris.localize(before_naive)
@chebee7i
chebee7i / tableau.py
Last active May 11, 2022 12:07
Tableau Colors
"""
Categorical color palettes from Tableau.
For example: http://kb.tableausoftware.com/articles/knowledgebase/creating-custom-color-palettes
"""
palettes = [
# Long name, short name
('Tableau 10', 'T 10'),
('Tableau 10 Light', 'T 10 L'),
@chebee7i
chebee7i / _cydefordereddict.pyx
Last active August 29, 2015 14:09
DefaultOrderedDict
from collections import Callable
from cyordereddict import OrderedDict
class DefaultOrderedDict(OrderedDict):
# Source: http://stackoverflow.com/a/6190500/562769
def __init__(self, default_factory=None, *a, **kw):
if (default_factory is not None and
not isinstance(default_factory, Callable)):
raise TypeError('first argument must be callable')
OrderedDict.__init__(self, *a, **kw)
/*
I've wrapped Makoto Matsumoto and Takuji Nishimura's code in a namespace
so it's better encapsulated. Now you can have multiple random number generators
and they won't stomp all over eachother's state.
If you want to use this as a substitute for Math.random(), use the random()
method like so:
var m = new MersenneTwister();
# original XML at http://www.w3.org/Math/characters/unicode.xml
# XSL for conversion: https://gist.github.com/798546
unicode_to_latex = {
u"\u0020": "\\space ",
u"\u0023": "\\#",
u"\u0024": "\\textdollar ",
u"\u0025": "\\%",
u"\u0026": "\\&",
@chebee7i
chebee7i / bayesian_networkx.py
Last active September 10, 2018 09:25
Some functions related to Bayesian networks.
"""
Some functions related to Bayesian networks (DAGs).
Most of this was pulled from:
http://www.mi.parisdescartes.fr/~nuel/bntworkshop2010/lecture3.pdf
"""
import networkx as nx