Building an IRC Server for Vim

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
see also irc is uh protocols basically tcp with raw strings yeah yeah i think i know it's really simple this handsome young man clearly blinded by dreams and naivety is going to be building an irc server in c just so he can chat in neovim so we built a server for neovim to be able to communicate to other neovim clients via irc i at that point thought this server would be simple so we built it in c with non-blocking sockets and of course eventually zero allocation messaging which led to a fun game that we played called will it sag fault i may have lost some i can feel the rage the rage is happening and i may have won some suck it suck it suck it so let's go over how you do a server and see so this is how you create a socket server and see i followed this diagram okay whoa whoa whoa whoa whoa hey hey hey hey i'm not i'm not doing this okay hey i'm not gonna be get that c server out of here prime get out of here hey let's go over some memory okay let's do something actually interesting in here let me tell you about how we kept the allocation at a zero okay so before we talk about memory remember that irc's are just strings separated by a registered nurse they come usually in the shape of this who they're from the command where they're going and of course the parameters for that command so that means a standard message that you're just trying to talk to a group of people would look like hey it's from pic it's a private message it's to chat and of course it's let's get parameter to play will it sag fault since i'm building a server i need this message to last for a long time that means i need to call malik and actually create some sort of memory buffer which i can actually read from the socket into and when i'm done with that message meaning i've sent it out to all the other sockets i can then free the message but of course you know when you're building something live on twitch you can't just do that no you got to create a complicated linked list and buff your own pool it up so that way once you've allocated like five ten messages even if people are chatting like five ten times a second it's just gonna hum along not even allocating nothing just oh it's beautiful so we did create this live on twitch so i actually even think through my problem in re-reviewing the code this is stupid you know what i could have done is i could have made this into a singly linked list how a singly linked list works is that it just simply points to the next node or the previous node depending on your perspective so as you can see here i have three nodes if i were to pop off one node for some memory i would remove this one set my head right here and return this one out to the user if i were to do it again remove it set it return it if i simply wanted to add back to the linked list i would take wherever my head's pointing at i would then set it to my node that's coming back in and then this would become head it's that easy how could it ever say fault the rage is happening maybe i did say fault on this part all right so let's both go over the code and make the necessary changes to make this from a doubly linked list to a singly linked list so first i can just remove next so here you go this is just like the previous diagram i showed you is that i have where i'm pointing from the previous and then i have a couple extra like my own data fields right here and then really i only have two functions i need to expose get memory release memory so let's go over the code i will also be fixing my doubly link list into a singly linked list all right so this is create memory right here let's get rid of that next what i do is i just simply malloc a new memory node which contains all the buffer a pointer and of course a pointer to the previous memory node next i will set all these fields if you don't set the fields you don't know what you're gonna get people and then of course i just return it every you know that's that's the simple stuff okay so let's go down here and look at get memory so first you'll see if i have no memories i just create a new one and return it i don't even keep track of it at all else all i gotta do is grab the last memory now this is where it gets really nice using a singly linked list is i can just take this and dab it just dab the hell right out of it and then just go like this memories equals memphis right and that's it that's all i gotta do and now i'm ready to rock cause eventually prev will be null and i will create a new memory let's talk about release memory so release memory is actually also pretty straightforward now remember by using a singly linked list this dramatically makes things simpler so i'm going to erase those two things i'm going to go six down hit here i just want to use dap again i never get to use it it's so much fun to use but you know what in reality i should have used cap no cap honestly i should have used that way better all right so let's simply go memories uh memories equals mem and then above that simply go like this mem uh periv equals memories so this is release all we do is that it's really that simple all right so you're probably asking me why would i do all this well really what this will do is allows me to keep reusing that memory over and over again i don't have to recall the os every single time i need a new piece of memory is this over engineering absolutely is it over engineering for only 26 users absolutely was it built live and i'm doing it simply to impress my wife and reaffirm her that i am a cool guy did i think i was going to say fault not at all all right well whoa whoa enough of this server stuff okay it's time to get to the ui in neovim all right so let's talk about all the vim apis hey whoa whoa whoa whoa whoa whoa whoa whoa whoa stop with all that stop stop stop stop shh hey sorry i literally here let me do a quick recap for the ui we called some window apis we called some vim loop tcp connection apis we built a little bit of irc string processing but most importantly we robbed both tj and beastco of their channel points on twitch and it felt wonderful now that i just gave the greatest explanation ever to be held about neo-vim ui crafting let's get this service launched don't forget about docker oh yeah docker you know you gotta do like a from with and run run copy run run user worked or run run expose command all right so let's go get this launched on lenode all right so let's go to lenove.com prime hundred dollars free credit using the goat primogen come on baby you know that's too good it's too good hashtag [Music] so once you've logged into lenode you should see the following screen for me to set up the vim irc server i had the first simply create a node selected ubuntu set my region picked a node renamed selected a tag entered ultra secure password set my ssh keys created lenode now i have to set up my domain created a new one irc the primogen.tv my email use the lenode select lenode create a domain within about three minutes this domain was ready and i was able to test this in production all i had to do was clone down the c server execute the docker script and i would be ready just prove to the world that i do not sag fault so i simply launched the console entered in my super awesome name and my super secure password i cloned down my repo install docker build the docker image then simply just run the vim irc server i could have used lenovo's stack scripts to automate all of this but you know i just had to prove to the world and mostly to pick that i will not say fault my neo-vim irc server yes that's right that is how we did it we did the whole server and ui just like that i know you're impressed i mean i'd be impressed too i mean the best part is i didn't even say fault you know what i had running on the line i did not get to test it once in production and if i messed up i had to do a full stream in e-max now that my friend is commitment oh gosh you're still here hey hey whoa whoa hey if you like this style hey let me know put a little comment down below hey if i could have done things better let me know you know there's not a lot of people here at the startup so you know it's it's nice having a friendly face around you know that oh yeah you
Info
Channel: ThePrimeagen
Views: 12,480
Rating: undefined out of 5
Keywords: software, vim, programming, javascript, typescript, software engineering, web developing, web developer, software developer, developer, cpp, programmer humor, humor, reactjs, js, ecmascript, tc39, Netflix, Engineering, Engineer, Facebook, Amazon, Interviews, Software Interviews, vimrc, neovim, spacevim, vim c++, vim editor, text editor, vscode, vscode vim, vim plugins, autocomplete, vim autocomplete, nodejs, twitch, developer productivity, spacemacs, algorithms, datastructures, Data Structures
Id: Cct_vXCJOFw
Channel Id: undefined
Length: 8min 28sec (508 seconds)
Published: Wed Mar 31 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.