Skip to main content
View on YouTube to comment and like!

Syntax Video

Syntax Bytes with CJ - Clash of Code | Working on Tauri / Rust / Svelte Desktop App

Chapter 1 0:00

Intro

hello everyone welcome into syntax bites episode three I'm a pro streamer I definitely forgot to unmute my microphone uh today we are going to be playing Clash of code and working on Atari app uh so the app we're working on is called the syntax production assistant it uh is used to help publish the podcast episodes It's a desktop app it's built with tar spel kit that's going to be a good time but before that we're going to warm up with some Clash of code so Clash of code is the competitive coding game where we all get dropped into the same room and we have to compete to solve the coding problem and I'm going to go ahead and disable my break timer real quick and there's different kinds so there's fastest mode which is whoever can solve at the fastest get the highest placing um there's also shortest mode which is like code Golf and then there's rever reverse mode where you are given the inputs and the outputs and you have to figure out what code to write based

Chapter 2 0:28

What is Clash of Code?

on that so uh if you are not signed up head over here you can sign in with GitHub it's pretty easy um yeah thank you again to SpaceTime DV for that raid sorry everybody I forgot to unmute but we're here now good to see you all welcome in that random dude and ventrix and Mark and soil and raccoon uh and Shashi and Jeffrey and a roomy and denal and viven and Danel and who's watching on Twitch we've got zero Turner and Andrew Lane good to see you and the hallu and Cesar uh and elom welcome in so uh let's let's jump into it let's let's try to write some code and felon good to see you as well um now I think what we'll do is just we'll start off with fastest mode and uh I'm going to let you use any programming language so I'm going to use JavaScript because that's my preferred programming language but if you're watching out there and you like other programming languages you can choose those two now it's a little unfair because if you use something like python

Chapter 3 1:12

Saying Hello

or rub a lot of times they have builtins and you can actually solve it a lot faster but we're going to allow it um yeah I I don't think I heard so uh Andres is is mentioning uh Scott has a a story about a beanie um well the thing is this is this is a brimless hat right this is not a beanie but I I I don't know I I like I wear beanies in the winter time and then when the summer comes around um I can't uh wear beanies anymore so I found a brimless hat I don't know I I sometimes I just don't want to fix my hair you know I sometimes I just want to put a hat on um I I I will will say yeah it's definitely I don't know what you would call it like is it hipster to wear a beanie I feel like everybody's wearing beanies these days all right let's let's write some code um we're going to do fastest mode so if you want to join you can click this link in the chat um we will wait

Chapter 4 2:10

What hat am I wearing?

for uh at least as many people to join as they as want as they want to and then uh and then we'll get into it um and what can I do in the meantime let's actually do a code Wars speed run while we're waiting for everybody to get into the lobby so code Wars is another place that you can practice programming we are going to do some seven qes so these are fairly easy um but we'll see how many we can do before the timer runs out in 4 minutes here we go well actually I'm going to I'm going to show ones that I have not trained on so these will be s q problems that I have never seen before and I already don't like the name of this one um minimize the sum of the array given an array of integers find the minimum sum which is obtained from summing each two integers product this is not a 7q problem so it

Chapter 5 3:09

CodeWars Side Quest (Failed)

basically wants us to add every number with every other number and get the minimum we can do this it's going to I can do it like in in squared time I don't think it's going to care about um uh efficiency that much okay so let's say uh the Min sum is going to be array at zero and array at one just to initialize it um does it pass us arrays that are empty we'll do this so like if there's nothing in the array we'll set that off at zero so we have our initial Min and now I need to iterate over the array um I'm just going to use a for each and then this is going to give us a and then we're going to iterate over the array again internally again this is an ins squared solution it's not good but this will work there's probably a way to do it that's not N squared meaning a loop inside of a loop um and then we have the a index and the B index because we do

not want to sum the same number together so uh if the a index does not equal the B index meaning uh this number is not the same then we will add them together and we'll say uh Min is equal to math. Min of uh a plus b or the current Min so we're constantly overriding the Min with the minimum sum and then we will return the in again this is not performant I really hope they don't make me uh Do It um in uh a more performant way okay should return the minimum expected five to equal 22 um what I do wrong let's go ahead and log out the array and see what what's passing in for this test 5423 okay uh if the indices don't equal each other we're going to add them together

and overwrite the Min uh what does the Min start off as oh I think do I need to wrap this in parenthesis there's probably some weird stuff going on

here let's log every time let's log a b and the current

min oh wait minimize the sum of wait wait wait it's no we're not looking for the minimum sum that's this is not a seven cu I'm telling you I'm already struggling um this is not a 7 Q okay how how would we minimize the sum

then given an array of integers find the minimum sum which is obained from sum each two integers product um minum Su obtained from summing each two integers product Oh

we have to sum we have to first multiply every number times itself then we need to find the minimum of adding all two I'm not gonna I I am protesting this problem okay let's see if I can get a different one done in 30 seconds um any of the no no no any of those are not seven Q's I'm telling you okay this says uh we have a GPS record of every s seconds here we go here are the sections can you calculate the average hourly speed on every section uh maybe no I can't I I'm I'm not on today let's let's do this let's do this Clash of code so we got a few people in here with us we've got philon Lance uh Mark Pablo leore and Maris here we go here goes The Clash um and yeah I think it's it's okay if you if if if even if you're a beginner uh programmer it's okay it's okay we're going to take it slow

Chapter 6 7:40

Clash 1 - Calculate Kinetic Energy

and I will try to explain the problem too so we have 15 minutes to solve the problem you can see the description over on the left hand side it has our inputs our outputs and then some examples and then on the right hand side is where you write your code now what's different about coding game is you're not writing a function to return something whatever you console log will be considered your answer and then you have these test cases down here so um if you click this button you can see all of the input outputs for each of these tests so these are the inputs the outputs inputs the outputs and um essentially it usually has some setup code which reads the input for you so um here we're grabbing the height which is the first line of input and then the mass which is the second line of input we haven't even read the problem description yet but it looks like for all test cases the input always has two numbers one on each line you don't have to write any code for that they've already written that for you and then uh

we have to do the work down here and then whenever you're ready you can click test and you'll see that whatever you console log is considered your output and it needs to match the expected output and then once you get all the Test passing then you can submit okay here's the problem oh yeah and uh here is where you can choose your programming language but I'm going to use JavaScript the problem says uh Ski Jumping demands the athlete to control posture and movement during a jump athletes try to maximize acceleration by minimizing both the friction between skis and snow and the aerodynamic draft to obtain a maximum run this just sounds like a very needy client I your job is to calculate the total energy of the skier okay given the height of the jump and the mass of the skier and the gravity constant is 9.8 okay so they give us it involves math we're going to have to do some math today so we've got these equations mass time height time gravity is the potential energy and the kinetic energy is 12 * mass time velocity squ since the skier starts from rest all potential energy at the top converts to

contic energy at the bottom we'll figure out what this asking this is asking more calculate the total energy of the skier given the height and the mass okay so if we have the height and we have the mass and we know what gravity is we can get the potential energy so let's just do that first because I know that we have that um so we can say the potential energy we can call it the the PE is equal to the mass times the height and then we know that gravity is uh 9.8 um so let's create a variable called gravity set it to

9.8 all right this gives us the potential energy the kinetic energy is 1 12 * mass time velocity

squared so is total energy just kinetic plus potential maybe it is we'll maybe we'll have to do some Googling and look up physics okay so the kinetic energy is 12 let's do 0.5 time the masstimes uh velocity

squared how do we find their velocity

um I guess I'll just Google it so given or I'll Duck Duck Go it given mass and height how to calulate Velocity how to find the velocity here we go sciencing.com um multiply the length of time the object has been falling by 9.8 m/ second for example if an object has been free fall for 10 seconds then it would be 10 * 9 9.8 subtract your result from the object's initial upward velocity what can anybody in the chat help me is anybody doing has anybody figured out the other formulas um I guess I guess lamir and and AV roomy have already figured it out um our output is the kinetic energy rounded to one dust okay so the total

energy is kinetic energy we need to use the potential energy to calculate the velocity that's what I'm guessing um use potential energy to calculate velocity how to calculate speed given potential energy and mass that's what I

want I don't need to calculate the kinetic energy that's I need to that's what I need to Output the kinetic

energy the potential energy equals the kinetic energy so literally all we have to do is calculate the potential energy is that real because this is ridiculous if that's the case that's that's actually the case we just need to round it huh all right how does math.round work in uh in JavaScript

can you give it number of decimal places no that just rounds to the nearest

integer um and this wants us to do what rounded to one decimal place how do we do that JavaScript round to one decimal place do I have to do two fixed and then that converts it to a string and then convert it back to a number

yeah I mean we could use two fixed can you tell that I don't like maths I mean I have a I have a minor in math okay um here we go here's our answer um it didn't work it want okay never mind we can do two fixed because it wants because it's just a console log we'll use two fixed so you can say number two fixed and say we want one decimal place that should actually do it because it's just a console log anyways yeah that took me way too long but there are lessons to be learned here there are lessons to be learned here yeah and congrats to a super secret name who says I did the thing yeah that's awesome that's a awesome you did the thing and Mark says I did a hacky thing where it would only work 50% of the time

um yeah so yeah it didn't have to be a number okay uh but here are our learnings for that specific one first of all understanding the problem is like 80% of the battle I mean I guess sometime I guess maybe you might say it's half the battle but it's like really understanding what they're even asking for is huge right and in that case they literally gave us the formula and that's literally all they wanted the wording was just a little convoluted and also um in this case I didn't I wasn't as familiar with the problem domain right so this is this has to do with physics I haven't done physics in many many years um and in this case the potential energy is literally all we needed to calculate this was a very easy one but it actually took me seven minutes to solve but that's okay um we'll we'll wait for other people to keep clashing and then if you have solved it yourself click this uh click the share code button so I can actually um Show Your solution with the world and now I want to redeem myself I

Chapter 7 15:09

Clash 1 - Retro

Chapter 8 16:01

CodeWars - Pyramid Array

want to do at least one code Wars before this time is up before the this clashes up hardcoded the decimal place is everything 0 zero um honestly that those seven qes really got to me I'm actually just going to try to do a six Q which is supposed to be harder um most completed and things I haven't trained on

pyramid array write a function when given a number greater than zero returns an array of ascending length subarrays I could I could do that in my sleep I think I don't know okay so we we need um we need the the result array we just actually just have a single array so we want to return for for every um number we want to return a new array so I actually want a map I want I'm going to do a map but I need an initial array that is of the length of the N of the pyramid so I'm going to use array.

from pass in the length as in and so this is going to create an array of length n so if n was three we would get an array of length three and then this also accepts a map function which gives us uh the the value which in this case is going to be undefined and the index so the index is going to be 012 we want to add one to it and create an array that um has that many elements in it so we can use array. from again so I can say array.

from let's actually call this this length so it'll be easier to write pass in the length this is going to give us an array of length uh plus actually we need it to be plus one I'll keep it I'll keep keep it as I because length is I + one so when I is zero it's we'll have one and then we want to fill this array with

um oh they just have to be filled with ones that's super easy and this one line of code will do it first try I have totally redeemed myself there we go I know how to program um Sweet let's get back to uh let's get back to code Wars uh or yeah uh uh not code Wars Clash of code so let's see how limore did it it looks like everybody watching is mostly a JavaScript developer um and uh we have one PHP developer all right yeah what's up the sneaky Crow yeah we are doing we'll be working in an app that is tar V2 that is correct what's up Andre welcome in as well all right uh let's see Lor's answer they solved it in two minutes and 31 seconds yes that's that's it honestly I think because everybody solved it in JavaScript we're going to see some very similar answers maybe I can point out some differences like they technically

