Tag: code

All-encompassing code update

Today is a big day for Spin Rewriter — even though it may not seem like it.

20 minutes ago we rolled out a huge update to our entire codebase. Through a massive multi-month code refactoring effort we’ve made our code more streamlined, more maintainable, more readable, and vastly more future-proof.

Fun fact: When we deployed all this new code to our servers 20 minutes ago, more than 90% of all files containing code were updated.

In the process we’ve also eliminated over 1,100 lines of code.

Wait… Less code? Doesn’t that seem like a bad thing?

There’s a brilliant quote attributed to Bill Gates: “Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

I think that’s an absolutely brilliant way of putting it. By making the code more compartmentalized and more reusable, we were able to significantly trim down the amount of code required in total.

And even though Spin Rewriter was running on great code before, with this latest update the code is downright beautiful. There’s another relevant quote:

Code is poetry.

Here at Spin Rewriter we believe that 100%, and with every update we make sure we’re delivering a better, faster and more robust user experience to our awesome users. Cheers! 😀

Improved parallelization of CPU-intensive tasks, Part II

OK, we’re back!

As I mentioned in the previous post (published on February 9th), here at Spin Rewriter we always strive to further improve our server infrastructure and fine-tune our code. We’re looking to deliver faster and better software that’s more intuitive and more robust than ever before.

We’ve now taken advantage of some new opportunities to parallelize certain aspects of Spin Rewriter’s existing spinning process. This means that we’re now able to run certain parts of the spinning process on multiple processors (CPUs) on different servers at the same time instead of running it on just one server.

Here’s a simplified explanation of the benefits this brings. Imagine you have an article with 20 sentences. We can either have our software detect the parts-of-speech on each of those sentences in a row, and if it takes our software one second to analyze every sentence, we’re looking at 20 x 1 second = 20 seconds of waiting time for the user.

We can, however, break this article down into 20 separate sentences — and send each of these sentences to a different server in our grid at the same time. Each of those 20 servers then processes just one sentence, and only 1 second later we get the processed results back to the central system.

The result: The same article is now fully processed in just 1 second instead of 20.

And the result that matters much more than that: Our users are even happier! 😀

Of course the exact real-world situation isn’t as cut and dry, but we were still able to roll out a significant improvement in speed and robustness of our spinning systems — and we hope you’ll love it!

Improved parallelization of CPU-intensive tasks

OK, the title of this post might sound a bit “high and mighty”, but hopefully it shouldn’t be too difficult to understand once we break it down a bit.

As you probably already know, our server infrastructure is quite state-of-the-art which allows Spin Rewriter to have great uptime and to always process all of your articles, find the best synonyms, manipulate sentence structures, export thousands of text files etc. etc. in a matter of seconds.

We always strive to further improve our infrastructure and our back-end software code. Faster, better, more intuitive, more robust — this is what drives us.

We’ve recently dug extra deeply into our software and found some new opportunities to parallelize some aspects of the spinning process. In other words, we’re now able to run a certain aspect of the spinning process on multiple processors (CPUs) on different servers at the same time instead of running it on just one server.

We’ll bring you more details in our next post, however right now we can already give you a hint that GREAT things are underway. Stay tuned! 😉

 

Spin Rewriter 5.0 API library now available

Good news for all developers out there: We just updated the Spin Rewriter API code samples, SDK libraries, and documentation!

Even better news for all developers: The brand-new Spin Rewriter 5.0 API is 100% compatible with older versions of our API, which means all your existing code will keep on working flawlessly without any changes required on your part. 😀

What’s new in the 5.0 version of our API?

For starters, we’ve added the new Spin Rewriter 5.0 functionality such as the ability to intelligently randomize the order of paragraphs and unordered lists when generating new articles in order to maximize their uniqueness. All of this is described in the updated API documentation.

We’ve also released brand new code samples that will get you up & running within minutes…

…and maybe most importantly, we’ve released a new version of the Spin Rewriter API SDK for PHP:
http://www.spinrewriter.com/api-samples/spinrewriter-api-sdk-v5.0.0.zip

