PostgreSQL – random notes

  • the default schema (when you create a database) is: public
  • everything created is put into public  unless changing the search_path of the database
  • every database has two catalogs, the usual information_schema, and pg_catalog, which has postgres-own schema information
  • extensions are add-ons.
Advertisements

Sometimes you pay more for a level of maturity

In the recent months I have paid attention to the soft skills of a set of people I often interact with (at work, the library group, and the place where I volunteer)

These are my observations of the value (paycheck) I estimate different people get based on soft skills: maturity is a top soft skill

  • What maturity gets you?
    • knowledge of when/how to act on new information
    • better understanding of priorities
    • be more thoughtful of all aspects of completing a task (such as, does it fully work? did I consider all possible scenarios?)
  • What other soft skills you already screen for?
    • In most teams, even in a library group, you likely already screened for a minimum acceptable of soft skills
    • The screening likely included communication skills, certain achievements, and a team fit
    • Likely you gotta pay extra for the mature-level person
  • What soft skills can your team develop over time?
    • Focus
    • Knowledge of other’s strengths and weak points
  • Plan for action
    • Observe soft skills of other people in the different teams you belong to

List of movies

Watch when available in DVD

  • Annihilation

Random list of movies that I have watched

  • A Girl Like Her (high-school flick)
  • Admission (romantic comedy; Tina Fey)
  • Adore (romantic mess)
  • After.Life (suspense; Christina Ricci; and the young dude from the cool-guy/old-guy mac commercial, he’s bad at acting)
  • The Age of Adaline (romantic flick)
  • All Relative (b-rated romantic comedy)
  • Aloha (b-rated romantic comedy; Emma Stone)
  • American Honey (crazy teenagers)
  • Andron (b-rated scifi; skip it)
  • Anesthesia (crazy teenagers; skip it)
  • Already Tomorrow in Hong Kong (b-rated romantic comedy; skip it)
  • Ask Me Anything (b-rated teen flick)
  • At Middleton (b-rated romantic comedy; skip it)
  • Before I Go To Sleep (thriller; skip it)
  • Dirty grandpa (it delivers; Robert De Niro)
  • The Duff (high-school comedy)
  • The East (highly recommended)
  • The Fifth Wave (skip it if you are a parent). The audio-book is quite good for commute because it is engaging but it does not distract you from driving
  • Get a Job (entertaining after-college flick)
  • The Gift (b-rated suspense; skip it)
  • Ginger & Rosa (b-rated drama; skip it)
  • Gone Girl (thriller; Rosamund Pike)
  • Good People (b-rated thriller; skip it)
  • Instructions Not Included (skip it if you are a parent)
  • I Smile Back (messed up film, skip it; Sarah Silverman)
  • The Impossible (Drama; skip it)
  • Jackie (Drama, skip it; Natalie Portman)
  • Jake Squared (Drama/comedy; skip it)
  • Jenny’s Wedding (romantic drama; Katherine Heigl; highly recommended)
  • Kingsman. The secret service (action)
  • Labor Day (b-rated drama; Kate Winslet)
  • Life As We Know It (romantic drama with baby included; Katherine Heigl)
  • The Loft (b-rated; bachelors trouble about dead girl)
  • Men Women & Children (b-rated romantic comedy; Adam Sandler; Judy Greer)
  • Miss Meadows (skip it)
  • Muriel’s wedding (b-rated romantic comedy; Toni Collette)
  • Noah (it delivers)
  • Non Stop (action; Liam Neeson)
  • Solo Con Tu Pareja (indy romantic fun flick; in spanish; highly recommended)
  • Transformers. Age of extinction (it delivers)
  • Two Night Stand (good enough romantic comedy)
  • The way way back (b-rated kids summer break; Toni Collette plays secondary role)
  • The road within (b-rated troubled high-school kids; skip it)
  • Walk With Me (documentary; skip it)
  • Wild (camping; skip it)
  • You’re the worst (tv-series; skip it)

 

