Meditations on Writing a Queue, Part 2

Queue Pop
Now that we have data in our queue, we need a way to get data out of it. Introducing tiny_queue_pop
void *tiny_queue_pop(tiny_queue_t *queue) {
pthread_mutex_lock(&queue->mutex);
while(queue->head == NULL) { // block if buffer is empty
pthread_cond_wait(&queue->wakeup, &queue->mutex);
}

struct tiny_linked_list_t* current_head = queue->head;
void *data = current_head->data;
if(queue->head == queue->tail) {
queue->head = queue->tail = NULL;
}
else {
queue->head = queue->head->next;
}
free(current_head);
pthread_mutex_unlock(&queue->mutex);

return data;
}
This function takes a tiny_queue_t pointer as an argument and returns an untyped pointer (void *).

Link: https://dzone.com/articles/meditations-on-writing-a-queue-part-2?utm_medium=feed&utm_source=feedpress.me&utm_campaign=Feed%3A+dzone%2Fwebdev

Meditations on Writing a Queue, Part 1

What is a queue besides the line for the little teacups at Disney? In programming, a queue is a very useful data structure that can simplify our programs, especially when it comes to threading. In thsi series, I’m going to walk you through building a queue in C, talk about how to effectively use a queue, and also compare to the Queue implementation that ships with Ruby.
What Is a Queue?
While there are different types of queues, the most common is a FIFO (first in first out). The first person in line to ride Space Mountain is the first person who leaves the waiting area (and they also get the best seat).

Link: https://dzone.com/articles/meditations-on-writing-a-queue?utm_medium=feed&utm_source=feedpress.me&utm_campaign=Feed%3A+dzone%2Fwebdev

Debugging a Rails Server in Visual Studio Code

I have been using Visual Studio Code as my IDE while coding in Ruby as I didn’t want to fork out a load of money to purchase RubyMine (I hate spending money) and so far have been getting by without being able to debug my code. Now the only reason I haven’t needed to debug so far is that I am still learning Ruby on Rails and therefore the code I am writing isn’t exactly the most difficult to fix when something goes wrong. But I got stuck recently and it took me a long long time to figure out what was going wrong and started to wish that I had a debugger setup. Anyway, time for me to stop blabbing on and actually give you some information.
Setting it up is actually really easy, as some awesome people have made some plugins and gems for us to use.

Link: https://dzone.com/articles/debugging-a-rails-server-in-visual-studio-code?utm_medium=feed&utm_source=feedpress.me&utm_campaign=Feed%3A+dzone%2Fwebdev

When Do You Use Parentheses in Ruby?

So I am still reasonably new to Ruby and I have only been working on it at home and therefore have had no one review my code and comment on whether I am writing my code in the correct way. The only input I have is from code that I see online and the book I bought about Rails. Now, most things are pretty straight forward and being as I work as a developer I have a basis on what is readable and what is not which leaves most of my code looking good (in my opinion) but the one problem I have are parentheses. I have no clue when I can omit them and when they should be used and even looking through my book I couldn’t find consistency.
After searching the web it seems the area is a little blurry but pretty much comes down to if parentheses make it easier to read your code, then add them in, otherwise omit them. I tried to find some concrete answers that take this a bit further but every place I looked, everyone, seemed to have different preferences.

Link: https://dzone.com/articles/when-do-you-use-parentheses-in-ruby?utm_medium=feed&utm_source=feedpress.me&utm_campaign=Feed%3A+dzone%2Fwebdev

New & Upcoming Course Highlights: JavaScript, SQL, & Ruby

Every week, new courses and workshops are published to the growing Treehouse Library! Here’s a short list of what we’ve added recently, upcoming course highlights, and our weekly video update of What’s New at Treehouse. Start learning to code today…
The post New & Upcoming Course Highlights: JavaScript, SQL, & Ruby appeared first on Treehouse Blog.

