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
4> T = tag:new(id, "erlang", false). | |
{tag,id,"erlang",false} | |
5> T:save(). | |
{error,{error,error,<<"23505">>, | |
<<"duplicate key value violates unique constraint \"tags_name_key\"">>, | |
[{detail,<<"Key (name)=(erlang) already exists.">>}]}} |
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
-module(boss_db_sql). | |
-compile(export_all). | |
%% Much more elaborate version -- and with comments! | |
%% Drop in src/lib/ to be able to use it from anywhere in CB. | |
%% Return just the values from an executed SQL query. | |
sql(S) -> | |
{ok, ColNames, Values} = boss_db:execute(S), | |
Values. |
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
%% First try at making a small IRC bot. | |
%% Dedicated to ThordenM. | |
%% | |
%% Rune Juhl Jacobsen, 2012 | |
-module(irc). | |
-compile(export_all). | |
-define(NICK, "lolcat"). | |
-define(USERNAME, "lolcatzz"). |
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
%% filename clashes with erlang module btree! | |
-module(btree). | |
-export([find/2, min/1, max/1, insert/1, insert/2, print/1, print/2]). | |
-record(node, {val, left = nil, right = nil}). | |
%% find a specific value in a tree, or not_found | |
find(Value, Node) when Value == Node#node.val -> | |
{ok, Node}; |
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
-module(coinchange). | |
-export([coinchange/2]). | |
coinchange(_, {sorted, []}) -> | |
[]; | |
coinchange(A, {sorted, [C | CS]}) when A < C -> | |
coinchange(A, {sorted, CS}); | |
coinchange(A, {sorted, [C | CS]}) -> | |
[C | [coinchange(A-C, {sorted, [C | CS]}) ]]; | |
coinchange(A, C) -> |
NewerOlder