The Longest Email I Ever Sent (Programmatically)

It was a quiet day in July when I got a message from SendGrid about a service I run, CodeTriage, which helps people contribute to open source projects, had gone over its limits. Calls to send out emails were all failing. The fix was easy: bump up the limits by going to the Heroku dashboard, click “edit,” and adjust the plan. Previously I got notifications that I was almost out of credits for the service, but since it was SOOO close to the end of the month, I thought I could squeak by without having to upgrade. I was wrong. No biggie though, as soon as I upgraded my add-on emails started to flow again. It wasn’t until later that I got the bug report, while I was successfully sending out emails, they were MASSIVE. Some of the people who got them couldn’t even open the emails, they were causing the clients to crash. Before we can understand why we need to understand how the service sends out emails.
The service works by sending people links to open OSS issues in their inbox, or for Ruby apps links to methods that can be documented. It is an “email first” interface, and if emails aren’t working then the whole app is effectively down. The idea behind sending users open issues is that they can help “triage” them. Ask the reporter for specific version numbers, or for an app that reproduces the behavior. As such, when a core contributor to the project gets to that issue, there is less that needs to be done, the issue no longer needs triage and is ready to be worked on.

Link: https://dzone.com/articles/the-longest-email-i-ever-sent-programmatically?utm_medium=feed&utm_source=feedpress.me&utm_campaign=Feed%3A+dzone%2Fwebdev

Code Recipes Now on GitHub – 5,000+ Recipes for Python, Perl, Ruby and More

For more than a decade, ActiveState has hosted a vast repository of code recipes and discussions over at https://code.activestate.com/ – but in recent years it began to seem out-of-sync with the way developers shared code. New users and recipe updates had to be disabled to prevent spam and yet there remained a treasure-trove of interesting and useful pieces of code in this archive.
So, as the first phase of our ongoing effort to update and improve our community sites, we’ve migrated the entire library of code recipes (more than 5K recipes, 15K files and a mind-boggling >700K lines of code!) to GitHub. It’s become clear that GitHub is the central repository where developers share code, and to make it easier we’ve transferred all of the recipes, along with their descriptive text and original licensing terms to our new GitHub repo.

Link: https://dzone.com/articles/code-recipes-now-on-github-5000-recipes-for-python?utm_medium=feed&utm_source=feedpress.me&utm_campaign=Feed%3A+dzone%2Fwebdev

How to Write a Lock-Free Queue

Update: I did mention that lock free data structures are really hard to write, it looks like there might be some issues that haven’t been addressed in the implementation of this LF Queue that we’re referencing. The rest of the analysis is still valid and hopefully useful to you, just know there’s actually more that needs to be done, don’t try to use that code for a mission critical application out of the box.

It’s said that locks keep honest people honest. In programming, locks keep multi-threaded programs honest by ensuring only one thread can access a resource at a time. Why would we want to get rid of locks then? In this post, I’ll revisit the queue that I wrote in C and instead look at a “lockless” queue implementation. We’ll talk about atomicity and the tradeoffs when choosing one strategy or the other, and end with some ways to write “lock-free” Ruby code. Prepare to unlock your imagination!

Link: https://dzone.com/articles/how-to-write-a-lock-free-queue?utm_medium=feed&utm_source=feedpress.me&utm_campaign=Feed%3A+dzone%2Fwebdev

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