Recipe: Egg fried rice

Ingredients:

  • 2 eggs
  • 1 green onion
  • 1/2 tbsp olive oil
  • 1 bowl cooked brown rice

Wash the green onion; chop it into 1/2 cm. long bits. Beat the eggs lightly, add the onion to eggs, mix them and add a pinch of salt. Cook the egg on a nonstick pan at medium/high flame with oil. Fry the eggs similar to scramble eggs. Add 1 bowl of cooked white rice (about the same amount as it was of eggs)

Button for getting a PDF back (Zend/PHP)

When using PHP with Zend, the requests for having a button that creates a PDF are like a train that’s never late. Often there are two cases:

  1. Easy: The PDF is created on the backed and stored there. Just pick your favorite PDF library (I use tcpdf). Then the file can be saved on the server, and you can keep track of it by creating a database table for it. For the purpose of downloading it, just make a route (and action) on Zend that handles the request, normally by ID.
  2. Easier but with a catch. The PDF is created every time and not stored on the server. Once that you verify that the PDF object was created, TCPDF has an output method that makes the response for you. The catch is that on the controller you need to set the return view model to terminal (via setTerminal(true)), and directly get out of the controller’s action via return $this->getResponse(); Otherwise, the PDF will contain (after EOF) some HTML, which is not clean, and it could trigger errors (such as unable to find the phtml for the action).

For option 1, consider having a separate class for handling the PDF files together with their corresponding database table, because, if later you have other sections that will make PDFs, you would not want to be repeating such code again and again.

Please upload this excel file to the database

An occasional request to a website I maintain at a non-for-profit organization is to upload records to a MySQL database. The data is given to me as an attachment in an Excel file. These are the steps that get the task done in the fastest time.

  1. Make sure that I get the file to my Gmail account (either directly, or I just forward it from my .edu email to my personal Gmail).
  2. Click on the attachment (in Gmail), not the download, but the “Edit with Google Sheets” button.
  3. As needed, “fix” data, such as date values, and remove formatting (if any).
    1. Arrange the columns to match those of the table into which you want to load the records to.
  4. Download (from Google Sheets) as tab-separated values. “File” -> “Download as” -> “Tab-separated values (.tsv, current sheet)”
    • The benefits are:
      • not having to open Excel locally at all (or OpenOffice, LibreOffice)
      • not having to deal with windows/unix line endings upon exporting from your favorite (local) spreadsheet
  5. Open the terminal (ideally OSX, or Linux, but cywin gets the job done too under Windows).
  6. Get rid of the first line, which usually is the header line.
  7. “Copy” the file to the linux box where MySQL is located (such as via scp, or sftp).
  8. Login to the linux box where MySQL is located.
  9. Backup the database (and copy the backup to another linux box before the next step)
  10. Login to MySQL, and use the command LOAD DATA INFILE to load the data
    • Example: Load data infile ‘/tmp/strains.txt’ into table strains;
    • Pay attention to the message indicating how many records were inserted. It should match the number of records that you expected to insert.
    • Pay attention to the other messages such as “Warnings”. When “Warnings” is not a zero, then do a command: “Show warnings;” to help you identify what the problem was. It could be that lines are truncated because the field in the table was too small, or that you don’t have a value in a column that does not accept nulls.
  11. Check your data. Then tell your boss (or yourself) that the task is “done”.
  12. Disadvantages of this approach:
    • Your google-sheets will be cluttered with the opened excel files. (Not easy to get rid of those things, I’ve tried and just decided not to bother; if needed, just rename the file to something that starts with “z_useless_” so that it is listed alphabetically at the end, and you can remember that you don’t need it).
    • You may have to read the additional options of the LOAD DATA command, when you have columns that have values that depend on other fields. However, MySQL is quite powerful, with functions for strings, and simple arithmetic.