Skip to content

Instantly share code, notes, and snippets.

@tomzx
tomzx / gist:5663921
Last active December 17, 2015 19:58
protected function getForeignKeySqlDefinition(ForeignKey $foreignKey)
{
$def = '';
if ($foreignKey->getConstraint()) {
$def .= ' CONSTRAINT ' . $this->quoteColumnName($foreignKey->getConstraint());
}
$columnNames = array();
foreach ($foreignKey->getColumns() as $column) {
$columnNames[] = $this->quoteColumnName($column);
@tomzx
tomzx / gist:8584838
Created January 23, 2014 19:09
List all FK relations
SELECT
ke.referenced_table_name parent,
ke.table_name child,
ke.constraint_name
FROM
information_schema.KEY_COLUMN_USAGE ke
WHERE
ke.referenced_table_name IS NOT NULL
ORDER BY
ke.referenced_table_name;
@tomzx
tomzx / gist:9354214
Created March 4, 2014 19:51
Give ALL permissions to NAME_dev on %_dev databases
GRANT CREATE ROUTINE, CREATE VIEW, ALTER, SHOW VIEW, CREATE, ALTER ROUTINE, EVENT, INSERT, SELECT, DELETE, TRIGGER, GRANT OPTION, REFERENCES, UPDATE, DROP, EXECUTE, LOCK TABLES, CREATE TEMPORARY TABLES, INDEX ON `%\_dev`.* TO 'NAME_dev'@'localhost';
FLUSH PRIVILEGES;
@tomzx
tomzx / gist:a98fd99736c656dd19b1
Created May 25, 2014 23:48
Model attribute accessors ala ruby (for Laravel)
<?php
trait ModelAttribute
{
protected $attr_reader = [];
protected $attr_writer = [];
protected $attr_accessor = [];
public function getAttribute($key)
{
@tomzx
tomzx / gist:7f79141f423927789475
Last active August 23, 2017 21:06 — forked from sartak/a.md
Anki database notes
-- cards are what you review. easy!
CREATE TABLE cards (
id integer primary key,
-- the epoch milliseconds of when the card was created
nid integer not null,
-- notes.id
did integer not null,
-- deck id (available in col table)
ord integer not null,
-- ordinal, seems like. for when a model has multiple templates, or thereabouts
@tomzx
tomzx / gist:aa2d9172a1daef15a0ac
Created January 7, 2015 02:41
./gradlew: Permission denied
/home/travis/build.sh: line 175: ./gradlew: Permission denied
Fix by setting the executable flag on your gradlew file.
Either
chmod +x gradlew (on unix systems)
OR
@tomzx
tomzx / semver-changes-v3.0.0-beta2
Last active August 29, 2015 14:14
deployphp/deployer semver changes from v2.0.4 to v3.0.0-beta.2
Suggested semantic versioning change: MAJOR
Class (MAJOR)
+-------+---------------------------------------------------------------------------+--------------------------------------------------------+-----------------------------------------+------+
| Level | Location | Target | Reason | Code |
+-------+---------------------------------------------------------------------------+--------------------------------------------------------+-----------------------------------------+------+
| MAJOR | E:\Tom\Documents\GIT\deployer\src\Console\RunTaskCommand.php#24 | Deployer\Console\RunTaskCommand | Class was removed. | V005 |
| MAJOR | E:\Tom\Documents\GIT\deployer\src\Environment.php#13 | Deployer\Environment | Class was removed. | V005 |
| MAJ
@tomzx
tomzx / gist:abc1dc4b5860bc711e62
Created August 4, 2015 19:09
PHP Convert MySQL timezone format to PHP timezone
function convertMySQLTimezone($timezone)
{
$result = preg_match('/(?P<sign>\+|-)(?P<hours>\d{1,2}):(?P<minutes>\d{1,2})/', $timezone, $match);
if ( ! $result) {
return timezone_name_from_abbr('UTC');
}
$sign = $match['sign'] === '-' ? -1 : 1;
$hours = $match['hours'];
$minutes = $match['minutes'];
@tomzx
tomzx / gh,js
Last active September 18, 2015 00:42
gh profiling using node --prof --log-timer-events and https://v8.googlecode.com/svn/branches/bleeding_edge/tools/profviz/profviz.html
Statistical profiling result from null, (1219 ticks, 0 unaccounted, 0 excluded).
[Shared libraries]:
ticks total nonlib name
834 68.4% /lib/x86_64-linux-gnu/libc-2.19.so
268 22.0% /usr/local/bin/node
96 7.9% [vdso]
18 1.5% /lib/x86_64-linux-gnu/libpthread-2.19.so
1 0.1% /lib/x86_64-linux-gnu/ld-2.19.so
@tomzx
tomzx / melody-bootstrapper.php
Last active January 21, 2016 01:45
Melody bootstrapper
<?php
<<<CONFIG
packages:
- "your/dependencies: 1.0"
CONFIG;
if ( ! file_exists('composer.phar')) {
file_put_contents('composer.phar', fopen('https://getcomposer.org/composer.phar', 'r'));
}