Category: Programming

A bunch of updates

The launch frenzy still hasn’t settled down, however I was able to find a couple of hours in between writing a ton of emails to introduce some great updates to Spin Rewriter.

Yes, that’s correct – Spin Rewriter is already getting better not only by learning from its users about the quality of various synonyms and meanings, but we’re also actively improving user experience and adding new cool features.

Here’s what was updated in the last 24 hours alone:

  • we fine-tuned the uniqueness meter that tells you how unique your generated articles will be
  • we added support to ignore whole phrases (multiple words) when doing a One Click Rewrite
  • we have changed the 800-word limit to a much higher one that you shouldn’t hit when rewriting your articles
  • you are now able to delete finished articles from your archive
  • you can export up to 400 unique version of your article in 400 text files, OR in a single text file
  • Spin Rewriter now automatically fixes most common misspellings (dont, doesnt, hasnt, havent, wierd, definately, etc.)
  • we fixed and improved a bunch of other stuff

Hope you guys like it! 😀

 

No more “Whoops, where did it go?!”

I wrote about a functionality that was requested by a couple of our Beta Testers about a week ago – our users demanded something that would prevent them from losing all their hard work if they accidentally pressed the “back” button or somehow left Spin Rewriter’s Edit Mode without saving their progress.

We just improved Spin Rewriter’s user interface and added what was requested – from now on you can no longer accidentally lose your progress. Whether you click the “previous page” / “next page” button, refresh the page, click on a link or close your browser while you’re in Edit Mode, you will be asked to confirm if you really want to do that. This way you can feel safe and happily click on everything you want, and you’ll never lose your hard work.

Try it out! 😀

Prevent users from accidentally leaving the page [JavaScript]

Sometimes your users might lose important information that they’ve been working on by accidentally leaving the page. They can either press the “previous page” or “next page” button by accident, or they can hit the “backspace” key on their keyboard, inadvertently click a link etc.

Luckily you can prevent them from losing their progress by using the following bit of JavaScript code:

window.onbeforeunload = function() {
    if (your_users_might_lose_their_work) {
        dialog_text = "IMPORTANT: Are you sure you want to leave this page?\n\n";
        dialog_text += "WARNING: If you leave this page, you will lose all your current progress.";
        return dialog_text;
    }
};

This code works perfectly fine with all modern browsers, with one small disclaimer: Firefox will not show your custom warning to your users, instead it will simply state “This page is asking you to confirm that you want to leave – data you have entered may not be saved.” However, that’s exactly what you usually want to say in this situation anyway.

Another big update

We’ve just rolled out another important update for the new article rewriting system Spin Rewriter.

This time we focused on improving the artificial intelligence behind it to make it understand your articles even better. We implemented two important additional natural language processing methods (our colleagues over at Stanford and Princetion have been toying around with them for a while now) and we couldn’t be happier with the results. Spin Rewriter now correctly understands over 94% of the tricky ambiguous words with many meanings, and 100% of all other words of course.

If you want to see it in action, sign up and become one of our Beta Testers! 😀

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? 😀

Get HTML of selection [JavaScript]

I just recently needed to get the actual HTML of what was selected in a browser. Selected as in “you drag your mouse across some text and it turns blue”. So I came up with this nifty piece of JavaScript code that works quite flawlessly across all major browsers (yes, including IE).

/**
 * gets the current selection, including HTML code
 * @return string
*/
function getSelectionHTML() {
	var userSelection;
	try {
		if (window.getSelection) {
			// W3C ranges
			userSelection = window.getSelection();
			if (userSelection.getRangeAt)
				var range = userSelection.getRangeAt(0);
			else {
				var range = document.createRange();
				range.setStart(userSelection.anchorNode, userSelection.anchorOffset);
				range.setEnd(userSelection.focusNode, userSelection.focusOffset);
			}
			var clonedSelection = range.cloneContents();
			var div = document.createElement("div");
			div.appendChild(clonedSelection);
			return div.innerHTML;
		} else if (document.selection) {
			// Internet Explorer selection
			userSelection = document.selection.createRange();
			return userSelection.htmlText;
		} else {
			return "";
		}
	} catch(e) {
		// an error occurred - supposedly nothing is selected
		return "";
	}
};

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;
	}
}