These are chat archives for synrc/n2o

8th
Nov 2017
natewilly
@natewilly
Nov 08 2017 02:41
So I got it to work, and now I want to tell n2o to use sample.erl as the starting file for my app in n2o/samples/apps
i can use the default messaging app, that works fine
im confuse about how to tell n2o to use my own application now
You say to change settings here: \subsection*{Application}
In {\bf app} setting you should place the name of your OTP application
that will be treated by N2O and NITRO as a source for templates and
other static data with {\bf code:priv_dir}.
but I'm confused on what this means....where is this?
What is /bf?
natewilly
@natewilly
Nov 08 2017 05:33
so I just found this: -define(TEMPLATE, filename:join(lists:reverse(tl(lists:reverse(filename:split(code:priv_dir(?APP)))))) ++ "/test/index.html").
in test.hrl
great.
Namdak Tonpa
@5HT
Nov 08 2017 05:33
First of all you should choose which approach you go with
natewilly
@natewilly
Nov 08 2017 05:34
what do you mean?
Namdak Tonpa
@5HT
Nov 08 2017 05:34
Templates, or Erlang DSL, or pure Data on Wire
N2O supports all of them
natewilly
@natewilly
Nov 08 2017 05:34
Well, I like the idea of having everything be a websocket
Namdak Tonpa
@5HT
Nov 08 2017 05:34
Should I explain all three?
natewilly
@natewilly
Nov 08 2017 05:34
if you want, sure
i like html and websockets
Namdak Tonpa
@5HT
Nov 08 2017 05:34
All three options are totally compatible with WebSockets
natewilly
@natewilly
Nov 08 2017 05:35
and i want to stream video....not sure if that matters
eventually want to be able to stream video
live
would like to learn to do that
Namdak Tonpa
@5HT
Nov 08 2017 05:35
Let me explain in a modern way
natewilly
@natewilly
Nov 08 2017 05:35
okay
Namdak Tonpa
@5HT
Nov 08 2017 05:37
A. Nowadays de-facto approach in Web is to build JavaScript protocol and pass between client and server only JSON or BINARY data (N2O supports both). The best you can achieve is to create Pure JS app on client side and create only data protocol in Erlang/N2O. This will allow to plug designers, JavaScript Rx libraries, React or other bullshit :-)
BTW we are using this approach in production (for obvious reasons).
BUT
natewilly
@natewilly
Nov 08 2017 05:38
binary data seems ideal for speed reasons
Namdak Tonpa
@5HT
Nov 08 2017 05:41
B. If your resources are limited and you don't want to pay all the money to JavaScript-kiddies :-) E.g. lets say you are building Web Admin, then no need to hire CSS/JS developers. As N2O has it roots in Nitrogen, it supports Nitrogen way of building pages (like in Scsal Lift, OCaml OCsigen, Lisp) — i.e. you build the page in HTML DSL of your own language (in our case this is Erlang) and generate HTML from those pages. #button{} #div{} #br{}.... This is the most natural Erlang way and involves no HTML/CSS/JS direct manipulations. This is the approach of the original author of Nitrogen — Rusty Klophouse. In n2o we moved this library out of n2o to synrc/nitro. And later we added synrc/svg for SVG DOM elements. #g{} #rect{} #svg{}.... etc.
natewilly
@natewilly
Nov 08 2017 05:43
Would it slow things down if I used html instead?
I have no experience with DSL
Namdak Tonpa
@5HT
Nov 08 2017 05:44
No
natewilly
@natewilly
Nov 08 2017 05:44
I prefer to use html/css
Namdak Tonpa
@5HT
Nov 08 2017 05:44
DSL means to write HTML but in Elrlang.
A class ?
First one ?
natewilly
@natewilly
Nov 08 2017 05:44
i want to directly use html
and css
Namdak Tonpa
@5HT
Nov 08 2017 05:44
ok
then "pure Data on Wire"
natewilly
@natewilly
Nov 08 2017 05:45
okay
Namdak Tonpa
@5HT
Nov 08 2017 05:45
well we have an example
Here is example of very tiny N2O Protocol https://github.com/spawnproc/tic
This is a integrator of several API behind a UNIFIED API which is implemented as JSON protocol in N2O
natewilly
@natewilly
Nov 08 2017 05:46
ok
you just write such stuff and plug it to sys.config
$ cat sys.config
[ {n2o, [{protocols,[protocol]},
...
and that's it!
natewilly
@natewilly
Nov 08 2017 05:49
one moment. trying to figure out how your sample app uses this in the file
OHHH
{app,review}
Namdak Tonpa
@5HT
Nov 08 2017 05:50
All official N2O samples use B approach!
not A.
natewilly
@natewilly
Nov 08 2017 05:50
which is DSL
{app,review} < - is this the line that connects your example application to the rest of the framework?
Namdak Tonpa
@5HT
Nov 08 2017 05:51
Look: https://github.com/synrc/n2o/blob/master/src/endpoints/n2o_proto.erl#L9-L13
protocols() -> wf:config(n2o,protocols,[ n2o_heart,
                                         n2o_nitrogen,
                                         n2o_file,
                                         n2o_client,
                                         n2o_http ]).
natewilly
@natewilly
Nov 08 2017 05:51
by the way, I come from C++, so I'm still trying to get used to the erlang syntax. sorry
Namdak Tonpa
@5HT
Nov 08 2017 05:51
N2O is just a protocol router, we plug protocols to N2O and it just works
we have FTP PING NITROGEN protocols
other guys creating pure JSON or TEXT protocols
N2O can even work over MQTT over raw UDP/TCP!
without HTTP at all!
natewilly
@natewilly
Nov 08 2017 05:53
interesting
I was correct about {app,review} though, yes
?
Namdak Tonpa
@5HT
Nov 08 2017 05:55
N2O is not a usual web framework you may know, this is like WFC (.NET) or Camel/CXF (Java)
natewilly
@natewilly
Nov 08 2017 05:55
Yea this is not common
Namdak Tonpa
@5HT
Nov 08 2017 05:56
{app,review} points a module review.erl as a module which will be used for NITRO pages
N2O is a Network Software Foundation for Network Applications in Erlang
As I had 10 years experience in .NET and 5 years in Java I built N2O as a replacement of corporate bullshit
natewilly
@natewilly
Nov 08 2017 05:58
What do you mean corporate bullshit?
Namdak Tonpa
@5HT
Nov 08 2017 05:58
N2O is built for Enterprise, that is why this is not like Hipster Framework
natewilly
@natewilly
Nov 08 2017 05:58
haha. okay
i see
Namdak Tonpa
@5HT
Nov 08 2017 05:58
I mean sizes of Enterprise software
N2O core is 500 LOC
we have no repository more that 1000 LOC in synrc organization
you can remember all the modules literally!
natewilly
@natewilly
Nov 08 2017 05:59
Keep it lean, keep it clean.
Namdak Tonpa
@5HT
Nov 08 2017 05:59
all the bodies!
N2O is TRUE simplest web framework!
you may add Nano, Yocto, or other bullshit prefixes :-)
natewilly
@natewilly
Nov 08 2017 06:00
well i like the approach
So I was following a tutorial for n2o
and it said that
I should put my app in the app folder
and then edit the sys.config
to have n2o point at the folder
Namdak Tonpa
@5HT
Nov 08 2017 06:02
Yes, because turtorial explain B approach
natewilly
@natewilly
Nov 08 2017 06:02
and that's basically how I can start making a website
Namdak Tonpa
@5HT
Nov 08 2017 06:03
in A approach you don't need {app,module} :-)
you need to create raw N2O PROTOCOL
see tic example
natewilly
@natewilly
Nov 08 2017 06:03
tic?
Namdak Tonpa
@5HT
Nov 08 2017 06:04
it compatible with wscat
$ wscat -c ws://127.0.0.1:9000/gdax/BTC-USD
connected (press CTRL+C to quit)
< ['05:35:29.783', +5195, 1035.15, 0.24517252]
< ['05:35:29.785', +5349, 1094.27, 0.04]
< ['05:35:29.816', +5453, 1094.34, 0.1]
< ['05:35:29.857', +5564, 1094.37, 0.2479]
> book
< 10000000.0 -0.01
   9.99999 -317.078
       1.0 -5.010673
       0.5 -5.01
       0.3 -0.011
      0.25 -9.877214
       0.2 -0.011
natewilly
@natewilly
Nov 08 2017 06:04
oh tic got it
Namdak Tonpa
@5HT
Nov 08 2017 06:04
tic I just gave you: https://github.com/spawnproc/tic
natewilly
@natewilly
Nov 08 2017 06:04
yea
Namdak Tonpa
@5HT
Nov 08 2017 06:04
The protocols could be outdated on crypto venues, so be careful :-)
natewilly
@natewilly
Nov 08 2017 06:11
so i need to edit the .erl files in protocols folder
to route to my app?
Namdak Tonpa
@5HT
Nov 08 2017 06:11
yes
natewilly
@natewilly
Nov 08 2017 06:12
and as an example, after writing those files, if my app were the TIC app, I would then edit this: https://github.com/spawnproc/tic/blob/master/sys.config
and put my protocols in these spaces?
{n2o, [{protocols,[protocol]},
{query,protocol},
{session,protocol},
{route,protocol}]},
Namdak Tonpa
@5HT
Nov 08 2017 06:12
yes
natewilly
@natewilly
Nov 08 2017 06:13
and that's it?
Namdak Tonpa
@5HT
Nov 08 2017 06:13
yes
natewilly
@natewilly
Nov 08 2017 06:14
so i put my project app files in a folder in n2o/samples/apps
and do those above things
Namdak Tonpa
@5HT
Nov 08 2017 06:14
yes
natewilly
@natewilly
Nov 08 2017 06:14
alright
now we're getting somewhere
Namdak Tonpa
@5HT
Nov 08 2017 06:14
there are other ways but for newbies this is fine
natewilly
@natewilly
Nov 08 2017 06:15
lol
Namdak Tonpa
@5HT
Nov 08 2017 06:15
I'm trying to keep folder flat without apps/ folder
with /src in root like in libraries
Listing 2: OTP Application — for libraries
Listing 1: Solution — for multi-app solutions
natewilly
@natewilly
Nov 08 2017 06:17
okay
i think ill keep it one OTP app
for now
so you have a rebar.config
in your review app
{deps_dir, ["../../deps"]}.
{lib_dirs, ["../../apps"]}.
{deps, []}.
{erlydtl_opts, [
{doc_root, "priv/templates"},
{out_dir, "ebin"},
{compiler_options, [report, return, debug_info]},
{source_ext, ".html"},
{module_ext, "_view"}
]}.
you have html files in your priv/templates
and then you have beam files in /ebin/
natewilly
@natewilly
Nov 08 2017 06:22
those beam files have the functions that are responding to interactions with javascript in the html files, correct?
Namdak Tonpa
@5HT
Nov 08 2017 06:22
if you go with A way, you don't need this
this is fo C class applications
using DTL (Django Template Library)
natewilly
@natewilly
Nov 08 2017 06:24
okay
i still want to do templates
what i mean is
i want to be able to have, say, some html for what a certain thing on the website looks like
and be able to put it wherever i want in the middle of another html file
i can do this with method B, yes?
im wondering now if i should do C method
Namdak Tonpa
@5HT
Nov 08 2017 06:26
You can mix all the approaches
You need to spend some time reading Erlang code )
n2o/samples is a good start
But remember that N2O has no limitation
:-)
natewilly
@natewilly
Nov 08 2017 06:27
which approach do you recommend with websockets
ive never used DTL
i would have to learn it
Namdak Tonpa
@5HT
Nov 08 2017 06:27
A. tic. don't use DTL bullshit, or even Erlang DSL
be modern kid!
be compatible with other world!
but if you feel that you're old school — then you may do whatever you want
natewilly
@natewilly
Nov 08 2017 06:28
no i like html
i dont understand why you would work around html
natewilly
@natewilly
Nov 08 2017 06:36
okay. i will go learn what it means to write a protocol
yes.
thanks for help.
Namdak Tonpa
@5HT
Nov 08 2017 06:36
np