Chapter 9 18:48

Clash 1 - Reviewing Solutions

used let here didn't have to because you could use a const that is the case and thank you the sneaky Crow thank you for that follow uh and there we go Andrew cleaned up the code a bit and kind of just did it all in one line so instead of defining a variable calculate it wrap it in parenthesis call two fixed I'm curious if anybody didn't use two fixed and we'll see how that got them so wble woo look at this we've got some Enterprise level code they wrote a function calculate kinetic energy it takes in the height and the mass and then um we calculate the potential energy which we learned is the kinetic energy they call two fixed and then they log it out nice I probably would have put gravity outside of the function because it is like a global constant and I'm not the biggest fan of uh variable shadowing at the same this this shouldn't be a code review because you're trying to solve it as fast as possible and you're not going to write the best code when you're solving it as

fast as possible but you know I'm trying to make content out of this I think we can code review it but yeah this is uh this is variable shadowing looks like AI code oh I forgot that well this technically was a private Clash but there are Bots that will join non-private clashes and I think they're run by AI because they solve it in like milliseconds and let's see how felon did it yep look at this gravity and all caps that's also another convention where if you have a constant you use all all caps to say that that thing is a constant and uh they hardcoded the plus do zero at the end um beautiful beautiful so first of all math. round drops the decimal completely and then uh and then they just add a zero on the end and they still got it 100% so there're the is says boo that man no I mean if it works it works right I think for these specific problems you're trying to solve it as fast as possible so if you can get all the test

to pass it's as good as any other solution um yeah you have to know rust to build with tar initially not really um because it launches a web View and within that web view you're just doing webbased code so our our codebase is a spelt kit application and so this directory right here SRC is just spel kit if you know spel kit you can code inside of here where you need rust is when you want to do things that are lower level or like trying to do things on the device itself and for that tari has a way of creating custom commands that you can call from the JavaScript side and so you can see here in our tar Source in our lib file we have rust functions that have this annotation on them and any rust function with this annotation you can call from the JavaScript side and so this specific app we're doing things

like converting a file to MP3 so we use like uh FF imp for that we extract metadata with FF probe um there's some YouTube uploading that couldn't be done like directly in the browser so it's actually being done on the rust side so um we are writing rust in that app but um technically you could do some without without it okay great work felon I like like your solution and here's here's my solution we eventually got there uh David Myers is saying I originally had math.

round value do fix but I vered to math that round just realized that that totally drops the decimal though zero yes so divide by 100 round it multiply by 100 it just that would just remove the decimal right um okay Rich did it with JavaScript as well look at this we've got our gravity constant we've got our is this Pascal case I was I was so I know camo case is with starts with the lower lowercase letter first is Pascal case with a capital letter first but like C case and I rossom thank you for that follow um yes so Pascal case is camel case but it starts with a capital letter so look at that that's a that's a pascal case potential energy variable um and then they round it in two fixed I think technically you didn't have to round it

because two fixed would have taken care of that awesome and here goes Lance it with the PHP it's pretty straightforward so uh in PHP I'm guessing this is how you read from uh standard in or read from the input that's given to you and it is reading those in as numbers so percent is probably like decimal and storing them in a variable called height and a variable called Mass uh then we have our gravity constant do the calculation and then it looks like PHP has a number format uh method so we give it the value I'm guessing like number of decimal places we could look into it though let's look at a PHP number format with that what is that thing doing so yeah number number of decimals decimal separator thousands separator fascinating I would think that you would always want the decimal separator to be

a period but maybe not maybe there are some locals where you don't separate you don't use periods for the decimal and so their number format kind of like takes that into account it does look like that these are the the that's the default though um but I guess because you didn't want there to be commas because that would uh they'd be added for thousands that's why you had to pass in all of the arguments to make sure that the the commas didn't happen nice nice PHP great work Lan it let's see how David Myers did um oh we got so this is not quite Enterprise this is like hipster JavaScript code we've got Arrow functions multiple of them um we've got the potential energy function and the kinetic energy function um but the kinetic energy function is not used I'm guessing they were probably reading through the problem and kind of like writing this out as they were reading it and then finally just realized that they didn't need

it um yeah oh that's good to know yeah um uh Vivien is saying in Sweden we use commas but not in programming so it would make sense so like number format potentially would use commas to separate the decimals uh like for displayed values right not not in programming hipster Javas script code yeah um and Scandinavia uses comma as a separator too I see I'm see uh I'm building an app with n and I want to distribute it as a mobile app too I'm afraid tar introduces overhead or makes me learn R it it actually does and honestly that's one of the biggest pain points for me when I was building the app because I I built it uh with Scott from C and we did it in a week cuz it was a hackathon and I mean usually during a hackathon you're trying to just get stuff done and so when I'm trying to get stuff done it's very hard for me to like sit down and learn a new programming language but you definitely do have to learn rust you should look into

Chapter 10 26:14

Hybrid Mobile App Solutions

quazar so quazar uh is quazar dodev I think it's built on top of um capacitor JS and allows you to do crossplatform it also allows you to build like desktop apps too so um let's

see I don't know exactly where to look in here but if you haven't heard of quazar check it out because it takes a capacitor JS capacitor JS which is kind of like the successor to Cordova where you can build hybrid uh mobile apps and and desktop apps where um the mobile app literally just has a web View and your app is running inside of that web view in capacitor has a bunch of plugins so you can do more native things like run in the background access the camera access the file system do Native geolocation push notifications all these things you would want to do on mobile they have JavaScript plugins that allow you to just run them within your codes so like the camera plugin you install it you have to do potentially some specific stuff if you're targeting iOS or Android but then the actual code that you write is just JavaScript code you actually like import this into one of your view components and uh it would do the native

stuff um but that's capacitor uh that comes from the team that did uh ionic um but you don't have to use ionic to use capacitor ionic is kind of like the component Library um that lets you style things to look like iOS look like Android depending on where the code is running so they have uh iOS mode and markdown mode but these are all just components under the hood it's using capacitor but quazar is built on top of capacitor all right I'll stop talking about it now but um you might have better mileage using something like that because you don't have to learn rust you can write everything with with JavaScript um you used a capacitor and ionic to build an NFC scanner nice nice yeah Co I have oh yeah we should do more okay I'm I'm I'm getting distracted um awesome let's do another one that was

that was super fun here we go uh this time let's let's give reverse mode a try so this will show you the inputs and the outputs and you have to figure out what it's asking you have to figure out what code to write let's do it what's up harsh welcome in

yeah Pao are you out there we're starting we're starting and technically we have uh four minutes till it starts we'll give poo time to join because I think they want to they want to hop in let's go do another code wars in the

Chapter 11 29:41

CodeWars - Clean up after your dog

meantime now I'm scared of seven Q's I think the I think the main issue is um I've solved so many of them that the only ones it can show me are the ones that I've been avoiding for the longest time let's just see what this one is clean up after your dog you've stumbled across the Divine pleasure that is owning a dog and a garden now pick up all the crap um you need to find out if you have enough capacity to collect all the crap and make your garden clean again um you are given number of bags and then the garden and you need to see how many there are in there uh that's really easy right so you're given an array of arrays what is the cap number so you have access to bags and the capacity of a bag oh each bag can carry that number of elements I

see okay so the the total amount that we can pick up total possible is bags times cap and then if we want to get all of the um at signs we can actually flatten this array so if I do um x dot is it flatten smoosh there's a method that will take an array of arrays and turn it into a single

array it's just flat yeah this is what what we want so flat is going to turn that array of arrays into a single array and then I want to count every single at sign that's in there what's the best way to do that um oh let's join it all together into a single string replace all of the underscores with nothing and then grab the length because that will be how many at signs there are and if that length is less than the total possible we're done first try no uh expected false to equal C okay so um we need to give a different output um so

if if the length of all of this is less than or equal to the to I I missed the equal sign so or equal to the total amount we can pick up then we will return clean um oh we have to watch out for the dog there's a bunch happening here these I don't think these tests test for that okay so um let's actually do this this is going to give us our garden how much time I got one minute okay so this gives us our garden and then uh if garden. includes a d then we just return dog and then lastly we return C

crap uh is includes on strings

let's log our

garden

console um it didn't replace our underscores is it oh it's like a weird Unicode character

what oh you're right I need replace all thank you phon replace only replaces the first occurrence uh and then I spelled crap wrong okay I think just in time just in time yes yes okay let's go do Clash of kill um all right so this is reverse mode now in Reverse mode you will see input and then output and you have to figure out what code to write now I'm not going to say it out loud I think I'll explain it afterwards because I don't want to influence anyone else but I see what is happening here I think I know what to do so we are going to say the result is to take this

Chapter 12 34:25

Clash 2 - Reverse Mode Initials

input uh split it on spaces and then um oh specifically if we see a professor or a doctor we need to leave that at the beginning okay um okay I'm going to do this in like a loop of sorts I'm going to have my output starts off as an empty string and then we're going to have our um teachers teacher types which is just a set that has professor in it and then also has doctor in it so if we come across a professor or a doctor we know to uh leave it alone actually I want this to be a map because if we come across a professor we need to return Prof and if we come across I mean um

yeah like this if we come across a

doctor uh we return

doctor like this so Professor becomes Prof doctor stays as actually we'll just do it as doctor so that way I can um uh join the final thing on Spaces okay and then um if result at zero we'll say this if result at zero if the first thing in there um is in the map so we'll say if teachers has that teachers has that first result why did I choose a map and not a 2d array because I want to use this has method this has method will work return true or false uh if it's in there so if it's in there then our output um we are going to add the

map at that cool and actually let's call our out let's just make our output and a we can do it like this um

I I'm I'm I'm overthinking this um let's Loop over after splitting it on parts so I'm literally just going to have a a loop fan a standard standard for Loop here that goes from zero while I is left less than all the parts. length increment on each iteration and actually we'll do it uh from index

one so uh if the first thing in their name is either Professor or doctor we are going to push in the abbreviation um otherwise we are going to push in the first letter of that that specific uh item but um we'll say um Parts at zero at zero and I renamed my variable so this needs to be parts now okay split the input if the first element is a professor or a doctor push it into the array with their abbreviation if not just push push push in the first letter and then for every other one uh push in the uh first letter at indexi okay and then the final answer is going to

be the whole thing joined together on periods with one more period at the

end it looks like everything needs to be capitalized so we need to take this and say two uppercase like

this sweet done sixth place not too bad not too bad um how's everyone else doing out there yeah oh thanks Scott actually a uh a viewer a former uh coding Garden viewer actually made this I was just streaming one day and they like like look I made this art um I I like it a lot um yeah and thanks phon for that suggestion earlier with the replace all um I always forget that replace in JavaScript only replaces the uh the first occurrence you have to pass in a regular expression to replace all of them or use replace all which is newer and does that for you yeah uh why a map and not an object uh it's a little more type safe um basically um you're completely right we

Chapter 13 40:29

Maps vs Objects

could just have an object where the keys are professor and then the values are this value here um but um for this code it would have been completely fine because then we instead of using the has method and the get method we would have just used bracket notation um but it's probably because I use so much typescript I've gotten used to using map um but have I got the video for you because I did a video on where objects can actually um uh come back to bite you if if you use them in the wrong way uh JavaScript so if uh if you're interested in that check out this video because I talk about why maps and sets are pretty useful in a lot of scenarios uh this is basically the use case for maps yeah and and I mean honestly I mean before map was ever introduced into JavaScript like we used object everywhere so I I came from a C background and if I ever wanted to do something like this we have the the dictionary type um but it was so cool

when I started learning JavaScript I was like everything's a dictionary everything is keys and values um but yeah the map has it has its has its time in its place yeah of course

