This file contains 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
UPDATE public.mytable SET | |
jsonfieldname = jsonb_set( jsonfieldname, '{json_obj_key}', array_to_json( | |
ARRAY( | |
SELECT DISTINCT( UNNEST( ARRAY( | |
SELECT json_array_elements_text( COALESCE( jsonfieldname::json->'json_obj_key', '[]' ) ) | |
) || ARRAY['Element to add'] ) ) | |
) | |
)::jsonb ) | |
WHERE id = 23 | |
RETURNING *; |
This file contains 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
UPDATE public.mytable SET | |
jsonfieldname = jsonb_set( jsonfieldname, '{json_obj_key}', array_to_json( | |
ARRAY( | |
SELECT DISTINCT( UNNEST( ARRAY( | |
SELECT json_array_elements_text( COALESCE( jsonfieldname::json->'json_obj_key', '[]' ) ) | |
) || ARRAY['Element to add'] ) ) | |
) | |
)::jsonb ) | |
WHERE id = 23 | |
RETURNING *; |
This file contains 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
-module(join_binries). | |
-export([join/2]). | |
join(TitleList, Sep) -> | |
Fun = fun(<<>>, Acc) -> | |
Acc; | |
(Word, Acc) -> | |
<<Acc/binary, Sep, Word/binary>> | |
end, | |
lists:foldl(Fun, hd(TitleList), tl(TitleList)). |
This file contains 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
collections.map(function(coll) { | |
return { | |
type: "checkbox" | |
, callback: function() { console.log('this', this.checked) } | |
, checked: false | |
, text: coll.title | |
} | |
}) |
This file contains 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
# coding: utf8 | |
import pymongo | |
connection = pymongo.MongoClient('localhost', 27017) | |
db = connection.photos | |
albums = db.albums | |
images = db.images |
This file contains 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
{ok, Viewers} = eredis:q(State#state.redis_pool, ["HGET", "channel:clients", Key]), | |
ViewersInt = list_to_integer(binary_to_list(Viewers)), | |
case ViewersInt > 0 of | |
true -> | |
eredis:q(State#state.redis_pool, ["HSET", "channel:clients", Key, 0]), | |
?D([Key, ViewersInt]), | |
net_pinger:set_billing(binary_to_list(Key), ViewersInt); | |
_ -> ok | |
end |
This file contains 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
%%%------------------------------------------------------------------- | |
%%% @author greg <> | |
%%% @copyright (C) 2012, greg | |
%%% @doc | |
%%% | |
%%% @end | |
%%% Created : 29 Nov 2012 by greg <> | |
%%%------------------------------------------------------------------- | |
-module(ring). |
This file contains 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
%%%------------------------------------------------------------------- | |
%%% @author greg <> | |
%%% @copyright (C) 2012, greg | |
%%% @doc | |
%%% | |
%%% @end | |
%%% Created : 29 Nov 2012 by greg <> | |
%%%------------------------------------------------------------------- | |
-module(ring). |
This file contains 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
start(ProcNum, MsgNum, Message) -> | |
init(#state{num_procs=ProcNum, msg_num=MsgNum, msg=Message}). | |
%% first process | |
init(#state{proc_num=Proc, msg=Message}=State) when Proc == 1 -> | |
Pid = spawn(ring, loop, [Proc]), | |
Pid ! Message, | |
init(State#state{proc_num=Proc+1, first_pid=Pid}); | |
%% last process |
This file contains 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
start(ProcNum, MsgNum, Message) -> | |
start(ProcNum, MsgNum, Message, 0, 0, 1). | |
start(ProcNum, MsgNum, Message, PrevPid, FirstPid, Num) when ProcNum == Num -> | |
spawn(ring, loop, [Num, FirstPid, MsgNum, Message]); | |
start(ProcNum, MsgNum, Message, PrevPid, FirstPid, 1) -> | |
Pid = spawn(ring, loop, [1, PrevPid, MsgNum, Message]), | |
start(ProcNum, MsgNum, Message, Pid, Pid, 2), | |
Pid ! Message; | |
start(ProcNum, MsgNum, Message, PrevPid, FirstPid, Num) -> |
NewerOlder