MongoDB explain command to show all execution plans

So the MongoDB courses are almost finished, and now both MongoDB for Developers and MongoDB for DBAs tracks are in the finals phase.

One of the questions is about indexes, where you’re given the list of indexes that exists for a collection, and an example of a query. The question is to identify which indexes could potentially be used for optimization for that query.

I had my ideas for the answer, but to be sure I wanted to create a sample collection, add indexes and view all execution plans. It is in fact doable, if you pass a parameter to the “explain()” command:

//these also worked in version 2.2:

The output will include a field called “allPlans”, which is an array of all possible combinations of indexes that could be used. Neat.

Holiday gift idea: DIY cupcakes made of fuzzy socks

Another quick and easy idea that’s great if you need to give gifts to a large group of people; give socks! Because who doesn’t love socks? And the love only increases with time, as shown on this highly scientific chart:

You will need:

  • Fuzzy socks (any socks will do, but I love super soft ones, also pastel or bright colors will look best). I got mine at Uniqlo – amazing quality and a steal at $10 for 2 pairs
  • Muffin paper cups/liners, fairly large in diameter, because you’ll need to fit socks into it. Holiday or other pretty patterns will work great, but plain white will be nice too. I got mine at the Container Store
  • Rubber bands, can be found at Staples
  • Pretty ribbon, I got mine at the Container Store
  • Mini pompoms or anything else of bright color that looks like cherry. I think lollipops in clear wrap will work well too. I got mini pompoms at the Paper Presentation store
  • Clear bags for treats, mine were from Target, I think any party supply store will have them

Steps to create the cupcakes:

  • Roll socks into a bundle starting from the toe
  • Put a rubber band around it, so it stays put
  • Adjust the middle layers into a cupcake shape
  • Carefully stuff the socks into the muffin liner
  • Tie a ribbon around your cupcake
  • Put the mini pompom or other decoration on top of your cupcake
  • Put it into the clear plastic back
  • Attach ribbons, tags or any other additional decoration if desired

Gift and impress the heck out of everyone! :)

Customized Wufoo forms inside a WordPress site

I’m a huge fan of Wufoo. They made the annoying form-building/validation/emailing of confirmation/reports super easy. Anyone can build a form in a matter of minutes and run with it! Their system also supports payment integration with Paypal, and even Stripe. So it’s a no-brainer: use Wufoo and save yourself a ton of time.

I had to build a form for friend’s website (running hosted WordPress), where users can order items without the actual shopping cart functionality. So I went ahead, setup the Wufoo forms, customized the fields and design, and embedded the form via Javascript. All seemed good.

However, the order process turned out to be actually very custom (and some of the requirements changed), and as much as I tried to bend this form within Wufoo to do what I needed, it just wasn’t enough: there were a lot of custom calculations with Javascript and that required re-building the form using the API. So I wanted to share some tips on customizing a Wufoo form within WordPress.

First, set up a new page template in WordPress as you normally do.

Then, create your form in Wufoo, so all the form and field information is captured and saved within the Wufoo system. You will be using the API to pull field names and such.

Next, in the Wufoo dashboard, click on “Code” link which will take you to the code manager screen. In the top right corner you’ll see the “API information” button, clicking on which will give you the API key. Copy it.

In your WordPress template, include links to the Wufoo CSS and Javascript files, which should look play australian pokies online like Online Pokies this:

<link href=“https://[your_account_name]
forms/css/index.XXX.css” rel="stylesheet">
<script src=“https://[your_account_name]

Wufoo API will give you form/field data as either XML or JSON, I prefer JSON and conveniently enough, PHP has encode_json() and decode_json() functions, which basically will do parsing for you.

Here’s a snippet of code that will get you form data, such as form name, ID, description:

// Get form data from the Wufoo API
$url = ‘https://[your_account_name]’;

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_USERPWD, ‘YOUR_API_KEY:footastic’);  
//keep ‘footastic’ - it’s actually what the API expects, hehe

$json = curl_exec($ch);