Andre first um I'm having trouble that's okay you still have have a little more time yeah object wouldn't uh officially keep its order I guess that yeah that's another caveat again I don't think it would care for this scenario but uh there's something about when you're putting um keys and values into an object dynamically um they potentially won't keep the order that you put them in whereas a map always keeps the same order that the keys were entered in yeah all right I'm going to start looking at Solutions now let's take a look at how Mark did it they did it in two minutes and 13 seconds they used a map that makes perfect sense I I was I'm having a lot of trouble coming up with good Solutions this morning so take the input and actually let's let's talk about um what they wanted us to do so essentially they

Chapter 14 42:28

Clash 2 - Reviewing Solutions

gave us a a name like a first and a last name but sometimes that name would also have professor at the front or doctor at the front and we needed to return all of the initials joined with periods but if they were a professor it should be shortened to Prof and if they were a doctor that should be included in the output as well so split the name on Spaces if the name is Professor we want Prof if it's doctor we just want to return doctor if not we just want to take that first letter send it to uppercase join it all together on a period and then add one more period at the end beautiful solution mark great solution and solved it in two minutes flat great work all right let's see how lore did it um they used a regular expression to split on white space yeah so this is kind of like splitting on a space but this is just in case there's like more than one space um and then they map it this is

the exact same solution as marks um except I like this idea here so instead of needing to join it on a period perod and then adding a period to the end whenever you add the first letter of any given name you always include period because then you don't have to do the extra period on the end I like that good job lore all right Rich did it yeah oh it seems like I have a I had a very unique solution like I didn't use reducer map like everyone else is using um so split the input on spaces and then were they using the answer no I think this is a leftover variable because they just used a reduce to begin with so um a and actually here's a really good coding tip if you ever see

yourself doing like a um a map and then a join or a map and then a filter you could do that all in a single reduce and so that's basically what what rich is doing here is we are mapping and joining all all all in one so this reducer starts off as an empty string and then um if the current word is a doctor we are going to put it on the end why are we putting it on the

end because it's it's always going to be at the beginning this confused me but the only time this code is ever going to be hit is if the uh if accumulator is an empty string so this is like saying empty string plus thing but um thing plus empty string would have done the same thing yeah completely fine okay so uh the accumulator now starts off with uh doctor or Professor okay then this returns and this gets called again now the accumulator is either the first letter of their name with a period or doctor or professor and then we get the next word and so after the next word it's probably just going to run this code that says take the current string and then append the first letter of the current word plus a period to it and then repeat repeat repeat so this one reducer is generating a string and what's nice about this is It's a single iteration as well as well in one iteration we generate the output versus if you use a map and then a join technically that's one iteration to map

over everything and then another iteration to join it all back together um so technically this would be a little bit more performant yeah um and Pao is saying reduce Plus or a thumbs up or thumbs down it depends I think um I think it depends on your team right if you're working with others that use reduce all the time and everyone's really familiar with it go for it but um a lot of times reduce can be very hard to read and there's a lot of cognitive load to break down what this thing is actually doing whereas if you see like a sequential map filter join it's a bit easier for at least my brain to understand what's happening whereas a reduce I kind of have to read the code to figure out what's happening so yeah gusta says I didn't even know it existed yeah cool uh I'm nearly there just last step can you review my code for the

memes memes I'll take a look I'll take a look all right let's see how Pablo did it they try almost code golfed it uh they created a map just were you listening to me uh Pablo or poo um or did you come up with the solu the exact same thing that I did I mean ultimately the solution is different but we both decided to create a map um and so split the incoming string on spaces so we have all the words and then for each word if it exists within this map um then wait wait wait wait oh we use nolish coalescing beautiful that's actually a really cool use of nolish Co coalescing with a map because if it exists in the map it's just going to return that value beautiful and your map actually

has the uh periods inside of it so that way you don't have to do a further join after that um so yeah yeah honestly this might be one of the best use cases of knowledge Co coalescing I've seen because it's like grab the value if it exists you don't have to have like an if statement or like a weird Turner if it's in there get it otherwise take that word grab the first character send it to uppercase put a period on the end and then finally join it all together on a stream yeah great work great great work poo right let's see how Admiral did it um very similar to like one we saw earlier so they split it on Spaces they then map over if it's the first thing they do that otherwise um they grab the first letter send it to uppercase put a period on the end and they used a template literal here instead of just concatenating a period and then we get to my code I can't believe I'm the only person that that so far that didn't use map or

reduce um I used a for Loop so I have my map here it would have been a lot easier if I would have mapped them to periods on the end split it on Spaces if the first element is in our map here then we grab the corresponding value put it into our output array um but if it is not then we grab the first letter and send it to uppercase yeah like technically all of this code right here could have just been put into a map but the way that I was thinking about it is like I always only want to do this to the first value um or the first word in the the the string here and um turns out you really wouldn't have to do that anyways because inside of a map or inside of a an array map it's not going to exist in here unless it is the first thing so yeah all of this codes could have just been inside of a map and then it would have cleaned up this we wouldn't have need this Loop

here because then basically I look at the first thing and then after that I look at every other word after that and I know that it's not going to be a starter so I can just grab the first letter and send it to uppercase great all right uh Lancet with the PHP oo okay let's let's break it down um their function is called get initials it takes in the name a professor becomes a Prof a Prof becomes a Prof a doctor becomes a doctor and a doctor becomes a doctor so they might have just added this so I'm guessing this is this is an associative array this is an this is a map it's it maps from one value to the other and um I'm guessing say they wanted to make sure that the the input could have also provided like the abbreviation and they wanted to make sure to handle that but this is their map that says given this value in the input it's going to be this value in the output this is one of the greatest things about PHP is they have an explode function so the explode

function in PHP is the split function so explode this string on spaces and then we get a a an array with each of the words um and then we have a little for each here so so for each words as index and word some some weird syntax here but this is kind of like a uh for of Loop in JavaScript because this gives us the index value and then this gives us the actual value inside of the array cool then we've got some weird stuff going on here so UC words string to lower so send it to lowercase and then uppercase what is that just a built-in function to do uppercase uppercase is the first character of each word in a string wow that's like uh like title

case so that just uppercases the the first letter fascinating um and then if we're on the first word and the word is in this associative array so is set is I guess a built-in method to work with associative arrays is set check determine if a variable is considered set that means if a variable is declared indifferent than null wait oh no never mind never mind never mind you can just use bracket notation so using bracket notation is how we reach into this associative array so we reach in with the word and if it is not undefined so that's what is set is doing it's saying if yeah it's a not null check uh uh if it is not undefined then we actually use the the value that we looked up in that associative array

yeah um cool and then otherwise we just grab the first letter send it to uppercase put a period on it and then so they have explode to break it apart and then they also have implode to bring it all back down together bring it all back together fascinating great work glance that it was fun to see some some PHP code um are there going to be more videos in the self host 101 series I don't have any planned right now um but maybe eventually there we could potentially do maybe even just a Q&A followup where maybe I get some questions ahead of time try to answer them um all right let's see how wble woo did it and so this is a super secret name over on Twitch don't don't ask me why I made a class I just know I did because I wanted to so here is our enterprise Enterprise solution um we've got a uh we read in the line we then have a name formatter where you

pass in the name there's a process message function and then a get formatted message function so this this is oop objectoriented programming um fascinating and so some of the fields on this class are the m itself whether or not they're a professor whether or not they're a doctor and then ultimately the formatted message so when they call Process message that is going to do the actual work right split it it split it on Spaces um see if it is a professor or a doctor um and then they have a format title and name um function so shift it from the incoming array so this array is going to have every word in it and when you call shift that'll remove the first value in the array

um and then get

initials takes in the array grabs the first word joins it all together

but why is it of like length

one did they uh did they get 100% yeah they solved the problem okay I'm not going to look at this too much longer but I think they purposefully made it like a really convoluted um solution like an Enterprise level solution it's fun it's fun I will say though uh this part here where we're calling format title and name I don't like the fact that so I mean this is object oriented programming you can do what you want but technically this is like a side effect like we are defining the variable in this method and then actually modifying it inside of this function um which I don't like um because that that that value was not defined inside of here then the other thing is you're removing it but you're not doing anything with it that's that's what confused me is

um yeah huh okay great work wble woo super secret name going above and beyond for portability and O op and some NASA kind of readability great work love to see it um yeah exactly it's the opposite opposite of code golf um yeah great work all right let's see how phon did it and then um we've been live for about an hour we'll do one more after this and then we'll we'll get to writing some Rust and tari code um so uh split the message map over it if it's a professor or a doctor return it otherwise return it with a period beautiful great work felon no one used included David Meyer says he used includes I don't know which one you are are you the first one the last one oh yeah there you are

oh yeah unfortunately did you not submit

it um yeah you only got you got 0% for some reason um honorifics oh you ran out of time no that that's okay I had no idea that these were called honorifics that would make sense um yeah and Andre is saying it would be nice if the syntax streams use the chat a aggregator yeah the only issue is my um my chat overlay that I use for coding Garden is very like coding Garden themed I would want to build something that um looks more like syntax if we were to combine the YouTube and twitch chat together and what's up America 2050 welcome in good to see you um yeah well honorifics cool David says I Googled it um so that's Professor doctor great um and then two initials so this splits it on spaces and then for each one we grab the initial so two

initial says if it is one of those we're going to use that as the initial um

fascinating I think this was extra code right here because you're converting an object into an array and then using the includes method um I see what you you were trying to do you were saying if the input string had Professor like if the input string was already abbreviated you wanted to uh use that instead that's what this was trying to do but you used keys in set of values I see um and then otherwise we grab the first letter send it to uppercase um so that looks good and then we want to return um the result with the initial I think your only problem David is you're missing the last period so uh there needs to be a trailing period on the

output uh um yeah okay I see what you're saying um

well so if there is something which there should be because that's the accumulator then you want the previous value with the next value yeah I think that's your only issue David yes yeah so David is saying uh they should have done result initial period and then that would have put the period on the end um all right one more of these and then um let's do a code golf yeah let's do a code Golf and for this you have to use JavaScript it it seems like everyone here is using JavaScript anyways but if uh if I let you use python or Ruby you can make some really short Solutions so this is solve the problem but in the fewest number of characters so we'll we'll see some fun tricks for for code golfing choose typescript typescript would be like impossible to golf because you'd have to have types everywhere um I remember first yeah yeah

yeah um it should still be a an emote on on coding Garden well we have the first try emote

okay um vanilla JavaScript confuses me nowadays yeah I think for me um it doesn't I um I like typescript more now like I I I honestly have have use typescript so much I'm even using it in like oneoff projects that typically I would have just used JavaScript for but yeah uh once a day I get frustrated that websites don't open links in a new tab yeah I use command click a lot oh the the Discord bot used to do something like that fascinating and uh mm lvx thank you very much for that follow all right I'm going to give you 20 more seconds to join The Clash and then we will

start yeah if you have a mouse uh with a middle middle click um that will open it in a new tab too

all right let's get into

it all right um this is shortest mode so technically you can use all 15 minutes to make your code as small as possible um and so if you're uh just just seeing uh Clash of code for the first time problem description is on the left code is on the right and your code size is right here and you want this number to be as small as possible the person with the smallest number uh wins if two people tie whoever got it done in that number quicker uh also win or win instead uh and comments count check this out if I remove these comments um my code size is gradually going down so you don't you don't want comments also this is Javascript so you don't actually need to use conset or VAR and you don't need to use semicolons and you don't need to use spaces in between uh like equal signs

Chapter 15 1:03:07

Clash 3 - Code Golf / Shortest Mode

