This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH RECURSIVE genres_materialized_path AS ( | |
SELECT id, name, ARRAY[]::INTEGER[] AS path | |
FROM genres WHERE parent_id IS NULL | |
UNION ALL | |
SELECT genres.id, genres.name, genres_materialized_path.path || genres.parent_id | |
FROM genres, genres_materialized_path | |
WHERE genres.parent_id = genres_materialized_path.id | |
) SELECT * FROM genres_materialized_path WHERE 15 = genres_materialized_path.path[array_upper(genres_materialized_path.path,1)]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
id | name | path | |
----+--------------------+--------- | |
16 | Hard Boiled | {14,15} | |
17 | Police Procedurals | {14,15} | |
(2 rows) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION get_children(genre_id integer) | |
RETURNS json AS $$ | |
DECLARE | |
result json; | |
BEGIN | |
SELECT array_to_json(array_agg(row_to_json(t))) INTO result -- inject output into result variable | |
FROM ( -- same CTE as above | |
WITH RECURSIVE genres_materialized_path AS ( | |
SELECT id, name, ARRAY[]::INTEGER[] AS path | |
FROM genres WHERE parent_id IS NULL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"id": 1, | |
"name": "Arts & Photography", | |
"children": [ | |
{ | |
"id": 2, | |
"name": "Architecture", | |
"children": [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION test_func(data json) RETURNS json AS $$ | |
return JSON.stringify(data); | |
$$ LANGUAGE PLV8; | |
SELECT test_func('{"a": {"b":"foo"}}'::json); | |
test_func | |
------------------- | |
{"a":{"b":"foo"}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION get_tree(data json) RETURNS json AS $$ | |
var root = []; | |
for(var i in data) { | |
build_tree(data[i]['id'], data[i]['name'], data[i]['children']); | |
} | |
function build_tree(id, name, children) { | |
var exists = getObject(root, id); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH data AS( | |
select array_to_json(array_agg(row_to_json(t))) as data | |
from ( | |
SELECT id, name, COALESCE(get_children(id), '[]') as children from genres | |
) t | |
) SELECT get_tree(data) from data; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
core: 7.x | |
api: '2' | |
projects: | |
drupal: | |
version: ~ | |
cdn: | |
type: module | |
subdir: contrib | |
version: ~ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM progrium/cedarish:cedar14 | |
RUN curl https://github.com/gliderlabs/herokuish/releases/download/v0.3.1/herokuish_0.3.1_linux_x86_64.tgz \ | |
--silent -L | tar -xzC /bin | |
# install herokuish supported buildpacks and entrypoints | |
RUN /bin/herokuish buildpack install \ | |
&& ln -s /bin/herokuish /build \ | |
&& ln -s /bin/herokuish /start \ | |
&& ln -s /bin/herokuish /exec |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python2 | |
from collections import namedtuple | |
from ansible.parsing.dataloader import DataLoader | |
from ansible.vars import VariableManager | |
from ansible.inventory import Inventory | |
from ansible.playbook.play import Play | |
from ansible.executor.task_queue_manager import TaskQueueManager | |
Options = namedtuple('Options', ['connection', 'module_path', 'forks', 'become', 'become_method', 'become_user', 'check', 'remote_user', 'private_key_file', 'ssh_common_args', 'sftp_extra_args', 'scp_extra_args', 'ssh_extra_args', 'verbosity']) |