Eat. Sleep. Code: The Computer Programming Thread, Ver. 010

Not really. There’s serious syntactical and compliance differences.
There’s some info here:

You’ll find questions such as these cropping up all the time
"What are the differences between bsdtar and GNU tar?"

Then someone has to port gnutar onto OS X:

So you can get it, but if you fire up a command line and assume your script which runs in GNU will run on BSD, you’ll run into strange bugs all the time.

Ah yeah I forgot they use BSDtar. That’s a pretty glaring example, yeah, people use tar all the time.

I want to make a website using a MEAN stack with a front page with articles that get updated daily.

I would like the first 10 latest articles to be up by default, and if the user wants more they could click the “Load More” articles button, pretty much like the frontpage of this website.

To do this, I was going to write a script serverside that would check the dates the articles were written and order them by date. The filenames of the first 10 articles get spit out and an array with these names gets produced. This array is what the controller would load onto the view of the main page. When the user clicks on “Load More” the script spits out the next 10 filenames of the articles, and concatenates the first 10 names with the second 10 names and displays the 20 articles in the view on the index.html page. This continues as long as there are more articles to load.

I was wondering two things:

  1. What is the technical name of the functionality I am trying to implement? For example, I tried googling “make website with updating articles in AngularJS,” but it didn’t really give me a name for this.
  2. Is there a better way to do this? A way more native to AngularJS perhaps?

Are you asking what it’s called when someone clicks “Load More” and it does? The most common name for it is AJAX (Asynchronous JavaScript And XML), though it doesn’t really need to be XML. Basically you just need javascript for it, and it seems AngularJS can do it with JSON (See Here). Plain javascript can do it just fine too.

Seems like AngularJS is perfect for something like that, though I don’t know if theres a technical name for that functionality. The classic way is to have some sort of index marker, so you know how deep into your list you are. The server calculates all the articles ordered in date, and has it stored into memory (or in a database, able to be loaded, whatever the case may be), and then when you make the first call, it just returns the first 10. When you have the “Load More” menu option, you just pass to the call what set of indexes you want. So the first call you’d pass 0 (or 1, up to you), and then increment it by 1 for the next call. So the server says, “I actually want the next 10 articles” and it knows which 10 to pull out of its array.

In Angular, you can just get the results from the server back, and then append them to the array storing all the existing articles, and it should automatically insert them as soon as the data object binded to the display is updated.

The downside to this is that if the source object is updated (i.e. a new article is loaded and stored in the server), then when you retrieve the next set of 10, it may end up bringing back duplicate articles (i.e. article 10, loaded in the first load, is now stored as article 11, so it comes back when you click “Load More”), so solving for those sort of concurrency issues is a bit harder, though likely small in the grand scheme of things. Sites like reddit build their cache and then seem to store multiple caches over time, and identify which one the user is working on in the url request (Clicking next shows something like https://www.reddit.com/?count=25&after=t3_5uxq5e which means give me the next set of artciles starting after 25 depending on the timestamp encoded as t3_5uxq5e). If you ever dig too deep into reddit, you’ll notice you’ll get a blank front page, this is because the time that you started digging is no longer cached, so they have no idea how to show you the data for what you need to see.

If you look at shoryuken, for instance, it loads from a url like http://shoryuken.com/page/3/ where 3 indicates you want the 3rd set of 10 articles. Try putting some huge number, like 1000, and see its rebuilt as far back as 5 years ago.

And then, try putting negative numbers and see what happens. For some reason, it actually loads up “random” articles instead of a page listing, that’s pretty interesting lol

edit: It seems to search for articles based on your keyword after page and bring back the best matching one it can, so searching for shoryuken.com/page/test brings up “http://shoryuken.com/2016/02/17/test-street-fighter-vs-netplay-during-playstation-networks-free-multiplayer-weekend/

edit 2: It seems I took too much time to explain what you said you were already doing, so disregard lol

You don’t need to write a script to order the articles by date and that is a terrible idea. That should be part of the query that you do to retrieve the articles and the results should come back already sorted. Just grabbing all articles then sorting them by date in actual code and using the first 10 ones is a terrible idea. You want to run a query that just retrieves the last 10 articles sorted by most recent date.

What you are trying to do is just make a web request. There really isn’t a “special term” for it. You’re just making a web request from the browser that does “stuff” on the server. On the server is where you will have an endpoint that will then make a query to the database and return the results back to the client.

Considering you don’t really know these concepts yet, I wouldn’t even dig into AngularJS yet. That is like trying to run before you can even crawl. You are better off playing around with jQuery first and learning a lot of basics before considering Angular. You can do what you are trying to do very easily with just jQuery.

Yeah, you’re right. That is a terrible idea. I should just use MongoDB, store the filenames in a database along with the date, and then query the database for the first 10 items by date, feed that into the view, and let Angular take it from there.

Thank you purbeast.

Yeah that works. The speed of just querying the DB and ordering by date will be much more efficient than writing an algorithm on your server to do the same behavior, plus there is no maintenance to worry about. With 10 items you won’t notice much of a difference, but once that collection grows in size or you want to start getting more than 10 results, you would start to slowly notice performance differences.

Anyone else doing Advent of Code? I’m having a blast with it. Currently at day 7.

What’s that?

It’s an advent calendar where you get coding puzzles to solve every day, with varying levels of difficulty. It’s pretty neat regardless of your programming prowess, thus far we’ve seen everything between identifying infinite loops, confirming text input and creating fairly large data structures.

As someone who knows a bit of programming but wants to improve and get some challenges, it’s been a great time for me thus far.

Didn’t do the calendar but will start now, thanks for the link/info.
Was a bit bored & stuck at projecteuler anyway, first doors look interesting. : 3

Have any of you guys done some coding on matlab?

I have punched in some commands in MatLab, not really done more than that with it.

My University starts teaching math/nat-science-students Python from week 1, so MatLab kinda got downprioritized. The few times I’ve used it is when I’ve had off-key statistics courses and the teacher liked MatLab bettter than R.

Yea I’ve done too much Matlab.

Funny thing is I was hired at my current job to sometimes use Matlab, but since then, other people got hired and anytime a Matlab task was created, they’d do it instead.

Matlab makes good plots.
Meant to use R a handful of times this past year, because a co worker made an R script to make some plots.

I’ve also used sagemath and some other python plotting libs.

I second this. Half the time I’m using Matlab in order to make a plot too complex to be easily done in Excel. Plus I write the plot creation as a script so I have a record of what the hell I was doing and can easily feed it different data.

I just transferred to a 4 year in Electrical Engineering and I did C++ at my CC but now I’m thinking of taking a matlab class even though I can get it waived

The thing is, if you can write software, then you can program Matlab to automate plot making in a straight forward manner, after some basic fumbling around with interfaces and sometimes a lot of tweaking of minor details.

I’m not sure in the value in taking a “Matlab” class.
I’m rock solid sure of the value in taking a “Scientific visualization” class, that happens to use Matlab.

I took a course that involved programming in Matlab while I was in college and it was completely useless to the overall picture.

Really? I’m looking at future courses and some of the courses are gonna have us using matlab. IDK probably just gonna take it anyway