like this and we don't need that or that so uh those are just some hints as to how how to make it as small as possible typically what I like to do is just solve it first then gradually make it as small as possible because it's really hard to code in a in like a small way yeah but what's up what's up Stony Eagle welcome in um oh oh yeah good point oh no it's a it's a good thing to bring up uh specifically here you can use the word print instead of console log this is just specific to coding game this is not um print in the browser will literally try to print the page um but in this case you can use the word print and that's shorter than console log so uh already we have have this down to 84 characters okay the problem says a B and C are three non- negative integers you will create a division where the numerator is the maximum value of a and c and the denominator is the minimum value of a and C if the denominator is

equal to zero replace it by one the inputs have been chosen such that the numerator will always be divisible by the denominator and so the result great um it seems pretty easy we just have to do exactly what it says uh but if you're new to maths you may not be familiar with numerator and denominator am I even familiar with them I'm pretty sure the numer if the numerator is the Top Value being divided by the bottom value which is the denominator but now I'm second guessing myself uh division numerator the numerator and the denominator yeah so the numerator is the part on Top the denominator is the T on the bottom and D for down denominator is down um so we need to divide the maximum value of ABC by the minimum value of ABC let's do it um so one interesting

thing we can do is uh because JavaScript functions you can pass arguments in even though the argument the functions themselves don't um accept arguments we can abuse that to actually get this all on one single line of code so um if we say um we want to readline and put that inside of a and then we want to readline and put that inside of B actually I think we go in the other no I think we do this we want to do it in reverse and then we want to read line and put that inside of C let's see um what A and C are if we do this yeah 42 and three and if we see this input 4 2 three yes okay so there's your

there's your one hint on how to make this stuff shorter so basically what I did is I put the variable assignment inside the invocation of read line because it's not being used but now all of these variables exist at the top level so um this gets us there then Honestly though uh I don't think we really even need parse int um because we're going to be doing some maths we can use like a A plus sign later honestly I might do this keep the parentheses put the Plus in front of it so that parses it as an

integer yeah okay so that gives us three integers a b and c uh the other thing we could do I said I wouldn't shorten it until we we actually do it but the other thing we can do is we can actually change line to be the letter R so here we can say um uh actually we just do it on the first line say R is equal to read line and now we only have to call R

here sweet okay now uh we

want uh the maximum value of ab and C so we could just do math. Max a b c um and then we're dividing that by math. Min of a b and c I said I wasn't going to do it as short as possible first but I'm I'm going to because this one seems a bit easier if the denominator is equal to zero replace it by one um um so I'm going to do this or one so if math. Min is zero that'll be a falsy value and we'll replace it with

one that's it then we want to Output this

wow okay so I've gotten it in 79 characters one thing is if I were to put ABC into a list and then spread it into math.max would that be shorter um oh and what's up Oscar Oscar is suggesting m equals math is that going to be shorter um print in JavaScript will literally open up the print dial yeah um paragraph counts as a character on coding game um yeah I think any new line is a character watch so right now we're at 79 it's 78 if I put it on the previous line but to put it on the previous line I would need to put a semicolon which makes it back at 79 um all right right now we're at 79 if I if I make m equal to math

um is it shorter than 79 no it's longer it's longer um yeah that's extra characters technically but the other thing I wanted to do um is if I took ABC and then put that into like some values like V and then we spread that is this going to be shorter

that's 87 instead of 79 H I'm trying to think can I do the R equals read line right here or would that break yeah that breaks you have to do that first the other place I could potentially get rid of characters is all of these parentheses

[Music]

um because does math. Max accept um like

strings it does it coerces for us so we don't need to even parse these as uh

numbers wow okay that's 70 characters has anybody done it in less so Meritt did 136 RAV did it in 420 I I don't think I can do it any better I'm going to submit it now so that way if somebody doesn't do it faster or with less characters um then then I win um yeah the fact that it does the coercing automatically I don't think you can you pass an array into math do maxer Min this is going to help anybody potentially uh math. Max I thought you had to spread it yeah that gives you Nan so you do you would have to spread it

yeah didn't know the short rule yeah well it's it's only certain certain uh ones that that we attempt say you have to do it in the shortest number of characters uh this is the first one we're doing like that it's also called code golf they're actually code golf competitions where people try to they have a prompt for a specific kind of program and they try to solve it in the smallest number of bites or the smallest number of characters it is a recreational computer programming competition um but it's fascinating to see like yeah so this is code that prints the first thousand digits of pi uh and it's using a programming language called golf script which is purposefully very tur and short um but people try to golf in in like all programming languages so that's what we're doing right now we're we're we're playing some golf yeah so while we're waiting for everyone else to submit I can explain the project that we're going to work on today and uh how it all works so this is called the syntax production assistant

Chapter 16 1:13:51

What app are we working on?

and it is built on top of tari so tari is a uh way of building cross-platform applications that allow you to use web Technologies and then communicate natively with code that's written in Rust um and we specifically are using the tari uh RC V2 V2 RC um and uh one of the main contributors and I think the creator of of tari was on syntax recently so check out uh yeah episode 821 um where we had uh Daniel Thompson on talking about

tar wikip was was Wikipedia not in dark mode oh yeah yeah yeah yeah it's in dark mode um so uh that's what tari is and then um the actual web Tech that we're using is spel kit so uh this is a meta framework built on top of spelt it gives us routing data loading um it's technically all running as a single page application so uh spel kit isn't necessarily just for like apps that are running on back on the back end um we're using spel kit and it is purely a single page application running inside of a web View um but let's see if we can see how they show things work inside of here um I can actually show you in the code base so uh basically we have two Source directories this Source directory is our spelt kit application and this is just pure spelt kit um there's there's nothing special about it but this directory has all of

our rust code and uh because we want to do Native things like use S uh ffmpeg or FF probe or do Native file uploads all of that code is written here in Rust um and so this is rust code that does the lower level things and does the native stuffs and we can actually call that from the JavaScript side so for instance we have a command here called uh login GitHub any reason for spel Kit over plain spelt mainly because it gives us routing it gives us the router um like data loading strategies um yeah uh so this login GitHub function becomes a method that we can actually call from the JavaScript side so everything here in Rust we Define with uh this annotation that says it's a command and that means when we're running inside of the browser we can actually call this native code so if we

just search for uh login GitHub we can see potentially uh no this is not it I think we call this somewhere else let's just see right here so on the homepage there is a login button that you click that will take you through the ooth flow but when you click it it actually calls down into rust and so this invoke method comes from tari and allows us to name any one of those fun those commands that we defined in the rust code and it will actually uh do Native interop and actually call that native code and invoke it yeah yeah and we're using spel kit in single page application mode so if you look at our is it our vit config or our spelt config yeah so we're using adapter static so the output of this felt kit

application is all client side code JavaScript HTML CSS there's no serers side

stuffs um cool let's look at everyone 's solutions for this oh dang uh David Myers got it in 68 bytes they beat me they beat me by one bite oh yeah and we are using spelt V5 we should pull up the V5 documentation um is it this yes uh so we're using runes like dollar sign State and stuff like that okay how did they do it in two characters less than me let's see wow that makes perfect sense perfect sense it's really funny I'm looking at like the most uh like the hardest code to read ever but I get what happens what's happening here okay so reassign read line to be into the variable R beautiful this actually is a is is great um because yeah instead of using

Chapter 17 1:18:16

Clash 3 - Reviewing Solutions

math.min or math. Max um we um yo that's it's a great solution David this is awesome okay so create an array that has a b and c inside of it so this is going to read in each one and then the plus sign is the unary plus operator so it parses it as a number so now we have an array that has a b and c then we just sort that array so uh we're using the compare comparison method a minus B so it's going to be sorted from least to greatest and this now gives us an array of length three that is in sorted order from least to greatest and then we can use destructuring on the left hand side to grab the lowest value after sorting ignore the second value and then grab the highest value which is going to be the last value in the array so that gives us our denominator and our uh numerator and then from there we just divide in by the denominator or one uh the other aspect that you see David

doing here is putting everything on the same line with a comma so this right here is technically the comma operator and it lets us do multiple things on a single line so it's actually executing that uh then it's executing that then it's executing that uh technically if you just put these on new lines and got rid of the commas it would behave the same way and be the same number of characters but this is a way to like shorten things up and do it do it in a single line um yeah and so yeah this this underscore is a is a throwaway because basically we're destructuring here so we're pulling these values out of this array and we only after sorting we only care about the first and the last so by putting this here we ignore it and that allows us to get the first and the last beautiful beautiful solution David that that's great to see um and so mine I have three variables a b and c um I did this weird thing where um um the call

here is nested inside which saves us a a character because it's not on a separate line but that's just thrown away whenever the function is invoked um um uh I don't know so yeah uh America 2050 is asking would it complain if there was just a comma there I don't know I actually haven't tried that you could add an extra

comma I don't know I don't know well if you remove the underscore then in becomes the second value in the array instead of the last value in the array that's the main issue uh but yeah three values a b and c grab the max grab the Min if the Min is zero then it becomes one all right let's see how phon did it they also did it in 70 characters they came up with the same solution as me um well did they yeah I guess they saved a character by putting m equals math in there did I do that no it's the same number of characters fascinating all right uh let's see how lore did it yeah so having to put each of these on a new line is uh is making you have a extra extra lines of code yeah yeah uh what's up uh Builder boy I'm doing good yeah we're just finishing up with class of clasher code this is the last one we're going to do today um

but yeah thanks for joining us um cool yeah yeah and then wble woo whoa whoa whoa whoa okay so uh a is math BC and D is an array of length three that's filled with nothing and then we map over it read each number in parse it as an integer so this is going to give us a um an array of all three things read in and then after that we do the codes here okay yeah so instead of needing to call read line three times they just create an array of Link three which allows them to call read line three times all right let's see how Maris did it yeah I don't think they tried to shorten it they kind of just solved it um Can the sort method work without

the plus that's what Oscar is asking right now maybe yes it can oh wow you could get this even shorter David because uh a minus B is going to coer both of those into numbers [Music] wow wow you could have shortened it by three characters um it was complaining for you okay and then yeah Stony is saying that HST C comma comma a is valid so um in yeah it was this solution where we want to ignore that middle value um if you just leave it off it also ignores it cool all right uh did we look at maris's

yeah we did pretty standard let's look at Prav did not know that we were playing code golf so U but they still solved it so they grabbed the max they grabbed the min uh if the men is equal to zero set it to one divide them out beautiful um it could be short by four characters so get rid of all three of the pluses oh yeah you're right get rid of all three pluses and get rid of the underscore oh oh our powers combined we are the best JavaScript code golfer all right that was super fun thanks everyone for joining in it's so cool to see everyone's Solutions um when we play this over on the coding Garden a lot of people tune in that aren't JavaScript developers so we see Solutions in like C and Java and rust and stuff like that um but yeah it's always it's always fun to see how other people approach the problem as well okay uh I'm going to take a quick five minute break but when I come back we are going to work on the syntax production assistant which is a tari app built with spelt kit and we're specifically going

Chapter 18 1:25:13

What issues will we work on?

to be looking at some issues here that our producer Randy opened up um the first one is about a blinking cursor so let me actually just start up the app really quick to show you what it

does okay so I can run pnpm run tar Dev this will spin up tar and then tar launches a web browser uh well launches a native UI that has a a a web browser inside of it so um this here is our native application and um you can see that uh it has all of my projects inside of it um we probably need to disable selection on this main page um and oh I don't have the latest code let me grab the latest code because I I do believe that that got merged into um Main and those are all the fixs that I made last time

yeah cool uh did I get a professional set designer for the backdrop uh no no I I uh probably I think it was like a a week or two before I started started at syntax I started just collecting things um you can see uh I got these on eBay there's a Mac Macintosh 2C and then the IBM personal computer 330 so it's actually the one of the first personal computers by IBM um I found both of those on eBay um and then you can't usually see it cuz it's so blurry but this is it Focus yeah this is uh uh Windows 95 the actual box with the CD inside of it and then I have Microsoft front page the actual box and the internet suite which includes um what does it include uh Netscape Navigator I think

