All posts by Pavel Chuchuva

About Pavel Chuchuva

I help coaches to deliver group programs.

How to View Large JSON Files on Windows

Let’s say you need to view a huge (more than 1 GB) JSON file. Of course you are not going to view so much data, it’s humanly impossible. What you want to do is to get a general understanding of JSON structure.

I assume that JSON document is already properly formatted.

First of all we will copy first 10,000 lines to a new file. We will user PowerShell for that:

Get-Content large.json -TotalCount 10000 | Out-File truncated.json

Next, open truncated.json in Sublime Text Editor and scroll to the end:
sublime-truncated-json

The JSON is not valid right now. Let’s make it valid by closing all ‘[‘ and ‘{‘ brackets. Sublime Text has a great feature that highlights invalid JSON code:
sublime-invalid-json-highlighted

All you need to do is to try to add brackets alternating between ‘[‘ and ‘{‘ until you reach the first column:
sublime-valid-json

Now you can save the file and open it in JSON Viewer. Since the new file is small you should have no problems viewing it as tree:
json-viewer

By the way, I’m thinking of building a tool that would automate this process – leave a comment if you’re interested in learning more.

Viewing JSON

From time to time I need to examine data in JSON format. Now unformatted JSON is very hard to read, for example:

{"movies":[{"id":"770739679","title":"Captain America: The First Avenger","year":2011,"mpaa_rating":"PG-13","runtime":121,"critics_consensus":"With plenty of pulpy action, a pleasantly...","release_dates":{"theater":"2011-07-22"},"ratings":{"critics_rating":"Fresh","critics_score":71,"audience_score":96},"synopsis":"Captain America: The First Avenger will focus on the early days...","posters":{"thumbnail":"http://content9.flixster.com/movie/11/15/83/11158339_tmb.jpg","profile":"http://content9.flixster.com/movie/11/15/83/11158339_tmb.jpg","detailed":"http://content9.flixster.com/movie/11/15/83/11158339_tmb.jpg","original":"http://content9.flixster.com/movie/11/15/83/11158339_tmb.jpg"},"abridged_cast":[{"name":"Chris Evans","characters":["Captain America/Steve Rogers","Steve Rogers / Captain America","Steve Rogers/Captain America"]},{"name":"Hayley Atwell","characters":["Peggy Carter"]},{"name":"Sebastian Stan","characters":["Bucky Barnes","James Buchanan \"Bucky\" Barnes"]},{"name":"Tommy Lee Jones","characters":["Colonel Chester Phillips"]},{"name":"Hugo Weaving","characters":["Johann Schmidt/Red Skull","Johann Schmidt/The Red Skull","Red Skull"]}],"alternate_ids":{"imdb":"0458339"}}

I usually use JSON Viewer to format JSON:

{
    "movies": [
        {
            "id": "770739679",
            "title": "Captain America: The First Avenger",
            "year": 2011,
            "mpaa_rating": "PG-13",
            "runtime": 121,
            "critics_consensus": "With plenty of pulpy action...",
            "release_dates": {
                "theater": "2011-07-22"
            },
            "ratings": {
                "critics_rating": "Fresh",
                "critics_score": 71,
                "audience_score": 96
            },
            "synopsis": "Captain America: The First Avenger will focus...",
            "posters": {
                "thumbnail": "http://content9.flixster.com/movie/11/15/83/11158339_tmb.jpg",
                "profile": "http://content9.flixster.com/movie/11/15/83/11158339_tmb.jpg",
                "detailed": "http://content9.flixster.com/movie/11/15/83/11158339_tmb.jpg",
                "original": "http://content9.flixster.com/movie/11/15/83/11158339_tmb.jpg"
            },
            "abridged_cast": [
                {
                    "name": "Chris Evans",
                    "characters": [
                        "Captain America/Steve Rogers",
                        "Steve Rogers / Captain America",
                        "Steve Rogers/Captain America"
                    ]
                },
                {
                    "name": "Hayley Atwell",
                    "characters": [
                        "Peggy Carter"
                    ]
                },
                {
                    "name": "Sebastian Stan",
                    "characters": [
                        "Bucky Barnes",
                        "James Buchanan \"Bucky\" Barnes"
                    ]
                },
                {
                    "name": "Tommy Lee Jones",
                    "characters": [
                        "Colonel Chester Phillips"
                    ]
                },
                {
                    "name": "Hugo Weaving",
                    "characters": [
                        "Johann Schmidt/Red Skull",
                        "Johann Schmidt/The Red Skull",
                        "Red Skull"
                    ]
                }
            ],
            "alternate_ids": {
                "imdb": "0458339"
            }
        }
    ]
}

Much better isn't it?

JSON Viewer is great because it also shows JSON in a tree:
JSON Viewer

Now I can easily expand and collapse elements and quickly understand the structure of the data.

However there is one problem: JSON Viewer doesn't handle large files well. If I try to open 4 MB file it just freezes for few minutes and I have to kill it with Process Explorer.

Do you have the same problem too? How would you like to see the problem solved? Please answer as a comment below.

My Fiasco with Creating Software that Saves Electricity

In September 2014 I decided to stop active development of Fotrel and create a new product instead. This time I wanted to build software in environmental area. I envisioned software that would help to make the Earth cleaner somehow.

I was inspired by Peachjar company. They built a software solution that helps environment by reducing amount of paper flyers that kids bring from school.

Some ideas that I have considered:

  • Software for marine biologists
  • Software that helps solar panel installers
  • Planning software for garden designers

I decided to build software that would help people to save electricity. Most of electricity is produced by coal power plants that pollute air and increase global warming.

Power plant in Belchatow

Following Lean Startup methodology I conducted a lot of client interviews. People were generally interested in saving electricity. The problem was that I wanted to create a software solution, without any hardware component.

Finally I settled on software that would monitor electricity usage by integrating with smart meters.

Also I decided to build my audience first. I have created a registration page. On that page I offered “5 Easy Tips to Save Electricity” report. People would have to enter their email address to receive it by email. This is how I would build my subscriber list of people interested in saving electricity.

I got few subscribers that way but not many. That page didn’t rank high in Google search and I couldn’t get others to share the link to my page with their list.

In April 2015 I have read an influential book “The 7 Day Startup” by Dan Norris. The main idea of the book is to launch new product or service very quickly to learn if it’s something that people would buy.

One idea from the book struck me: if you are building your first product it’s going to be very hard to create something unique and visionary. You can’t afford to be Steve Jobs, not yet. You have to wait until you launch one or two successful products.

As the first product idea it’s much better to stick to something that people already pay money for. That’s when I realized that people don’t spend money on saving electricity. So it’s going to be tough for me as a single developer to build something revolutionary in that area, something that would change people’s habit.

In the end I decided to give up on my idea. Surprisingly I experienced enormous sense of relief. I felt much better after making that decision.

Lesson learnt: make the cycle to test my ideas much shorter by launching new products very quickly. I highly recommend reading The 7 Day Startup book – it’s very short but powerful.

How I Did Not Make Thousands of Dollars by Creating Google Chrome Extension

Not long ago a friend of mine approached me with this idea: build a software that would export LinkedIn search results to Excel. Apparently many recruiters and sales people are using LinkedIn for prospecting – finding potential buyers and candidates. They can search but there is no easy way to export results to CRM that they are using.

At first I was hesitant. I thought that this software would essentially fill a hole in LinkedIn. At any point of time, I thought, LinkedIn would implement this missing piece of functionality and we will be out of business.

However, as it turns out LinkedIn has no intention to add exporting functionality because they have products that fill this need: LinkedIn Recruiter and Sales Navigator. They are very expensive, by the way.

Also, there is a company that has exactly this and they are doing good. My friend talked to some recruiters and all of them told him that they use that product to export search result to Excel.

At about same time I’ve read ‘7 Day Startup’ book by Dan Norris. It’s a fantastic book, short and inspiring. The main idea is to create a product or service very quickly and launch it to see if people would buy it. So I got very excited about this. Competitor product was quite expensive – about $20 per month. I thought I could whip up a solution very quickly and charge less. If people start buying it we could decide how to ramp it up.

My idea was to create a Google Chrome extension that would scrape search results from LinkedIn website. Users would perform search as usual on LinkedIn, then click a small button in toolbar and get results in a text box. Then they would copy and paste results to Excel and from there they’d be able to do whatever they want with them.

export

What’s great is that Google has a special store for Chrome extensions. They even take care of charging money. People can buy an extension using Google Wallet.

Google also makes it easy to offer a trial experience. My idea was to let people to export just 20 results and then ask them to buy the full version if they want all results.

So feeling enthusiastic about this thing I have created my first extension in just one week. I published it on the Google Chrome Store and set the price to $19. The next step was to drive some traffic to the listing page.

I decided to make a YouTube video with the title “How to export LinkedIn search results to Excel”. People that search for that phrase would watch the video, find my extension and give it a try.

And then I remembered that I wanted to check LinkedIn user agreement to see if I can get away with scraping their website. The agreement couldn’t be more clear:

8.2. Don’ts. You agree that you will not:

Scrape or copy profiles and information of others through any means (including crawlers, browser plugins and add-ons, and any other technology or manual work);

Wow! I realized that by publishing this video I would essentially teach people how to do something that breaks LinkedIn user agreement. I just couldn’t bring myself to do it. Also, even though I wouldn’t violate the agreement myself (I just provide a tool) people would violate it by using my tool.

So I decided to back out of this project. It just didn’t feel right to me. I’m glad I didn’t spend long time working on it. Also, at least now I know how to create Google Chrome extensions.

Lesson learned: check website’s user agreement before creating a tool that scrapes it.

My First Electricity Calculator

I have built my first online electricity calculator. It’s very simple and there are lots of similar calculators out there but it’s a start.

Behold: Electricity Calculator

Here’s how it works. Let’s say you are wondering how much it would cost to run a nightlight if you leave it on all the time. This nightlight has 0.2 watt LED, so you enter 0.2 as wattage.

nightlight

Next you enter 24 as the number of hours per day. Here in Australia we pay 30 cents per kilowatt-hour on average. The calculator gives you the result: the running cost would be $0.53 per year.

Electricity Calculator

Another example. We have 6 light bulbs in our kitchen. They are CFLs (of course) and 14 watt each.

light-bulb

So in total they use 6 * 14 = 84 watt. We have them on for about 3 hours per day. We pay 40 cents per kilowatt-hour. According to the calculator the kitchen lighting cost us $3.02 per month or $36.79 per year.

electricity-cost-lighting

Easy Targets for Saving Electricity

When it comes to saving electricity there are steps that are very easy to achieve. They don’t require a ton of effort. And best of all, they are free.

For example consider a situation: the light is on but there is nobody in the room. The electricity is essentially being wasted. The solution is easy: turn off the light whenever you leave the room.

It pays off to find where in your home the energy is being wasted. Here are some more examples:

  • Heating or cooling empty rooms.
  • Keeping your computer on all the time. Turn it off when not using. Or, better yet, configure it go to sleep automatically.
  • Filling the kettle too full. The water that you didn’t use gets cold again. The energy used to boil it is wasted.
  • A second fridge that is almost empty.

The nice thing about these changes is they would not make any noticeable negative impact on you or others.

How to Measure Your Electrical Use with Electric Meter

The first step to saving electricity is usually to determine what devices in your home use the most energy. If you know your top 5 energy guzzlers you would know what changes will make the biggest difference.

The easiest way to do it is to use a plug-in power meter, similar to Kill-A-Watt.

kill-a-watt

Sometimes though it is not possible to use it. The device could be located in the hard to reach spot (e.g. whole house air conditioner). Or maybe you don’t have the meter handy.

What you can do in this case is to use your electricity meter, the one that counts how many kilowatt-hours you have used.

Recently I decided to measure how much electricity does our electric oven use. I suspect that it uses the most of the energy on weekends (that’s when my wife cooks).

electricity-daily-usage-chart

I guess the oven is hard wired – I couldn’t find the socket for it in any case.

Here is our meter on the side of our house:

electricity-meter

As you can see it is a smart meter. I live in Melbourne and we are lucky to get smart meters before the rest of Australia. The meter knows exactly how much energy our household is using right now but unfortunately it wouldn’t tell. All it shows is the total consumption so far and the current date and time.

However our meter has a little red blinking light. The more electricity we use, the more often it blinks. This is similar to the old meters with a spinning disk.

In fact there are two lights on our meter. According to the plate on the meter it turns the left LED lamp on or off every time 1 watt-hour is used. The right light is for var-hours.

So here is the plan:

  1. Calculate how much electricity our home is using with the oven off.
  2. Turn the oven on and calculate again.
  3. Subtract the first figure from the second figure. This will be how much electricity our oven use.

First, I counted beats with the oven off:

It was 4 beats in 38 seconds. This equals to 1 beat every 10 seconds on average. So every 10 seconds one watt-hour was used. Using this formula


watts = watt-hours / hours = watt-hours / (seconds / 3600 ) = watt-hours * 3600 / seconds

… we can calculate that this equals to 379 watts. Cool, we are using less than half kilowatt-hour per hour when the oven is off.

Next, I turned the oven on. I set the temperature to 200°C and the mode to ‘fan forced’. This time, I counted 32 beats in 20 seconds – this equals to 5,760 watts:

So based on that, our electric oven uses 5,381 watts or 5.381 kilowatt-hours per hour. At the moment we pay 40 cents per kilowatt-hour. So if we use our oven for 1 hour every day is would cost us $65 per month.

If you have an old analog electric meter you would count disc revolutions instead of blinks. Michael Bluejay has a great set of instructions and a calculator on his website that can help you.

How to Configure Windows 7 to Put Your Computer to Sleep Automatically

I used to leave my computer on all the time – just so that I don’t have to wait for it to start. Then, I upgraded my computer. As part of the upgrade I switched from Windows XP to Windows 7. What I noticed is now my computer goes to sleep automatically when I don’t use it. I think this is great for saving electricity.

Here is how to make sure that Windows 7 puts your computer to sleep automatically.

Click Start button, open Control Panel.
start-menu

Open ‘Hardware and Sound’ category.
control-panel

Open ‘Power Options’.
hardware

Click ‘Change when the computer sleeps’.
power-options

Set ‘Put the computer to sleep’ to 20 minutes.
plan-settings

The default is 30 minutes which is reasonable; 20 minutes is even better. Click Save Settings. Now if you don’t use your computer for 20 minutes it will go to sleep automatically.

While you there click ‘Choose what the power button does’ …
power-options-power-button

… and select ‘Sleep’ option.
power-button

I like to be able to quickly put my computer to sleep when I know that I finished for today. Also, when my kids were small they liked to press the power button just to see what will happen. Usually this resulted in Windows starting to shut down the computer and closing half of the programs before getting to some editor that would ask if I want to save the document before closing it.

The computer uses very little energy in sleep mode but starts up very quickly and in exactly the same state as you leave it. Another cool benefit is that you can wake it up by pressing any key or clicking the mouse. Keep in mind that you still need to shut down your computer if you want to unplug it. If your desktop computer loses power while it is in the sleep mode it would reset its state: all open programs and documents would be abruptly closed. This is why it’s a good idea to save your work when you step away from your computer – just in case of power outage.

See also: Sustainable Computing: Sleep or Hibernate?

Front Page with a Big Image in WordPress

I’m going to continue with setting up my photography website using WordPress and Twenty Twelve theme (see the first post in the series).

As a reminder, this is how the home page should look like:
Home page mockup

By default, WordPress shows latest blog posts on the home page of your site. Here is how to make it to show a single page instead. First, go to WordPress dashboard and click ‘Pages’ in menu on the left:
wordpress-pages-menu

Then, click ‘Add New’ link:
add-new-page-link

Enter ‘Home’ as a title and leave /home as a permalink:
add-new-page

Select ‘Front Page Template’ in page attributes section on the right. Otherwise you will get a sidebar on this page.
page-template

Click ‘Publish’ button. The page is ready, now it’s time to make it the home page. Go to Settings, then Reading:
reading-settings

Change ‘Front page displays’ setting to a static page and select ‘Home’ as front page:
wordpress-front-page

Here’s the result:
front-page-no-image

Our home page is almost ready. Now it’s time to add a big image to it. Go to Pages, then All Pages and click Edit link for the Home page:
all-pages

Click ‘Add Media’ button:
add-media

Switch to Upload tab and select your file. The optimal image width for Twenty Twelve theme is 960 pixels. However you can upload a bigger image – WordPress will resize it automatically. The height doesn’t matter but I like image proportions to be close to the golden ratio.

Once upload is finished set the ‘Link To’ to None and Size to ‘Full Size’ under attachment display settings:
attachment-display-settings

Click ‘Insert into page’ button. The image is in the post but WordPress helpfully made it fit its default column size (625 pixels). Switch to Text tab and remove width and height attributes from the img tag:
img-width-height

Now set template to ‘Full-width Page Template, No Sidebar’ and click Update button.

Voilà, home page in WordPress with a full-width image:
home-page-with-full-width-image

You can view result live: Acme Photography.

How to Set Up a Photography Website Using WordPress

Let’s say I’m a professional photographer and I need a new website. The best thing to do generally is to ask someone else to do it. But what if I’m just starting out and don’t have money to spend on a fancy website? I can get a basic website for free using WordPress.

First of all, I’m going to create a mockup of my new website:

Home page mockup

Home page should have a nice big image, a heading and a menu bar. The gallery page should have thumbnails. Visitor should be able to click on any thumbnail to view a bigger photo. Something like this:

Gallery page mockup

Looks good! Next, I need to decide where I’m going to host my website. WordPress.com looks like a good option: it’s free (as long as your website address ends with .wordpress.com) and it is maintained by the same people that make WordPress.

Go to www.wordpress.com and sign up for a new account.

Creating new website at WordPress.com

The address of my website is going to be acmephotography.wordpress.com

Sign up form at WordPress.com

This is how my brand new website looks like:

Brand new WordPress website

Not very close to the mockup, isn’t it? Let’s fix it.

The next step is to choose a theme for my website. The problem with WordPress themes is that there are just too many of them. After some poking around I decided to try Twenty Twelve theme by the WordPress team. It looks nice and crisp. It has a menu on top. Also, it’s free! Here’s how to set it up.

Go to ‘My Blog’ on WordPress.com and click ‘Dashboard’ link there.

My blog - with Dashboard link

Move mouse over ‘Appearances’ link in the menu on left, then select ‘Themes’:

wordpress-themes-menu

Search for ‘Twenty Twelve’ theme and click Activate button:

Activating WordPress theme

Close the dialog confirming that the theme has been activated. Go to Settings, then General. Set site title to ‘Acme Photography’. Remove tagline (set it to empty):

General settings in WordPress

Don’t forget to click ‘Save Changes’ button. Now click on website name on the top left to view your website.

View website link in WordPress dashboard

Behold: my new photography website, Acme Photography:

Website with Twenty Twelve WordPress template

It has a title and a menu bar. However the front page doesn’t look right yet. I explain how to configure front page in my next post.