// Setting 2nd parameter to ‘true’ will create an assoc. array.  
// If you omit it - result will be returned as an object
$result = json_decode($json,true); 

// You can use this to check what results you’re getting

//now you’re ready to move through your array and get values
$form_name = $result["Forms"][0]["Name"];
$form_desc = $result["Forms"][0]["Description"];

To get fields, you will perform a similar operation:

//Get field data from the Wufoo API
$url = ‘https://[your_account_name][form_id]/fields.json’;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, ‘YOUR_API_KEY:footastic’);
$json = curl_exec($ch);
$result = json_decode($json,true);
$fields = $result['Fields'];

Now that you have fields, you can create your page output as you desire, add custom functionality, and don’t forget to test.

This seems like still coding a good chunk of functionality, right? Well, yes, but you don’t actually need to do validation, reporting, payment processing and such, so it’s still less that you normally would do, if you coded everything from scratch. Also, admins will be making updates right in the Wufoo dashboard, so they won’t be touching the code or asking you to change copy for fields. As long as they save their changes, they will be dynamically pulled into the form on WordPress.

Holiday hostess gift: Cookie Balls

Yes, you heard it right: cookie balls!

I have a funny story to tell first. It was my first year working at the agency, so during one of the client calls we were discussing an idea for a holiday app. It had to evolve around holiday sweets, and the client did not want to do cookies (because – duh, everyone does cookies!). One trend that just came out around that time was cake balls. But you know, cake making can be too time-consuming. So everyone started to throw around ideas, and lo and behold, someone blurted: “What about cookie balls?” And so the cookie balls were born!

It is now a real thing, where you crush cookies and glue them together into yummy goodness using cream cheese. The fun thing about them, you can make different flavors, colors and toppings, and it’s like a tenth of the effort compared to cake balls!

So here you go: cookie balls that make a great gift to bring along to holiday parties.

Step 1: Make cookie balls

  • Soften 1 package of low-fat cream cheese (or go full-fat if you so desire)
  • Crush Oreo cookies into crumbs, about 3 cups (actually you can use any cookies you like)
  • Mix crumbs with cream cheese and make 1 inch balls (don’t forget to wash your hands before you start rolling, haha)
  • Take 16oz of Baker’s semi-sweet chocolate and melt it in the microwave
  • Dip your cookie balls in chocolate carefully and put them to dry on parchment paper
  • Sprinkle some crushed walnuts, colored sprinkles, coconut flakes or anything else you like
  • Refrigerate until firm

Step 2: Just as important – presentation!

I’m a huge believer that presentation can make or break a gift. Funny enough, I just finished watching Weeds season 7, where Nancy makes the same discovery – that presentation is everything.

Anyways: get a nice round cookie tin and some mini-cupcake liners. Put your freshly made cookie balls into cupcake liners, and into the tin.

Now they are yummy AND beautiful. Gift proudly!

Holiday gift idea: DIY fridge magnets

It’s holiday time of the year… again!

And for some of us, it’s time to prepare gifts for big family parties. Gift giving is fun, but figuring out what to get can be stressful. Also, it’s always appreciated if you bring something made by hand, and I love crafts, so I try to find quick and easy DIY projects that can be put together in a few hours.

I want to share an idea from a couple of years ago, hope some find it useful!

Cute round fridge magnets

You will need:
– Clear plastic cabochons, 3/4-1 inch in diameter, see photo below (can be bought at Michaels)
– Round magnets, 1/2 inch in diameter (can be bought at Michaels)
– Strong clear glue
– Old magazines with colorful pages or fun patterned paper of your choice, see example below
– Hole puncher 3/4 inch (I’m not sure of the exact name) – see photo below
– Clear box for putting your magnets in, I used a small 2×2, below (can be bought at the Container store)

*The choice of magazine ad is here only to demonstrate the pretty pattern, nothing else