Chapter 19 1:26:45

My Backdrop Explained

yeah okay here we are here's the app and it has all the latest features that I added last time like actually being able to remove projects like this beautiful beautiful but the whole idea is um it allows for streamlined publishing of the podcast so you can create a new project and then you drop a video in and that video uh was exported from Da Vinci resolve where we we do all of our editing let me grab an example here and when we export we include all of the chapter metadata so we can actually extract that out and we also uh want to take this video file and convert it into an MP3 so if I take this episode for instance and I drop it in you'll see behind the scenes it's slowly converting that into an MP3 file um and that MP3 file is actually what's going to be published uh to all of the podcast platforms so you can see that it's generating it right here so great it generated that and then the other thing is we extract the

Chapter 20 1:27:55

App Demo

metadata which is all the chapter info and we uh use that in our notes here because that's uh it goes to multiple places right it needs to go to the YouTube description description so like if you look at episode uh 816 on YouTube yeah I need to clean up my hard drive the the the recordings for the best next J for this video it's a two and a half hour long video uh were huge so I have some some space I need to clean up on my machine um but if we look at the episode your CSS sucks you can see that in the YouTube description the time stamps are here right so that's one place where those time stamps need to go the other spot is on the syntax website so if you go to the syntax website and you go to that specific episode um your CSS sucks we have all the show notes here the other place that

that exists is on Spotify um syntax Spotify see and anywhere where you you get your podcast so uh inside of any podcast Ed editor when you look at the episode it's going to have these show notes with all of these time stamps right so there's multiple places that all need this stuff um and this app allows you to extract it out and and then use it across all those places so we extracted the metadata we generated this markdown but we can copy as text and then that gives us um text that we can use on the YouTube description because this doesn't need to have all of that marked down and then whenever we publish to platforms like Spotify and apple music music they we use a a platform for that and they specifically want us to they have an HTML editor and that's basically what gets published to our RSS feed so we want to take these same notes um and copy them as HTML to

be used in that publishing place um and so this is the editor where you can also add more show notes and things like that um we integrated with AI I don't have my AI API key but this will like generate uh more title ideas and then lastly you have publish so this tab will automatically create a pool request on GitHub with all of these notes and that pool request when merged creates the page on the on the syntax website um so if we actually look at the syntax website you can see some recent pull requests um maybe ones that were closed yeah these were automatically created by the tool you can see autocreated by the syntax production assistant and so it calls the GitHub API it makes a pool request um and then uh PRS this markdown file with all that same info so the whole idea here is like streamline the process um that's that's

what the app does um but there's some things we need to fix so right now uh whenever we are in here in light mode the cursor is the wrong color so we'll need to fix that um yeah and then this is going to help Randy out by adding uh Sig pics and then also adding the show notes title because right now you can see that um it just shows the notes here whenever we create the pr we automatically add all of the socials um but Randy wants to easily be able to just have a a section that inserts the sips and Shameless plugs so that way he can edit it with from within the the editor here cool um yeah so and then the other thing is right now this editor whenever you click copy as HTML it doesn't have all the

Social Links um but when we publish to GitHub and we create this PR we're actually adding all of this stuff when we create the PR but we probably just need to have this in the markdown editor itself we don't need to like add it on so that's what I'll fix there we'll start there we'll see how long that takes us and then we'll work on some other things the to-do list is too long yeah I'm I'm I'm working away at it but so Scott and I built this as a part of hack we so um we work at syntax which is brought to you by centry and every year centry has a hack we where everyone at the company stops what they're doing and just decides to build something and it can be anything we decided to build this um and so we got to work on it which was great uh tell me the editor is Inc mde I'm pretty sure that sounds right I I I part of like during hack week I specifically spent probably an hour and a half just looking at different um markdown editors and then I settled on this

one um oh you're the maintainer nice I'm pretty okay your name looked familiar I'm pretty sure let me double check um if you're here then I have a suggestion for you because I actually instead of using the the built-in felt component um I had to write my own rapper for styling purposes um mark down

is it in

components I should just be showing you this code I'm pretty sure we I guess I could look at the package Json but I'm pretty sure we used ink MD that sounds so familiar um yeah we did there it is the maintainer is here and a really good code golfer um but let me show you what we what we did and why I had to write my own rapper which I can't seem to find in the codes here um so if we go to Project by ID notes you just made your day yeah yeah uh of all the ones I tested this one was just like it worked the way that I wanted it to there's still some some things we need to to switch up but um yeah it works um thought we wrote a custom wrapper component we must not have we probably

should extract it out to its own component um let me see let me see uh yeah yeah at this point we should we should extract it to its own component because you can see we have two different things that are using it I think I don't know if this One is using it um but uh I mean since since you're here I'll just tell you the main reason I didn't use the built-in spelt component is because it has a top level div and I couldn't style the the top level div um so yeah if we look at the ink M deep e component uh this actually I mean maybe could I have passed I have passed styles to the element itself would they AO would would they have automat atically gotten forward forwarded I don't know it was hack we I think I was rushing but basically I used the component and I was like oh I can't I can't apply styles to this element itself so then I just wrote my own

rapper that pulls ink mde directly and then binds it to an element yeah um yeah one one of the things we also liked about it is all of the CSS variables that you made available um where are they we haven't touched them yet cuz we haven't found the time but the fact that it's so customizable with all these CSS variables is also one of the reasons we we chose it yeah yeah cool yeah I mean I might I might make a PR or something like that um again it was hack week so we're just like trying to get the stuff together but that's awesome thank you thank you for being here live roasting coming no I think I mean we we we did our best with that component um yeah cuz see I wanted to apply all these Styles directly to that top level element it might have been possible I don't know I don't know oh Wes just tweeted the fingerboard

Chapter 21 1:37:01

Syntax Fingerboards

I want to go look because I I want some um yeah okay we are releasing next Monday uh syntax fingerboards so I have I have the the giant size skateboard that uh is uh mini siiz you skate with your

fingers um but yeah it's going to release next week and uh a couple of hats are going to release be released I think uh Scott and West tease what the hats look like um all of your sons have the the syntax fingerboards as gifts nice yeah I'm excited about these there's actually a fingerboard Park not too far from where I live so I'll have to to take it out there do do some tricks um okay I'm going to take a 5 minute break I'm going to get some water you all should do the same thing Get Up Stand Up walk around a little bit and then when we come back we are going to work on this app this syntax production assistant which is built with tar and spel kit I'll see you in uh five minutes yeah okay now I'm curious what is West boss's website because didn't his domain get taken there's an Easter egg on the right hand side but

did yeah they uh there was that whole deal with taking his domain where's the Easter

egg is my window too small make my screen really wide I might have to do it on a separate screen make it really white oh you won't be able to see this because the the monitor I'm streaming from um it doesn't have it I mean maybe I can uh yeah yeah look at this on the on the right hand side it says wow you have a big screen or yeah it says wow you have a big monitor that's great okay back in 5 minutes uh stay awesome and uh we'll see you soon we'll see you soon

Chapter 22 1:39:30

Break

[Music] n [Music]

[Music]

[Music] n

[Music]

[Music]

[Music]

[Music]

he [Music]

[Music] hey

hey hey

[Music] hey [Music]

hey hey

[Music] hey [Music]

[Music]

Chapter 23 1:45:46

Editor Dark / Light Mode

we're back welcome back everyone hopefully you took a quick little break let's get into it let's write some more codes so we're working on the syntax production assistant it's this native app here built with tari and spel kit and we have some bugs to fix so the first bug is the blinking cursor in light mode um and how am I going to get that I guess are we using a a theme for like light and dark mode I could change my overall system settings um I'm curious I'm just going to look at the top level CSS

so let's see static no where's the CSS I guess is it just in the top level

component the top level route in the layout oh there it is styles to CSS that makes sense um I'm guessing we're we're using like yeah prefers a media query for the theme yeah so if prefers color scheme light let me overwrite it um I think I'm just going to have to change my OS settings so that it it swaps it out uh so let me do that really

quick whoa everything's instantly brighter I don't know how long I'll be able to uh how long I'll be able to work this way okay so when we're in light mode uh yeah everything needs to be swapped here in the editor um because the cursor because the yeah the cursor is white our top bar here um is the darker color what does it look like in dark mode oh yeah it's the actual like editor stuff okay let's do our best so we need a media query for prefers light and then we're going to override the editor Styles so if we head into the notes page we can see that there is an editor class here and that's where we're setting all of the Styles um and we specifically need to add a media query in here that overrides those

Styles if they are in light mode um and I think the when we instantiate the editor we also pass in appearance

yeah um we're going to need to watch the we need to pass we need to take into account the the users's preferred um their preferred setting dark or light and then pass that in

here okay first of all I think I'm just going to refactor the editor into its own component because we are using it in two different spots here do I need to refact I'm just going to get it working first okay I need a uh a media query like a live there's there's a way to do a live media query um JavaScript media query uh basically oh light mode jeez uh match media match media is the thing that we want so we can pass in the media query and um this will actually get we can pass in a call back and it'll get fired if it changes but we can also like get the value I'm pretty sure so let's che check out mdn for I need to I got to change back to dark mode I did this to myself yeah um we can we can code in dark mode and then honestly if if we pass the correct

thing into the editor we probably should we won't have to fix anything else yeah let's WR it to together for never light mode what's up mosika welcome in uh trick trick the app to use light mode um right now we're just using the system preference as the thing there there would be a way to do it there would be a way to like store it in local storage and give the user a toggle right now we're not doing that um we could add that but I'm not going to worry about it um yeah I need match Media or JavaScript um this isn't the one that accepts a call back though there is one that accepts a call back when it

changes regardless we should be able to get the initial mode like so so uh inside of here we can do a match media and then um we'll say prefers dark and then we can pass in the media query that looks for dark mode which is this prefers I guess swap it around um this and then we'll say we'll say prefers light and so this should be a Boolean uh no it's a media query list see how this works oh dot ma dot matches is a Boolean we're going to call

that prefers light but I forgot in this code base we use uh uh underscore case I forget what that's called okay prefers light so if prefers light is true I'm actually going to put this into a variable called appearance so then I can just pass it into the other two snake yeah snake case yeah so the um appearance is that great work codium so uh and I spelled this wrong I did I did the wrong thing prefers light like that great now we'll just directly pass appearance into our Define options

and that should be all we need I think except if we have any specific styles that are dark mode Styles um then we'd have to override them but I don't think so because I think Shader tint is going to be set to the right thing depending on dark or light mode so this should be good enough when the page loads what we potentially have to worry about is if the user's pref uh preferred scheme changes while the app is open because this isn't going to be dynamic but let's see if this gives us what we expect we'll turn on light mode and refresh the app uh what's the best way to do

that okay that didn't work um let's double check ink mde and make sure that I'm passing in the right option there um well no appearance can be dark or light well that's that but is interface typed no yeah it's it's it's accepting darker light um let's just log out the appearance to see if we're getting the right thing

appearance is dark uh change to light mode fresh appearance is still

dark do I need to completely kill the app let's try it

oh I mean this is actually amazing to have the creator of the editor in in the chat uh it relies on the system value does your app let the user override dark or light uh we don't so we should just do auto great that that'll that should fix our problem then okay we'll do auto

sick see if this fixes it for us you know what I think oh it fixed it beautiful yeah I think the right now that's what I was trying to see because when I was looking at the types um it just said dark or light it could have just been for that one specific scenario uh

