RubyGuides
Share this post!

All posts by Jesus Castello

Troubleshooting with lsof

Lsof is a standard Linux utility that can help you troubleshoot a range of issues related to open files. If you run it without any options it will display ALL the open files in the system, which might be a bit overwhelming. Fortunately you can use the -p <pid> option to see all the files opened by a specific process. Another useful way to call lsof is by passing in a file name as argument, this way lsof will show you the process that has this file open.

Using lsof, an example

Have you ever been in a situation were you couldn't do something because you got a "Resource temporarily unavailable" error or something like that? Well this is the kind of thing lsof can help you with. Let's see an example: locked Read More

Sorting Java Collections

Java collections are most of the data structures that come with the language. They share the same basics methods thanks to the collection interface. One of the most common things you may want to do with a collection, besides adding and removing elements, is sorting them. Let's see an example with ArrayList Read More

Column formatting

Here is a quick tip on how to make the output of some tools prettier, for example we can use the mount command which by default looks like this:

Using the column command with the -t option we can apply some formatting so it is more readable:

Much better, isn’t it? Man page for the column command: http://man7.org/linux/man-pages/man1/column.1.html

PHP Arrays

This is an introduction to PHP arrays, so if you are new to the language or you just need a refresher you can get up to speed pretty fast. This is how we initialize an empty array and add some elements to it: Then we can see it's contents using the print_r() function. You may want to put this between <pre> tags for better formatting. Read More

SQLite Basics

SQLite is a serverless relational database. It is used notably by modern browsers like Chrome and Firefox to store data like history, cookies, saved passwords…

We are going to see how you can get around in the command line interface. To work with a database file you can start the program in this way:

What you get is a prompt similar to the mysql client. Now let’s see what tables are available:

If we want to see column names we can use the .schema command:

## Customize Output

To customize the output format of query results you can use the .mode and .headers options, for example:

You can add these options to .sqliterc for permanent effect. Finally, if you want to exit just type .exit

Something annoying about sqlite is that the ALTER TABLE command is very limited. You can only rename a table or add a column, but you can’t modify or delete columns after they have been created. There is an official work-around for this, explained here: https://www.sqlite.org/lang_altertable.html

Using SQLite in Ruby

You can use the SQLite3 gem: https://rubygems.org/gems/sqlite3

Summary

You learned some basic sqlite commands like tables, schema & headers.

Thanks for reading!

You might also like:

Redis: the blazing fast datastore

1 16 17 18 19 20 23