– Select paper (can be from old magazines like I had) with pretty colorful patterns
– Using the hole puncher make a bunch of round little circles
– Take cabochons and glue the round circles to the flat part, so that your pattern faces the cabochon surface
– Glue the round magnet to the bottom side of your magnet
– Let the glue set
– Put your magnets into a pretty clear box and add ribbon/wrap as desired

Super easy and fun gift to make, and you can be sure it will be used – because who doesn’t have stuff hanging on their fridges?

*Aren’t these cute and awesome?

If you think it’s too tiny to be gifted by itself, add a nice box of chocolates and/or a bottle of wine. Tada! High five to you who just did all the gifting and had fun!

Animal of the day: Whale shark

When I was visiting Mexico last year I learned that you could swim with whale sharks in summer and was immediately intrigued!

* Image from the National Geographic site

Its name sounds scary but the whale shark is the largest fish that eats only fish. Not only it is the largest fish but by far the largest non-mammal. How about that!

Here are some more fun facts about this big cutie:

  • Estimated life span: 70 – 100 years
  • Featured on the reverse side of the Phillippine 100 peso bill (didn’t know they had pesos)
  • It’s called “domino” in Mexico, “many stars” in Madagascar and “Papa shilling” in Kenya
  • Considered a deity and called “Sir Fish” in Vietnam

Source: Wikipedia

Real vs digital

I fear the day when the technology overlaps with our humanity.
The world will only have a generation of idiots – Albert Einstein

Last week I went to see the opera for the first time in my life. It was Verdi’s Aida and I loved every bit of it!

Then the next day at lunch we had a heated discussion about the future of technology (of course), and humans wearing Google glasses or a similar device that will allow us to receive information instantly and continuously, kind of like augmented reality that’s turned on all the time. You won’t even need to reach for your phone, it will just be displayed literally right in front of your eyes.

More and more things are becoming digital these days, and you can see ever leaving your room.

But then I thought, that all of those fancy technological gadgets still won’t replace things that are so human nature, like in-person interactions with friends, traveling, or live arts. Isn’t it amazing that operas that were written in 18th century still draw us in to see them live, art from centuries ago still inspires us, and no matter how much you Skype with your family overseas it doesn’t come close to flying over and spending time with them? And wouldn’t you rather go fishing/play basketball/drive a racecar for real than playing a similator video game?

I’m not sure where I’m going with this… let’s just all embrace our human-ness, choose to hang out with friends at a bar instead of Google hangouts, and go experience things in real world, outside of the digital screen.

WordPress: Exclude directory from URL rewrite with .htaccess

As you know, WordPress uses .htaccess to rewrite URLs so they become nice and SEO-friendly.

Sometimes though, you might want to use a directory within your web root that can be accessed directly.

To do this, open your .htaccess file and add a line right under the first RewriteRule instruction:

 RewriteCond %{REQUEST_URI} !^/(mydir|mydir/.*)$

Replace “mydir” with your actual directory name.

So your full .htaccess instruction set will look like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_URI} !^/(mydir|mydir/.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

Now you should be able to access that directory directly, like this:

Book: the Adventures of Little Onion (Chipollino)

Yesterday I was sick and was sitting in bed all day with my laptop, and somehow got carried away by this nostalgic wave for the books of my childhood.

Thanks to the power of the internet, today you can find things from many years in the past, collected and preserved by fellow admirers of the lost era of Soviet childhood captured in books.

One such book is by an Italian writer named Gianni Rodari, whose work was incredibly famous and loved in the USSR, but it seems like none of his work got any prominense in English-speaking world.

This book is called where the poor are oppressed by the rich and greedy. The story and its translation into Russian are wonderful, and another remarkable feature of this book were the illustrations. The characters of the story were drawn so well, and you can tell what kind of role each one is playing, whether they are rich or poor, kind or arrogant.

*The first cover is from 1955 – I had the exact same one. The next one is of Chipollino making Senior Tomato cry, because he’s an onion – get it? :) The third one is the cover for a later edition.

This is one of my favorites, and here’s the link to the full version (in Russian) with wonderful illustrations by Suteev.