You can simply include this PHP library and starting using the Spin Rewriter API with literally 2 lines of code!

I hope you like these changes & we’ll keep on working hard to make sure it’s super easy to integrate the awesome ENL semantic spinning power of Spin Rewriter directly into your own software!

Spin Rewriter is even faster now

With yesterday’s update we managed to cut down the post-processing time (when our software is actually learning from the changes you applied to your article so it can get even better in time) a whopping 82-84%!

This means that the user experience is even smoother now, and once you click the “Continue to the Final Step” you don’t have to wait for more than a couple of seconds. If you have a good internet connection, it actually takes less than 1 second to take you to the final step. 😀

Stay tuned, we’re working hard!

A major update

Just this morning we rolled out one of the major updates of our new article rewriter, called Spin Rewriter.

This includes an even faster user interface, 65% shorter pre-processing time (when our software is figuring out the exact meaning of each word of your text), it also takes 25% less time to generate and sort lists of relevant synonyms now, and the One-Click Rewrite option almost never crashes any more. 😉

Pretty good for a beta product, right? 😀

Creating an array of all dates between 2 specified dates [PHP]

I’ll just cut to the chase.

/**
 * create an array of all dates between two specified dates
 * @param datetime $strDateFrom
 * @param datetime $strDateTo
 * @return array
 */
function createDateRangeArray($strDateFrom, $strDateTo) {		
	$aryRange = array();
	$iDateFrom = mktime(1, 0, 0, substr($strDateFrom, 5, 2), substr($strDateFrom, 8, 2), substr($strDateFrom, 0, 4));
	$iDateTo = mktime(1, 0, 0, substr($strDateTo, 5, 2), substr($strDateTo, 8, 2), substr($strDateTo, 0, 4));
	if ($iDateTo >= $iDateFrom) {
		array_push($aryRange, date("Y-m-d", $iDateFrom));			
		while ($iDateFrom < $iDateTo) {
			$iDateFrom = $iDateFrom + 86400;
			array_push($aryRange, date("Y-m-d", $iDateFrom));
		}
	}
	return $aryRange;
}

Is this a valid URL? [PHP]

If your users link to some URL, it’s always nice to check if their input actually represents a valid URL. You can do just that with this function:


/**
 * return true if the passed variable is a valid URL address
 * @param $url
 * @return boolean
 */
function isValidURL($url) {
	$pattern  = '/^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/';
	return preg_match($pattern, $url);
}

If this function returns true, you might want to actually open the URL (using file_get_contents() or some other function) to see if it works.

Convert large numbers into a more readable format

It can be tricky to really understand the value of 7312946 or 983217 at the first glance. Saying 7.3M and 983k seems like a much better option. How to convert numbers into a nicer format? Like this:

/**
 * create a nicely formatted number
 * @param $number a large number
 * @param $shorten default true = append k or M, false = format with commas and dots
 * @return int
 */
function createHumanReadableInteger($number, $shorten = true) {
	if (is_numeric($number)) {
		if ($shorten) {
			if ($number < 100000) {
				$return_int = number_format($number, 0);
			} else {
				$number_proc = $number;
				$units = explode(" ", "B k M G T P");
				for ($i = 0; $number_proc > 1000; $i++) {
					$number_proc = $number_proc / 1000;
				}
				if ($number > 1000000) {
					$return_int = round($number_proc, 2) . " " . $units[$i];
				} else {
					$return_int = round($number_proc, 1) . " " . $units[$i];	
				}
			}
		} else {
			$return_int = number_format($number, 0);
		}
		return $return_int;	
	} else {
		return 0;
	}
}

Converting a DATETIME variable into a UNIX timestamp

Here’s how:

/**
 * convert a datetime value (Y-m-d H:i:s) to UNIX timestamp value
 * @param datetime $datetime
 * @return timestamp
 */
function datetime_to_timestamp($datetime) {
    list($date, $time) = explode(" ", $datetime);
    list($year, $month, $day) = explode("-", $date);
    list($hour, $minute, $second) = explode(":", $time);
    return mktime($hour, $minute, $second, $month, $day, $year);
}