Skip to content

Instantly share code, notes, and snippets.

ibnIrshad /
Last active February 24, 2018 17:45 — forked from miratcan/
Small python script that converts character sets to utf8 in all databases and tables. My solution for "Illegal mix of collations" errors. (
from MySQLdb import connect
conn = connect(user="[user]", passwd= "[password]", host="[host]")
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()])
ibnIrshad /
Created October 25, 2016 01:37
Dynamic Programming Solution to finding if one string is a 'shuffle' of two others
'''Let x, y, and z, be strings over some alphabet Σ, where |z| = |x| + |y| (here |w|
denotes the length of a string w). We say that z is a shuffle of x and y if there are (possibly empty)
strings x1, x2, . . . , xk and y1, y2, . . . , yk so that x = x1x2 . . . xk, y = y1y2 . . . yk, and z = x1y1x2y2 . . . xkyk.
Intuitively, z can be constructed as the concatenation of pieces of x and y, in the order in which these
pieces appear in x and y, respectively. For example, 'alabama' is a shuffle of 'aba' and 'lama', but 'amalaba' is not.
We want an algorithm that, given as input three strings x, y, and z such that |z| = |x| + |y|, returns
true if z is a shuffle of x and y, and returns false otherwise.
Answer: Dynamic Programming