no your types are right I can accept Auto okay uh that's great way less code for me um I I'm curious though does it listen to the um um and then now yeah look at that thank thank you David that's actually amazing you're able to you're just here and you can just help us and it is your library is already listening to the uh to that specific media query beautiful another reason to use ink mde sweet that's one bug fixed with two lines of code um nice sweet okay love to see it now because I'm an over engineer should we extract this into a separate

component yeah we should but since I'm here I think this is this is one aspect of like uh reducing the amount of uh Tech debt is um extracting things out reusing stuffs though I think it's going to be a hard Factor like if I look at how many places where um yeah I'm doing like this after

update I don't want to do it we're going to work on other more important things honestly we might have one day where uh we just do refactors but we got other things to work on let's just Commit This

and this is how we get code smell says Lance yeah I mean this is how we get teched at honestly like uh but I don't mind

uh let me open up a PR and then we'll work on the next thing um so when I open the pr I can say that it fixes number

26 fixes number 26 that should um link up the issue automatically

thought that it

would yeah shows a reference here and then yeah when that PR gets merged just going to Auto close this issue sweet all right let's keep

Chapter 24 1:59:08

Fixing show notes bugs / flow

moving the next issue we will work on is um adding sick piics to notes by default yeah I think what I I think what I want to do is whenever we add the notes in we'll just have all of this stuff and we won't hide it because right now um those socials get added specifically when making the GitHub PR so if we take a look at GitHub and then when we make the pool request I believe I thought I was adding in the show notes in somewhere somewhere in here it might actually be um when I call the method I'm passing in all those extra links so if we look at publish yeah right here so you can see when I create the pr it's just a big old template string and then I pass in all of this stuff here but I think what we

can do is when we import the video put this in the notes itself um and then also add in the sick pics in the notes as well that's what we'll do so we're going to grab

this and when we actually create the notes which is over here after they get imported I'm going to add this

in YouTube was spelled wrong inside of that

file here

here oh here gotcha I mean might as well good good good catch good catch okay so uh this file specifically loads in unless it's a prop ID and path

name maybe it's in the top level project component that actually does the import because when it Imports it sets the notes on the um project itself yeah here we go um so this function runs after dropping the video into the app because uh it will behind the scenes it's calling tari to do the FF probe which extracts the chapters and then after the chapters are extracted we now have the notes here so I think what I want to do is I just want to say notes are equal to um what they already are I guess I I guess I could plus equal them

this um and then we'll just make this let let because that will add that there and then um we also can put the header right above

it so that makes me actually want to do this we can say show notes

notes and then links and then uh we'll add the sick pics and Shameless

plugs like that okay so now whenever the stuff gets imported it's just going to add all of that automatically

if it's spelled wrong it's a to-do and it's probably my fault honestly I think I added all of those to-dos I we could do a get blame on that uh on that line but um SC Scott is saying it's their misspelling okay uh let's try a brand new project and the hope is when we drop a file in it's going to automatically add the title The um uh the links pics all of that automatically and it looks like it hung on MP3 creation um maybe I just need to restart the app but it did H all of this so check it out now it says show notes it has all of this um and then all of the links

beautiful Scott is saying um our show notes for syntax are basically a competition who see who can spell worse um cool so I mean this pretty much does it I think the one issue is whenever someone clicks uh copy as text they potentially don't want all of this extra stuff um so so this app needs AI to run over the show notes and fix spelling errors probably not I think ry's really good about not having spelling errors

um this looks good the only reason I'm like hesitating right now is I think about the the fact that when these notes get added to YouTube uh it doesn't have all the hit us up on socials it's much shorter than that uh it is just this section here so I think what I need to do is whenever I kind of want to change this button instead of copy as text it's like uh copy timestamps as text cuz that way we can only when they do that we can only give them this and all the extra stuff cu the other thing I'm thinking about is like we could have checkboxes that say like include sick pic or include links the only issue with that is like figuring out where to put them like do we put like if the notes are already there do we just appin them to the bottom um I kind of I kind of like leaving it

this way and then changing this to copy as YouTube text and then only pulling the the timestamps there I think that's what I want

um so that copy button where is that

oh that's going to be on the editor page of

course we have the person that actually cares about this in the chat what's up Randy So Randy is our producer and he is saying is it possible to copy the time stamps and above it would also include the episode description that's added after um is this the decipherer himself yes so it could honestly that makes me that makes me want to put these two things like in a separate editor that we then combine together at the end because if that's the case you can have a checkbox down here that says include s pck and then include Social Links and if you don't check sick P then it's just the Social Links but if you um you know you know what I mean that kind of thing um because and I guess the other thing is the summary that might even need to be a separate box

um because like for YouTube I guess you are including all of this and it does have the word show notes on it that's what I was concerned about is like does it have the word show notes and it does because when we render this out um it would just remove the like the heading there yeah okay how are you feeling about that Randy I'm thinking sick pics and then also the socials um are um just checkboxes honestly well I guess sipix and in Shameless plugs we would need to have text but socials are always the same right this is never this never changes is that accurate to say yeah and I mean this front matter editor is technically uh an editor instance as

well yeah I think that's the path I'm going to go down um is it possible those time stamps are added to the YouTube video in some way they are so um we had Youtube upload um and it includes that in in the description so on any YouTube video if you have timestamps in the description they show up as chapters like this so that you get that for free as long as they're in this this exact format and that's that's why we do

it I drop down any with only show notes um yeah I guess I I keep thinking thinking about the main issue is we have all these different export modes right and sometimes you want to have the sick pck Shameless plugs and socials sometimes you don't like the text that goes to our podcast publishing does include sick pics and and uh socials and then the text on the website does include sick picss and socials but YouTube does not include sck pics and socials and is that the only

place okay executive decision I'm going to put it in a separate editor and then socials doesn't even need to be an editor it just needs to be an include socials button that's what we're going to do I like that yeah checkbooks sound good to me says Prav well ultimately ry's the customer so I manag to Randy but I think I think Randy likes anything that's going to make his job easier um and so where do I put these check boxes Randy says love it all sweet um Let me let me pull up the YouTube chat because uh David who's the creator of the the Inc MD editor says I had like 50 instances on a single page without much performance impact that's awesome um yeah

okay yeah I think Aon has it and that's where my mind's going so if you check the box that says include sick pics it opens up an editor with the default text and then you can add them in and then if you check the box that says include uh show notes it opens up that editor with the default text and you can change it if you want to um I think the other aspect is um there should be a a button specifically that's copy show notes and so that's going to be the copy button for just this editor not the other two and then the other buttons include everything you see what I'm saying you see we'll get there okay first of all we need some check boxes um and I think I'm just going to put this below the editor and honestly at this point now that we have we're going to have multiple editors I probably should extract it into its own component uh but let's just get the checkbox working first so uh right here we're going to have a section we're going to have an

input type is checkbox um I don't want to bind it to that but we'll pick a variable um we'll create a variable called uh include sick picks and then we'll wrap this in a label

to cool and then include s pics is just going to start off as

false and we're using runes so uh we do dollar sign state starts off as false beautiful now uh let's see what this looks like it's going to be at the

bottom yeah seems fine all right now uh I was avoiding it but we're we're going to extract the this editor into its own component okay um here we go components we're going to call this the uh markdown

editor make sure it's typescript and then we're going to do it one at a time and just make sure everything works the way that we intend so we're going to pull out uh this editor

here and then in our component it'll Define these options we pull Define options in from uh ink

mde right um and then I think notes or uh the dock is just going to be a prop um there is a Define there's a way to do props now in spelt get props props how do we do props oh my screen just flashed on and off for a second um dollar sign oh that's easy enough dollar dollar sign props

um and can we type this thing what's the I probably should just look at the docs for spel V5 what what do we do with these uh to type

it type script yeah exactly I bounced back and forth between react View and spell so I like is it Define props I know that's the the the um the one that's in um the composition API um we just P yeah we just pass in a generic easy enough okay so uh pass this in we'll say that Doc is a

string um and then can we explicitly extract out doc see any type what am I doing wrong here

I think typescript just isn't working this this should be how it goes because now when we instantiate it we will just pass it in um and then we also are going to want some kind of like after update function that that that it can can pass in so um we'll take in after update which is um just a function that takes in a string yeah returns void

so I mean I guess technically we could you could pass in all of the options but I think every one of our editors is going to have the same options so it makes sense to abstract it this way but after update is a function that takes in a string returns void great um and now we can call that here so we'd call after update at the dock I mean technically I can just do that can't I cool and so now we would Define that component over here and we would have some um update function that takes in the dock and does this I'm going to I'm going to need to use that whenever we extract the rest of the component out

um okay so those are the options and then when we render it out it looks like this

and then we have an editor instance

and then we also have an ink instance uh where are we using that here

Okay so we've got the instance um when basically when the component mounts when it's available we then instantiate Inc and create an instance oh we can use so Scott is saying we can use custom events and then you can do on custom okay we'll do this instead of the uh after update well you can do it with regular JS that's how I was going to do it that's kind of like the react way but um we'll try to use events and I'll figure out but that means in the docks okay um declared but never

read what did what do we use the ink instance for in here

are we calling like instance. update or something like

that yeah I think we're going to just need some kind of update of it

why is this complaining possibly no that's okay okay uh at this point I'm going to try to render out my markdown

editor I don't know why I can't find it automatically let me just reload the

window I think it's a Remnant I think the code before needed the instance to call update on it but then later on didn't need that anymore uh unless we are we we exporting it no it's just a let I think I think it was left over from before we'll probably need it for something because we're going to need to call update on it and I think I'm going to make an event available called update so we can manually change the the document um and then we will accept a prop called visible that's fine

okay next we also need the Styles here

where does the date show up oh it's all yeah it's all broken right now um I'm just going to bring all of these Styles in for now and then remove them as we add other stuff okay so these Styles exist and we don't have a data input here

and then uh specifically we add the I'm going to leave that there because we might need to pass in a a prop that allows us to add that padding or allows it to be styled and so if you're not familiar with spelt by default these are scoped Styles so these Styles won't leak out of this component they're only going to be accessible and applied right right here um okay let's do custom events

now typescript wait what for a second you saw effect and weren using SP yeah we're using spelt it's it's the runes runes gives you that dollar sign effect thing yeah I forgot about I I'm focusing on the code missing all the uh the twitch chats yeah what's up Nate dun um I don't think I have a link here but I do have all my settings up on uh on GitHub my theme is called just

black okay uh custom event

action uh Mii Andre is asking have I tried Vim I have I've never I mean I've never spent the time trying to configure it and make it what I want and I have not tried Vim motions no I've probably been programming too long to finally decide to pick up Vim I have to stay not using Vim I guess okay okay so we Define an action

that I'm having a really hard time understanding what this even does um let's see if they have it in the spel V5 docks

actions are functions that are called when an element is created they can return an object with a destroy method that is called after the element is unmounted

okay sometimes actions emit custom events and apply custom attributes to the element they are applied to to support this actions typed with action or action return can have a last perimeter

attributes where is handle andit coming

from

um yeah America 2015 says I've programmed for too long we have way more programming to come to come is probably true uh you make a felt action which is basically a life cycle for a Dom

element I keep staring at it but handle emit uh is nowhere to be found so

what okay it's not meant to be it's meant to be like you define it yourself and then we want to use this

action you pass in some

prop um I'm G to be really honest Scot I don't think I want to use this I get this does not seem easy like CU I can't even so there's there's two scenarios right we have uh we Define the component here the thing that will need to be the uh receiver of events is the opposite side is going to be over here so like over here um there needs to be like an on um uh on update and then something like

this I'm going to write what I think the code should look like and then fix it afterwards um so let's just call this uh on notes update I like

that so when update happens it's going to call this we should be good um and then I need to import markdown editor

great then it should complain about missing

props um so we will pass the dock in as notes and then we'll pass visible in as editor visible and we'll get rid of this after update