Link: http://blog.teamtreehouse.com/new-upcoming-course-highlights-javascript-sql-ruby

5 Lessons I Learned From My Ruby on Rails Internship at Planet Argon

Five weeks flew by too quickly! Last Friday, our two interns from Epicodus had their last day with Planet Argon. During their time with our Rails development team, James and Tracie were able to work on real, live Rails applications. Along with building their technical programming skills, this internship allowed them to experience planning meetings, daily stand-ups, agile methodologies, and the tools agencies use to communicate every day. On his last day, James put together a list of five things he learned during his Rails internship with Planet Argon. Check them out!
1. Optimize the Speed of Your Rails App
Before interning at Planet Argon, I wrote apps that simply worked. Were they fast? Nope. To the naked eye they appear to be quick to load but scale it up and the whole thing slows down to a grinding halt. For you Rails programmers out there, use find_each instead of all, don’t ignore small things that might slow your app down (they start to stack up, trust me), and don’t be afraid to utilize your database to store data that would be quicker to retrieve than to re-evaluate, if appropriate.

Link: https://dzone.com/articles/5-lessons-i-learned-from-my-ruby-on-rails-internsh?utm_medium=feed&utm_source=feedpress.me&utm_campaign=Feed%3A+dzone%2Fwebdev

The Fastest Way to Generate a Heap Dump on Heroku

You’ve got an app with runaway memory use, what do you do hotshot? What do you do? If you’ve exhausted the usual suspects it might be time to take drastic steps. It might be time to take a production heap dump. I previously wrote about doing this on Heroku, but since then we’ve launched Heroku exec, a way to SSH into a live running Dyno to allow you to debug. Now that you can do that, you don’t need an AWS account or any fancy gems to generate a heap dump, just activate this feature and add the rbtrace gem to your app. Let’s do this to an app together.
First, we need to set up the app with Heroku Exec. Check the Heroku Exec docs as these steps may change in the future. We’re going to start by installing the plugin:

Link: https://dzone.com/articles/the-fastest-way-to-generate-a-heap-dump-on-heroku?utm_medium=feed&utm_source=feedpress.me&utm_campaign=Feed%3A+dzone%2Fwebdev

Python vs. Ruby: Which Is Best for Web Development?

Python and Ruby are among some of the most popular programming languages for developing websites, web-based apps, and web services. In many ways, the two languages have a lot in common. Visually they are quite similar, and both provide programmers with high-level, object-oriented coding, an interactive shell, standard libraries, and persistence support. However, Python and Ruby are worlds apart in their approach to solving problems because their syntax and philosophies vary greatly, primarily because of their respective histories.

Link: https://dzone.com/articles/python-vs-ruby-which-is-best-for-web-development?utm_medium=feed&utm_source=feedpress.me&utm_campaign=Feed%3A+dzone%2Fwebdev

A Variable by Any Other Name

Sometimes when you do everything right, things still go wrong. I previously talked about how bad I am at spelling and grammar in “The Four Year Typo,” which reminded me of my first major production failure at Heroku.
Here’s the setup. We have a service that builds apps. You don’t need to know this, but it’s called “codon.” This is the service that runs the buildpacks such as the one I currently maintain, the Heroku Ruby Buildpack. Believe it or not, when I started we had no production monitoring of build failures. If we so much as hiccup, Twitter tends to catch on fire and our support tickets come in like a tsunami, so there wasn’t a huge need. However, the faster we can find out about failures the faster we can fix them and fewer people get impacted. Also, when you’re deploying as many apps as we are, a one-in-a-million bug occurs a non-trivial number of times. So, we really have to be on top of things. One day I made a change to a buildpack that caused one of those one-in-a-million bugs to be exposed in Bundler, but because it wasn’t a major system meltdown, we didn’t really hear anything about it. While that is a bug, it’s not the one I’m writing about.

Link: https://dzone.com/articles/a-variable-by-any-other-name