browse by category or date

Since my last post, I’ve been adding new features to JSON Table Editor. Here are the enhancements:

  1. Button labels and tool-tips.
    As I carefully observe the page, I asked myself whether the user interface is intuitive enough. From there, I changed some of the button labels with a clearer text. I also added additional information whenever user hover above certain controls. Hopefully this will make the UI less confusing.

    On the sub-level, the “Output to JSON” button is changed to “Finish Editing”.

  2. Instantly load remote JSON/CSV file.
    Not sure why I never think of this feature before. Now we can make the editor to automatically load a remote JSON/CSV file by passing parameters.
    Example:

  3. URL Shortener.
    The URL described in point no. 2 will be very long. Sharing this long URL is definitely look ugly. Thus, I added option to shorten the URL whenever a remote JSON/CSV fis is successfully loaded.

     

  4. Upload to Paste Sites
    A long time ago, a user complained why he can’t save the JSON output to other online storage like Google Docs/Spreadsheet. Since I don’t think a JSON file will fit nicely to a Google Spreadsheet, I decided to look other alternatives on storing text online. After short research, I picked Hastebin, Pastebin and DPaste as the upload destination. Purely due to the easiness to use their API.

That’s all guys. Looking forward to your feature request, bug reports! Cheers!

About Hardono

Hi, I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 9 years.

Five years ago, I created JSON Table Editor. Recently I have the time to revisit the project and do some minor bug fixes and enhancements.

  1. Array editing.
    In previous version, loading an array of string will give you a table of characters. This is embarrassingly wrong.

    The updated version has no more of this problem.

  2. Improvements on multi-level object editing.
    I changed the button title from ‘Save to Upper Level’ to ‘Finish Editing’, which is more appropriate. I also make the window closed when you click ‘Finish Editing’ button. I also show the updated JSON so we can notice the changes.

    The changes also propagated all the way to the top. In previous version, on each child-window we need to click the ‘Save to Upper Level’ button.

  3. Limiting the proxy
    The proxy in the previous version is just a dumb proxy. It fetches any url requested and dump whatever content. I see a potential misuse here. So I limit the proxy to only fetch JSON, CSV and raw/text content.

    <?php
    	$qUrl = $_REQUEST["q"];
    	// create a new cURL resource
    	$ch = curl_init();
    	// set the URL
    	curl_setopt($ch, CURLOPT_URL, $qUrl);
    	// get only the Head
    	curl_setopt($ch, CURLOPT_NOBODY, true);
    	// curl_exec return value instead of directly to out
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    	// do the request
    	$res = curl_exec($ch);
    	// check the content type
    	$contentType = curl_getinfo ($ch, CURLINFO_CONTENT_TYPE);
    	//only accept json, csv
    	curl_close($ch);
    	
    	//error_log($contentType);
    	
    	if (strpos($contentType,'/json')!== false || strpos($contentType, '/csv')!== false || strpos($contentType, 'text/plain')!== false)
    	{
    		// ... SNIP ...
    		// Normal CURL processing
    	}
    	else {
    		//error_log('Not JSON');
    		echo "Invalid resource. We only retrieve JSON/CSV/text resource. The requested URL returned ".$contentType;
    	}
    ?>
    
  4. That’s all, folks! Looking forward to hear your thoughts. Cheers!

About Hardono

Hi, I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 9 years.

I first encountered this problem last Saturday. I made small modification to my blog’s theme, but I couldn’t see the changes. I want to change the display of posts with certain category. Here’s the change in index.php

<h1>
	<?php if (has_category('tweet')) { 
		the_title(); 
	} 
	else { ?>
		<a href="<?php the_permalink()?>" rel="bookmark" title="Permalink to: <?php the_title_attribute();?>">
			<?php the_title();?>
		</a>
	<?php } ?>
</h1>