okay uh just pass a function as a prop so don't do on update or are you saying I don't have to use actions anymore are you saying that I can just do it as uh function passing I could try to figure it out though um I guess I want on Emit and then I can handle the type that was emitted

gu says just just use prop passing now now I'm I'm hard-headed I want to figure it out um where is this look outside oh use click outside I I see this ain't for me I I think I there's other scenarios where this might work I'm just going to pass the prop down um so yeah we'll do on update and now over here on update

we'll call this on update and then after update which takes in Doc we'll call on update with the doc simple I guess uh cannot fan name on update oh then I must destructure it

okay is that it did I do it do I have a custom component [Laughter] now um so yeah we have this editor here um which is my custom component yeah great so now let's get rid of this stuff and we're going to be pulling this into uh those um other

editors I should be looking at the dev tools too because there could be things going horribly wrong

looks all right okay so now that we have ourselves a little component um we can add another one below the sick pcks um and so this is going to be visible if include sick pck is visible

then do we store this on the project and like combine it all together afterwards because right now a project only has um notes but would it make sense for a project to also have uh sick pics Shameless plugs socials

the thing is we're already storing the chapters the chapters are basically the time

stamps I think we uh we always like I think because they get PR to GitHub as just one big markdown file we think of them as notes but they're kind of separate pieces right I think it might even make sense to have a summary and then uh notes which are the time stamps and then socials and then sck pics and each one is a separate property on the project and the main reason I want it to be a separate property is so that uh they're all saved separately and then whenever we make a PR whatever we do a copy we combine them together accordingly I think that's got to be the way to go because we already have one for front matter um got to be it going create another prop called um sick

PS and then another one called socials

[Music] um and then we're grabbing the project notes and putting it into a state variable guess we want to do the same thing with s

piix then we also want one for socials and then we can order it in the order that it's actually defined

in and so this editor um will BEP and then we'll do the same thing we'll have a checkbox for socials

this will be include

socials and the doc will be

socials okay uh we're not passing in the on update function because up here what is on update do on update overwrites and then updates okay yeah we need a similar thing for all of the other types of updates so on SI Pi update we'll say s pick equals that Doc and then we save it to index DB and then we do the same thing for

socials cool now I need to pass those in I also need uh are they visible

variables I'm going to rename this from editor visible to notes

visible I'm also right now thinking about okay well could we actually do this inside the component like could I pass the component the name of the um project prop that it's in charge of and then it could actually pull all this stuff in itself and it could handle the updating itself I of like that idea

huh yeah let's do that because that's actually going to clean up the code a whole lot I'm going to rename this to project markdown editor um because it will specifically be tied to projects you won't use this for other types of markdown um but then we could literally accept a prop that is uh yeah I'll rename this to project markdown

editor and we can tell it that the field is

notes when does notes visible get set

it's just based on whether or not there are notes um I think we want we want this all the I think we want it to be visible all the time I actually I know there's a bug that if you delete all of the text in the markdown editor it just like disappears um

yeah I'm making the executive decision it's all just going to be there anyways whenever you open up the app

um that's what I'm thinking okay but now if we just pass in the field we don't need any of this other stuff because it can all handle it internally um like this and so over here field is going to be key of project this project has all these properties which means field

um why does it say it's the any type

this should work I mean honestly I just want it to be the string

Fields um yeah I'll just make my own little little type here

we'll do it on the other side check it out we are going to say uh

the uh markdown Fields project markdown Fields is going to be project but we're going to use pick which is a typescript thing um we want to specifically pick notes six look at that AI is uh new okay so notes six pck socials but also front

matter and so now this is a type that um only has those properties that we care about and so over here I want it to be key of those I guess I could have just literally created a a type for it or I mean I could have literally just had a type called notes um front matter sipic socials but I I think I have my reasons for doing this okay so we we pick we know what field we want to listen to then we actually have to extract it out from state so like this it pulls it in when the component mounts so we do something like this but we'd say the doc is uh app data which we Import in and instead of saying do

notes we say at field

um field is why why can't it find the this type here it says this is the any type what if I just Define it in line how does it know man uh is there a different extension I need to get type completion for props and spelt

V5 how to type a prop in spelt V5

do you not pass it in like this do we say this is of this type and it's equal to props yes okay that works better

uh project is possibly undefined can I use the question mark

here this kind of expression is always truthy what

like that because project we're picking that specific field that grabs the initial value um Co that should be all we need and then our on update function can call save with that specific field

I'm going to rename this to value and pass it in like this so that way I can overwrite it like that and then here we'll say at that specific field set it equal to the dock

um and then where does data. ID come from Project

ID H is there a way to get I guess I just I probably just want pass it in to the

component ID is just a

string a state referenced in its own scope will never update did you mean to reference it inside a

closure no I I guess I know that that's the initial

value okay we never hide it we have the editor great this simplifies a lot of stuff so I can now have a project markdown editor where the the field is notes and the ID is uh ID or data.

ID see um and then same thing here but I can say the field is sick F actually I should get type completion on this yeah sick picss and then we want another

one I guess we do want a visible prop for these okay we'll do that as well but that goes here and then this will be

socials um

we need to pass in a visible

prop and we need another one for include socials and then back over here we can add

visibility which is another prop that's optional and defaults to true

great I broke it all let's let's see what the problem is I'm going to restart uh tar

okay we go to notes everything is broken let's fix it can I find variable notes visible

not find variable format front matter editor visible I guess I'll just put these back for now get it working

okay so we have a show notes editor and then if I click this we have a sipix editor and if I click this we have a social editor that was a uh that was a long convoluted refactor but I think it was worth it because the the main component is now oh you could you can't even see the the app give me a second sorry uh yeah basically you can check these boxes and it hides and shows the editor and now we can give these a default value too okay uh and our parent component can can get cleaned up so now our parent component doesn't have to care about saving because it's being saved inside of the component which is good um yeah the front matter is like slightly different it has like a custom logic so I think I'm going to

leave the front matter as not using the custom component at least for now cuz it's that would more like be like a yaml editor rather than a markdown

editor cool let's clean it up a little bit so um this needs some margin around it I'm going to give this a uh class let's call it

[Music]

um optional editor it wraps it with like a

checkbox and now our optional editor class just has some margin top and

bottom cool great now let's add the logic where uh if it is a um sick pick it has a default value um and if it's a socials it also has a default value

so we probably want some kind of constants do we have constants [Music]

anywhere we don't

I'm just going to create a constants folder and then we'll create a uh project constants and we'll have a variable called um socials that is just a big old long string with all the default socials and then another one that has the sick pcks and Shameless plugs default info so we can grab that from the main page this

stuff need to add myself a to-do here to-do add socials and and uh s piix because this this is the file that uh PRS it to to GitHub okay uh so now back over here we can plug this

in cool and now we can use those default values inside of the editor so um let's just create a little map of default

values where uh we include notes which is nothing sick pics socials great uh but we can import stipic right here from our constants

like that

yeah and now that I'm thinking about it I'm going to get rid of front matter because we don't want them to we don't want to use this editor for front matter because it has its own editor great now that we have these default values we can use them so

if instead of setting it to the empty string we're going to set the default values at that given field like

that okay uh however

um is there an after load function on these options I'm going to look at the uh the docs for ink mde

looks like we have after update and before update I think the main thing is like when um when the component mounts I actually want to save the project because when it mounts we potentially want to set sick picks to um the underlying value

cool

um as you can see this has been a a fairly tricky implementation for me extracting it out this way um but I think we're really close I'm just thinking about the scenario where you check this box and then um we need to set the initial value but if you uncheck it we need to reset it back to the empty

[Music] string yeah but uh with that I guess I will show with the change that I just made this should actually work so if I check SI pics uh it pulls in the default values check that out and if I pck check socials it's got all the default values there the um the only issue is this isn't actually saved to the DB yet um it's just the displayed value that's basically what I'm talking about now

okay um I think I'll just listen to when when it's

checked probably literally tap into like the on change

here and uh

do I tap in the on change or do I just use an effect I think I'll use an

effect right see you later Randy I mean honestly this is taking me longer than it should but uh have a good one we'll see you later can I optionally change the oh you might be right I was trying to figure out what the not notation was for that um I didn't realize that you could do dot question mark like that is that

possible yeah I just get a weird weird error there question mark do bracket or question mark then

[Music] dot

great thank you thanks everyone that helped with that

um yeah okay so uh this mounts it sets sets the value on Mount um if it wasn't yet set and now I want to listen for when the checkbox is checked and unchecked because if it's unchecked I actually want to set those notes back to the empty string um so that they don't get saved under the hood so I want an effect that says uh if

um sick include six pick is true then we're going to uh save

it but if not we're we're going to clear it out yeah and Mii is asking uh is effect like a view Watcher um it is yeah it's basically a way to run stuff when stuff

changes oh that's good to know David I don't know can we do top level a weight in spelt components

yeah we're not really even technically using it right now anyways but it's good to know um and if this is if if it's false then we need to save it as the empty

string and we can handle this inside of the component so here's the here's the here's what we'll do we'll say uh um we'll need another prop here that's something like uh should clear if not visible um and that it defaults to false it's a long variable but it is clear as to what it is and so now inside of here um if should clear if not visible is true then we can have this effect that if visible is true then we save

it um otherwise we override it okay uh you can have I'm assuming you can have effects in conditionals I think because they are like compiler macros they're runes um I'm pretty sure I can do

this and so now back over here we pass in another prop on both the sck pics and the socials

um uh like that that's should defaulted prop without a value is just true

right all right moment of truth we click the button it's there we click this button it's there we go back it should have saved automatically and those should still be checked we need to save whether or not they're checked um so include socials should have an initial value that is uh if sick pick has a value

like that okay and I should be able to update it test test test test test test and now if I go back in go to the notes it has those updated values great and then we can include socials too why are we doing python variables uh they're not is that a python um is that a thing they do in the world of python um this is actually Scott's preference and I have really come around to it I mean the variables are longer but it is it actually it's so much easier to read than camel case yeah um I I keep missing uh twitch chats uh thank you uh bro thank you for that follow what's up C films good to see you weird decision to make a question mark dot instead of just question I don't yeah I think it has to do

something something with the part the JavaScript parser and syntax yeah it looks horrible so it's probably python come on come on um I like following whatever the design language rules are for that language yeah and in the uh the standard inside of rust is to use uh snake case

okay um we're closer now we have these areas that we can check now we need to include them in the actual markdown

um that gets uploaded to GitHub

so GitHub API uh well no this is going to happen on the publish page so the notes are there and then um if project. sipix is a thing yeah thank you AI That's beautiful so do two new lines yeah new line new line sick pics and then after that um if project. socials is a thing

um two new lines include the socials great uh yeah and then uh America 2050 is asking about the front matter and notes basically we are constructing one giant string that will be a markdown file uh that gets PR to GitHub so if you look at one of the most recent ones this is the the ult this ultimately this is the markdown that we're constructing yeah we're putting all the front matter up here we're putting all the notes and then socials and then if there were sick pics they would get included right here so if you haven't been following all the stuff I've been doing this this is the ultimate goal we had separate editors for each of these sections and then now finally when they click the make PR button it's going to smack them all together and then and then make the pr there and uh YouTube descriptions uh will only include these two sections

here and because of that I think our button already works the way we want it to like if we do uh copy as text that's only looking at the show notes it's not looking at socials and and Shameless plugs um so that gives us exactly what we want to paste into YouTube except for these extra new lines and I think I can just fix these on this Branch while we're here

um see I'm doing this weird text node thing where um joining it all together on new lines

what happens if we just grab element. text

content copy text nice think that's what we

want because if we add a

summary this then copy his

text uh um these aren't updating anymore that's not

