Skip to content

Instantly share code, notes, and snippets.

@ddebernardy
ddebernardy / WP-SubdirInstall-Fixes.php
Last active October 21, 2016 13:34
SubdirInstall component for WordPress
<?php
namespace Mesoconcepts\WordPress\Plugin\BugFixes\Component;
use Mesoconcepts\WordPress\Bridge\Component\WordPressInterface;
use Mesoconcepts\WordPress\Bridge\DependencyInjection\EagerLoadedInterface;
use Mesoconcepts\WordPress\Bridge\DependencyInjection\EventSubscriberInterface;
/**
* Subdir install fixes -- part of MIT-licensed `mesoconcepts/mc-bug-fixes` plugin
*
@ddebernardy
ddebernardy / wp-define.php
Last active August 29, 2015 13:57
WP define()
<?php
namespace Mesoconcepts\WordPress\Config;
/**
* Warning-free version of PHP's built-in \define() function.
*
* @param string $key
* @param mixed $value
* @param boolean $case_insensitive
*/
denis=# \d test
Table "public.test"
Column | Type | Modifiers
--------+---------+-----------
id | integer | not null
Indexes:
"test_pkey" PRIMARY KEY, btree (id)
denis=# select * from test;
id
@ddebernardy
ddebernardy / pgsql-system-views.sql
Last active December 30, 2015 22:19
Wrappers around the PostgreSQL catalog, to get convenient information on all sorts of DB objects in a format that's more useful than the information schema.
--
-- Copyright (c) Denis de Bernardy, 2011-2013
-- MIT license
--
CREATE SCHEMA IF NOT EXISTS system;
CREATE OR REPLACE FUNCTION system.typeof("any")
RETURNS regtype
AS 'pg_typeof'
@ddebernardy
ddebernardy / ruby-mutable-hash-key.rb
Last active December 29, 2015 06:29
Breaking Ruby hashes with mutable keys
>> k = {}
=> {}
>> h = {k => :v}
=> {{}=>:v}
>> k[:broken] = :yes
=> :yes
>> h
=> {{:broken=>:yes}=>:v}
>> h[k]
=> nil
@ddebernardy
ddebernardy / pgsql-use-index-on-coalesce-arg.sql
Last active December 19, 2015 02:38
Postgresql 9.2 prepare query test
drop table if exists parent cascade;
drop table if exists child cascade;
deallocate all;
create table parent (id serial primary key, val int unique);
create table child (id serial primary key, val int references parent(val));
insert into parent (val)
select case when i % 11 <> 0 then i else null end
from generate_series(1,10000) i;