So if the post has category ‘tweet’, the title will be just a text, not a link to single.php. But this simple change simply never appears. These are the steps I took in my quest to clear the PHP/Wordpress cache.

  1. W3 Total Cache’s Purge All caches.

    This blog is using W3 Total Cache plugin. This plugin provide 1-click to clear all the caches. Unfortunately, I still can’t see the changes after clicking the ‘Purge All Caches’ link. [ FAILED ]

  2. Restart Web Server
    One of the recommendation to clear the cache is by restarting the webserver. Since this blog is using Nginx, I run the following command.

     service nginx restart
    

    Again, this step also unable to clear the cache. [ FAILED ]

  3. Restart PHP Service
    Another recommendation is by reloading the PHP service. Since I didn’t know which service to restart, I run the following to list all services.

     service --status-all
    


    Then I restart/reload the PHP service.

     service php7.0-fpm reload
    

    Blast! This step is still unable to clear the cache [ FAILED ]

  4. Reset OpCache
    I also saw recommendation on how to clear PHP’s caching mechanism. I created flush.php in my web root.

    <?php
       opcache_reset();
    ?>
    

    Then I open the URL (https://sodeve.net/flush.php) in my browser, continued with opening this blog in a new tab. Alas! I still can’t see the changes.

  5. Desperate Actions
    Desperate because of the continuing failure, I tried some other steps like rebooting the web server

     shutdown -r now
    

    I also deactivated the W3 Total Cache plugin. All proven to be fruitless. [ FAILED ]

  6. Finally
    On my final attempt before giving up, I created info.php

    <?php
       //Delete the file after usage!!!
       phpinfo();
    ?>
    

    I open the page in my browser, then hit Ctrl+F and typed ‘cache’. After lots of F3s, I found this line:

    This could be the key! I checked the folder listed in opcache.file_cache, I found a folder with a random-generated name. I deleted that folder and Voila! My changes is now shown [ SUCCESS ]

Lesson Learned

If I make changes to WordPress blog content, I need to flush the cache using W3 Total Cache’s Purge All Caches. But if I make changes to the blog’s source code (php files), I need to delete the folder inside opcache.file_cache.

That’s all folks! I hope it helps. Cheers!

About Hardono

Hi, I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 9 years.

Today I encountered a strange problem when debugging our company’s Ionic Android web app. Inside chrome://inspect tab, I clicked the inspect link for the app.

The pop-up window was totally blank. Puzzled, I clicked the blank window and press Ctrl+Shift+I to inspect the blank Inspect window (Inspect-ception, if I may πŸ˜€ ). And voila, the errors revealed:

inspector.js:8635 Uncaught TypeError: InspectorFrontendHost.setOpenNewWindowForPopups is not a function at Main.BackendSettingsSync._updateAutoAttach (inspector.js:8635)
at new Main.BackendSettingsSync (inspector.js:8633)
at Main.Main._createAppUI (inspector.js:8577)
at Main.Main._gotPreferences (inspector.js:8567)
at DevToolsAPIImpl.embedderMessageAck (devtools_compatibility.js:33)
at <anonymous>:1:13

When I googled the error message, the first result was this forum post which was posted 5 days ago (8th March 2018). Skimming through the comments, it seems the problem will be fixed by updating Chrome. True enough, when I go to Help -> About Chrome menu, it asking me to update.

After the download completed, click the RELAUNCH button to restart Chrome.

SOLVED!!!

About Hardono

Hi, I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 9 years.

The past few days I have been scratching my head due to this seemingly simple problem. I can’t change the order of the pages in my Visio document.

Everytime I tried to drag the tab and change the order, it simply refused as shown above.

Today, I finally found out the cause. I need to change the Page Type from Backgroundto Foreground.

Once I did change to all pages, I noticed that the tab title is no longer italic.

About Hardono

Hi, I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 9 years.

Today I noticed that the comment’s author pictures are broken. Some are visible, some are not.

Using Chrome’s Inspect Element function, I can see that the image URL starts with http://0.gravatar.com/avatar/. When I opened the image URL, Chrome shown “This site can’t be reached” error. My first instinct was replacing http with https. And voila… the the image loads.

Now I need to make this fix permanent on this blog. Digging through the sidebar source code, I found that the avatar image URL is produced by this function: get_avatar (codex URL). This function can be found inside file wp-includes\pluggable.php.

I proceed by adding this change at line 2415 (WordPress 4.8)

	if (strpos($url,"gravatar")>=0)
	{
		$url = str_replace("http://","https://",$url);
	}

Then I realized that my changes could be overwritten by WordPress future updates. Luckily, this function is pluggable. I can just copy over the whole function into my theme’s functions.php. I need to put the function into a plugin and then activate it. This is the only way to override the default get_avatar function.

Since I felt that my approach of using str_replace is probably the worst :D, I Googled for this topic. As it turned out, someone asked about this topic 3 years ago. In that page I confirm that my approach is indeed bad. There is a parameter to indicate what protocol Gravatar will use.

get_avatar( $id, $size, null, false, array('scheme' => 'https') );

By default this parameter is set to null. So I just need to change it to ‘https’.

function get_avatar( $id_or_email, $size = 96, $default = '', $alt = '', $args = null ) {
		$defaults = array(
			// get_avatar_data() args.
			'size'          => 96,
			'height'        => null,
			'width'         => null,
			'default'       => get_option( 'avatar_default', 'mystery' ),
			'force_default' => false,
			'rating'        => get_option( 'avatar_rating' ),
			'scheme'        => 'https', // 'scheme'        => null,
			'alt'           => '',
			'class'         => null,
			'force_display' => false,
			'extra_attr'    => '',
		);
   // ... SNIPPED ...
}

Finally, I bundled this function into a plugin called gravatar-secure. I didn’t bother to submit this plugin to WordPress Plugin Directory since it’s too simple πŸ˜€

So if you have similar issue to what I have, you can download the zip file below, extract and examine the source code. Once you’re sure my code is not malicious, you can upload the gravatar-secure folder into your WP’s plugins folder then activate the plugin.

Disclaimer: No guarantee, no warranty whatsoever. Do at your own risk.

the plugin in action here at this blog

About Hardono

Hi, I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 9 years.