good uh YouTube descriptions are not also marked down um it's just plain text which is why we have the copious text button which basically strips all the markdown formatting and just turns it into plain old text like this I think my save for notes is broken um copy as text paste go back go back in notes there's saved okay so the copy is text button has an old value and uh thank you sck now thank you for that follow welcome in okay so copy is text is using notes uh notes is

that the value here um

I guess do I want a state variable here I kind of want a like a computed value like always look at the latest value of project. notes is that what state is for or do they have some kind of uh yeah I think I want

derived um where where am I using this in here

here we render the notes we render the notes yeah I think I just want this to be derived inside of this component

we do run into this issue State referenced in its own scope will never

update do I make this

derived yeah oh yeah and Scott is mentioning about the snake case he has dyslexia and it helps him read the variable names better uh the Double exclamation mark is not not so s picks and socials are both strings but I want a booing that is true if the string is not empty so that's what the notnot does um all right now that I have these as derived will it work uh cannot bind to a derived state that makes sense and that's okay too like I don't I don't need those to update does I have like some special syntax on

it I think this is okay because I only want the initial

value um so we go back we go in here go to the notes hello this is updated we then copy as text and hope for the best yes okay uh it includes it I think the one issue is like it doesn't it's not including these new lines for some reason which is why I had that extra code earlier but I think it's better than a whole bunch of extra new lines and then updated again copy is text cool copy is HTML cool I think the copy as HTML needs to include um sick pick Shameless plugs and

socials um why not derive it because it's based on the checkbox I need to I need it to uh the initial value is whether or not it is it exists right um yeah you gotta watch the episode just to see the takes on break dancing um but after that I don't need it to bind to the underlying value yeah the main the main issue is um I need the checkbox to be able to change it maybe there's a better way to do that oh nice Scott you're going to a qualifier that's awesome and hey sck now um I'm doing good I'm doing good I mean I've been coding a while yeah this this has probably been my longest live stream on the syntax Channel we're really close though we're really close because uh I think the one thing I need to do is that that copy as HTML button um needs to uh

include the um sigpic and Sheamus plugs so let's get that

working so we have a copy HTML button um we're rendering notes um let's call this all notes and this is going to [Music] be a template string grab notes and then uh it's look at the this uh this AI um it's using some weird template syntax that's that's the wrong template syntax um and then if uh sip is a thing honestly it's the exact same logic as um

uh whenever we push to GitHub can I extract this into something that's

reusable right because this this logic right here I think I want to I think I want to say uh get combined notes

like this it will pass in the project and uh we'll go from there where do we put this I think just put this in utils uh is this a text util not really it's more of a project util

it combined

notes great and then we import

project okay we've done it we now have a reusable function um I can call it here

it's weird that it adds that um and then I can also call it

here and yeah we'll see you later P off thanks for hanging out like I said this has been a been a long stream so I understand understand if people got to go um data. project like

this and then we'll import this in don't like how my editor always adds that js on the end there good luck with the bugs thank you um and then really we just kind of have to wrap this in a

if which it should be but just in case all right moment of truth now if I copy as HTML it should include everything it should include the sick pics the stess plugs the social socials um and it does yeah so there's all that stuff down there there's this beautiful

I want to also test like what happens if I remove the socials and then say copy as HTML he got rid of the socials beautiful uh what happens if I say no Shameless plugs but we do want socials and then we copy as HTML that has the socials and no shame okay I I think we're good let me clean some stuff up and then we'll we'll PR this okay this this file is a is a hot mess after I've been doing all this um I guess this I guess it needs to be a state variable yeah yeah see you later David thank you thank you so much for tuning in and I it's super awesome that uh uh we're using your library um so if anyone didn't know this is the markdown editor library we're using it's called ink mde and David is actually the Creator so it's super awesome that they got to see me work on it and uh throw

random codes at it cool um all right can I kind of just like ignore this error disable State reference locally

and are we using notes

visible I think we are um because here here was the the issue that used to happen before I think I fixed this issue but if you go through and then just delete all of the show notes before the editor would disappear entirely because uh you didn't have any show notes now I don't know if when you would actually do that um but that's why I got got rid of the visibility variable there cuz I don't want that to actually hide um I guess I that that bug could happen here too though like if I clear this out no because it's still checked um OB is

HTML yeah oh it works great that's what I want to see all right I probably want to start a new project to make sure that that still works and also let's let's test the markdown um ah copy as markdown also needs to combine everything together um so let's fix that

let say that it is not undefined because this wouldn't be V visible if it was undefined okay and we're so we've we've seen the benefit of multiple refactorings today so this idea of combining the the notes the socials the the um sick pics into a single variable we do we're doing it in three different places so it made sense to extract it into that reusable function I think it's a perfectly fine abstraction right it just takes those three variables and smacks them together with new lines uh but now um this copy as markdown should include everything and it does great let's create a project completely from scratch and then we'll also test the PR flow make sure all of that is good and then call it a day

okay we've got our notes those are good let's say we do want to include this and this and we just say test test test and this is episode

9999 tests do not merge okay

okay so the copy copy I keep testing the copy I think the copy's good copy's cop's good at this point um there is an issue with publishing to GitHub or like creating the um the pool request so that actually could fail I'm not going to work on fixing that today cuz um I don't have the

time what just

happened publish page. what happened what happened in that

file oh we've got a syntax error um what happened in

here oh we're just missing a closing um closing back tick

okay all right our notes look good um let's go open on GitHub cool and there it is okay awesome all right this is good enough let me clean up and then I'll I'll make a PR um I'm going to look at each file one by one um and make sure all all the stuffs is good okay so this is our um markdown

editor do we actually use that value for

anything we don't I don't think this needs to be a state

variable because we're not I it really only needs to be that if we're like watching it for changes but we're not because it's happening inside of here I think this can be cleaned up by actually just removing the state variable

entirely and then we don't actually need the ink instance for anything so we're going to get rid of

this um oh we do we do we at least need to uh create create it like that but we don't need to store it in a

variable and this should be fine cuz when the component mounts it's going to grab the initial value and then every time after that it's going to be updating it um on state so it's always going to have the latest value and then if you go away and come back to this component it was saved so it always has the latest value let's just test that but that that should be how it how it works so like notes we can go back we can go in here yeah

yeah that works cool so that's that's nice and clean there's not like an extra variable there sweet that component looks great uh next up we have our project constants that looks fine too then we have the project I think the only change we made here was to add new properties to the project great and then we added this function get combined notes and then on the project page itself what did we do in here uh we changed what happened uh when we get the metadata from the file yeah we put the word show notes above the notes that's the main thing and then we don't need to add socials and sips because we're work that's what we're

working on right now great um and what did we do to this file we did a lot to this file let me try to clean up any unused variables or or even think about a way to use this um yeah this doesn't need to be derived that I think the what I want here is when the component loads these variables should be the value as they were when the component loaded so I just want it to be this I don't want it to be the derived value I want it to be the value when it loads and then it'll get changed from

there state. snapshot is what Scott says that's good to know

well it's not it's not a snapshot because the checkbox changes it um that's the main issue is I want I guess could I do a sck pick stot snapshot

I want State state. snapshot yeah but that's the issue is these are derived values they're not State values oh okay okay you all can't see I'm reading reading the chat so we're we're going deep please my dear State take a snapshot of those sick picks doesn't like

that snapshot will unate stuff well I mean I guess we have we have two like spelt experts in the chat like what is the issue with just leaving it like this because I mean the the is the error says uh State reference in its own scope will never update that's fine I don't want it to update I just want the initial value uh when this code runs and then after that my checkbox changes the value but that checkbox doesn't need to bind to any state um so poo says I can ignore it then is this is this a spelt error a linter error like we have the disable State referenced locally for this line but um yeah

okay that's fine then um front matter as well getting another um warning yeah and so it's to prevent you from thinking that it's going to create a derived value it's good to I mean I guess that's that's good because I I could see people trying to use it in that way um but I specifically don't want it to be a DED value okay um that looks

good what is the uh ink front matter instance being used for oh yeah like when the front matter is being updated that makes sense okay um oh look where it's adding these comments every time I did it it's adding them down here um that's so funny it was putting them in the wrong spot I want it oh I I can't oh I guess well yeah it's not it's not HTML it's

that is it

this h

it really is not ignoring it that's that's okay there um okay we can get rid of all this extra codes because we figured out just using the text content is completely fine when we copy text we're just copying for YouTube so we're only copying the notes I'm going to say copy I think I'm going to change the button to say copy notes as

text um and put it first because these two are copy all

I think that that's the workflow we're basically if you're copying it as HTML or markdown you actually want everything but if you're copying it as text you don't want the socials in uh s pic you just want the notes Here cool um this looks

good I want to say include socials include pick and Shameless

bugs yeah I'm not I'm not sure poo

um it looks like it's coming from spel

okay I think the one issue right now is we do technically have duplicate CSS because um the front matter editor still needs that CSS and it's being defined in here I'm going to have to leave that for now and then um we changed publish as well

okay I'm going to go ahead and P this this is this is like a bigger one I'm guessing Scott will probably want to review it maybe he can fix some of my mistakes with spell 5 uh but this is good enough for me um this fixes which

number number 33 and then also

um number

36 I just solved like four bugs wow okay I didn't I didn't think about it but this uh okay this yeah number yeah we did number 33 and we did number 34 and we did number

36 um editor I'll call this notes editor fixes

great we'll make a PR and we'll call it a day

that's she learn code says I'd call it a week um someone tell someone telling us like three days work you never saw three tickets in the same day it's true I think I they're all like they were all related basically just the editor didn't do the things that it needed to do right so um now we have a section with sick pics and Shameless plugs if we want it and we're also adding show notes before the time stamps um now the HTML button includes the socials as well because we combined everything together which was a bug in another area and then now um when you copy as text it doesn't have all those extra new lines yeah we did it we did it um

yeah I would say no that's it request review great

PR great that's four issues in one day um you sent me a reppel with the ignore working can you copy the ignore to see if it works sure uh where did you send that to

Discord Discord yeah pulling up Discord now just a second

SP ignore State reference locally oh wow look at that nice animation I mean I don't know if that's on purpose but the uh the little yellow

squiggly but yeah let's see

it could just be an issue with my editor yeah see it's not working uh we can

reload yeah do not know why it could be an issue with the spelt extension that I have running in vs

code okay great work everyone we got four issues closed today and uh is definitely because some of you helped along the way um yeah maybe it's a versioning issue maybe like a spel 5 thing running in vs code and uh nus thank you very much for the the follow missed that earlier um your code is way more organized than mine mine looks like a tornado that I have to clean um oh I see we could be on an older version of of spelt 5 yeah that's probably it yeah maybe next time before I do any more work we just update our dependencies make sure there's no breaking changes or anything like that all right I'm going to get out of here thank you so much everyone for tuning in and uh uh Clash of code earlier was super fun that was that was great to see everyone's Solutions and uh we got some work done it was today was definitely um had to write a lot of code to get the stuff done but we got there and it was a good time um so this has been episode three

Chapter 25 3:45:45

Thanks!

of SX bites I'll see you again next week at the same time uh where we'll keep working on some of those issues and we'll find some other uh coding problems to do and uh yeah yeah yeah yeah so I'll see you next time thanks for tuning in and stick around for the raid we're going to raid on Twitch and if you're over on uh youtube.tv syntax FM yeah so head over to Twitch if you want to join us in the raid um no stream thingy um yeah do you mean raid thingy but yeah thank you Stony Eagle thank you for tuning in thank you everybody for tuning in over there on Twitch I'll be live again next Thursday same time on this channel all right see you that's it that's all

[Music]

[Music]

[Music]

[Music]

[Music]

Quote it with credit and a link. Quoting Syntax