SSL is based on the mathematical intractability of resolving a large integer into its also-large prime factors. Using this, we can encrypt information using what’s called a “private-public key pair”. Certificate authorities can issue SSL certificates that verify the authenticity of such a secured connection, and on the same note, a self-signed certificate can be produced without third-party support. By the end of the tutorial, you will have a web server accessible via HTTPS using a self-signed certificate.
Basic I/O in Ruby
The built-in gets
function simply reads a line and returns it as a string. The chomp
method from class String trims the line terminator. The prompts are generated with ordinary prints lacking a final newline.
# Get the parts of speech print "Please enter a past-tense verb: " verb = gets.chomp print "Please enter a noun: " noun = gets.chomp print "Please enter a proper noun: " prop_noun = gets.chomp print "Please enter a an adverb: " adv = gets.chomp # Make the sentence. print "#{prop_noun} got a #{noun} and\n#{verb} #{adv} around the block.\n"
Similarly, the to_f
method of class String converts the input string to a floating-point number.
print "Triangle height: " h = gets.to_f; print "Triangle width: " w = gets.to_f; area = 0.5*h*w print "Triangle height ", h, " width ", w, " has area ", area, "\n"
Play Background Audio on your WordPress website
Sometimes it is nice to low ambient sound effects in the background of your website, to set a mood or for some other purpose. There are plenty of websites where you can download such files, or you can make your own. It’s best to go for something that seamlessy loops and is not to distracting to the user.
Line Breaking with Ruby
Ruby generally uses line breaks instead of semicolons to separate statements. Lines can be continued by using a \ at the end, but this is rarely needed. If the line ends with pretty much anything that suggests there should be more, Ruby will continue on to the next line. This includes such things as ending with an operator, or inside parentheses or something else which needs to be closed.
The PDF Toolkit
Creating and reading PDF files in Linux is easy, but manipulating existing PDF files is a little trickier. Countless applications enable you to fiddle with PDFs, but it’s hard to find a single application that does everything. The PDF Toolkit (pdftk) claims to be that all-in-one solution. It’s the closest thing to Adobe Acrobat that we’ve found for Linux.
Ruby Hashes
Ruby hashes are similar to maps or dictionaries in other languages. They are essentially arrays whose subscripts are not limited to integer values. You can create them with the curly-bracked list notation shown below, but you can also assign to a subscript expression to add members. It’s not at all unreasonable to create a hash with empty brackets, then add members using subscripting.
How to Create a List of Forbidden Words for WordPress Titles
If you manage a multi-author blog and want authors to avoid using certain words or phrases, then this will come in handy. If an author has publishing rights, then the unwanted words can go live on your website. You can prevent this by taking away publishing privileges from users, but this means more work for you as you will have to review and publish posts yourself. So in this tutorial, we will show you how to create a list of forbidden words for WordPress titles.
Display Random Posts in WordPress
This method requires you to add code to your WordPress theme files, so exercise caution. Continue reading “
Arrays in Ruby
How to Include Category and Subcategory in WordPress URLs
WordPress comes with two built-in taxonomies to sort your content. They are called categories and tags.
As you probably know, categories are typically used for more broader topics and can have subcategories. However, if you are using the default WordPress URL structure, then your categories and subcategories are not included in the post URLs by default.