Code Slinger

Computer hardware is great and I have lots of it as the owner of a computer company. However when you want that cold plastic composite and metal thingy to do something...you need code.

Code Projects
  • Code Projects in C++,C#,PHP,Java

    Code Projects in C++,C#,PHP,Java

  • Future Tech

    Future Tech

X-NLP

X-NLP

Extreme Natural Language Processing.
Read More
Data Bots

Data Bots

Internet Bots for Crawling, Scraping and Data Mining
Read More
Vid Automatic

Vid Automatic

Creating rich real time video products and streaming services.
Read More
VR Hacker

VR Hacker

The Hacking of Virtual Reality with the Oculus Rift.
Read More

Symbolic Linking Directories on Windows

mklink

It is great to finally see a real effective symbolic link implemented as a standard option in the latest Windows 7 and up. If you have experience with unix or linux systems you may already know all about symbolic links. If not, a symbolic link is a way of telling the computers operating system that a file path points to a different location. This is useful when dealing with compatibility or access problems with programs such as unchangeable or default install locations of programs that are too problematic to actually reinstall in the new location or for some reason impossible to change. This method will help standardized file path conflicts.

When you create a symbolic link the “new folder” will point to the “source folder”. This will allow you to access files in the source folder through the new folder path and the computer will not try and correct it, it will believe the files actually are located through the new folder path, but in reality they will be affecting those in the original source folder.

1. Login to Windows 7 or 8 as an administrator
2. Goto \Windows\System32 and locate cmd.exe, right click on it and select “Run as administrator”
3. In the command window you will enter the command to create the symbolic link between the two directories like so.


C:\> mklink /D “C:\NEWFOLDER” “C:\SOURCEFOLDER”

Now if you open your computer folders and goto C: (or whatever location you did this at) you will see the folder C:\NEWFOLDER you will also notice a little arrow in the bottom left of the icon indicating this is a symbolic link (not to be mistaken by a shortcut).

Note on shortcuts: A shortcut will resolve to the source folder unlike symbolic links which resolve directly through the path of the symbolic link. So shortcuts don’t have the ability to correct path conflicts in most instances like this method will.

Mklink /D (symbolic link) vs /J (junction)

In the above example we used /D to make a symbolic link, however it must be noted that a symbolic link for a directory only works if the new folder and source folder exist on the same partition. If you want to make a symbolic link across partitions, drives, shared network drives-then you must a junkction. Simply replace the option /D to /J in the example above.

Oculus Rift Virtual Lap Dances

Duke and I went out on the town the other night bringing a fat wad a lot of bucks for the girlies.

Here is an moment in the life of game history now available in virtual reality for the Oculus Rift.

Oculus Rift Now Plays Most Popular PC Game in the World

I have spent long days and nights the last few months to add VR support to the worlds most famous PC game and here are the final results.

If your taste for great games in VR hasn’t been satisfied yet watch the new port for Mine Sweeper..OOOH YA!

View my new YouTube Channel @ http://www.youtube.com/user/codesslinger

WordPress.com Post By Email with Images (PHP)

wordpress_smash

In an earlier blog I showed how one can use a simple PHP script to send blog posts to blogger via email. The same thing can also be done to other blogs such as wordpress.com. When I say WordPress.com I mean the hosted site not the self hosted WordPress offered by wordpress.org (I will address self hosted WP sites in a future blog.)

Here are the steps to turn on Post By Email for WordPress.com blogs.

1. From the main account area: At the top of your wordpress.com login click “My Blogs” then under the blog listing “Blog Admin”, this will put you in the blogs dashboard
2. From the dashboard: On the left side menu, mouse over “Settings” on the sub menu select “Writing”. At the bottom of the Writing Settings page there is a section called “Post by Email” Click on the “My Blogs” link.
3. There should now be a list of all your blogs, in a table, one of the columns is called “Post by Email” and there is a button to push called “Enable” push it and it will generate a secret email that you can use to post blogs via emails to. Write this down we will use it in the code below.

When you send an email to this secret email address it will post the contents of the email to the blog and the subject of the email will become the title of the article. If you include an image as an attachment then the image will also be included in the blog and hosted on wordpress.com’s server.
However there is an issue at this time with such image attachments, the image is posted following the blog article contents, not at the top. In the forums the developers state they are looking into a fixing this issue but I don’t think it is a priority for them.

Another issue regards HTML content. Not all HTML tags and formatting will make as wordpress.com strips some out. Currently I have no list of what is and isn’t passed through but form and javascript tags are stripped.

I should also note that Post By Email for wordpress.com includes some extra custom tagging options. These options include:

• [category x,y,z]
• [excerpt]some excerpt[/excerpt]
• [tags x,y,z]
• [delay +1 hour]
• [comments on | off]
• [status publish | pending | draft | private]
• [password secret-password]
• [slug some-url-name]
• [title Your post title]
• [end] – everything after this shortcode is ignored (i.e. signatures). Make sure it’s on its own line with a blank line above it.
• [slideshow] – replaces the auto-gallery with a slideshow
• [nogallery] – disables the auto-gallery and displays all images inline
• [more] – more tag
• [nextpage] – pagination
• [geotag on | off] – override your geotagging privacy defaults to enable or disable the showing of geo information
• [publicize off|twitter|facebook] – change Publicize options
• [poll]question and answers[/poll] – insert a Polldaddy poll into your post

For details on how these tags operate you can read the documentation page on the wordpress.com site here: http://en.support.wordpress.com/post-by-email/

Now for the PHP code. I recommend using the PHPMAILER class and using a gmail account for the sender, this seems to be the most stable way of performing the email posts.

include('class.phpmailer.php');

$gmail_your_name = "YOUR NAME";
$gmail_username = "YOUR GMAIL USERNAME";
$gmail_password = "YOUR GMAIL PASSWORD";
$gmail_email = "YOUR GMAIL EMAIL ADDRESS";
$wordpress_email = "YOUR WORDPRESS SECRET EMAIL";
$wordpress_url = "YOUR WORDPRESS.COM BLOG URL";
$image_location = 'C:/YOUR LOCATION OF IMAGE/IMAGE.JPG';
$email_title = "EMAIL TITLE";
$email_body = "EMAIL BODY"; // (LIMITED) HTML OK

$mail = new PHPMailer();
$mail->IsHTML(true);
$mail->IsSMTP();
$mail->;SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = $gmail_username;
$mail->Password = $gmail_password;
$fromname = $gmail_your_name;

$To = trim($wordpress_email,"\r\n");

$mail->AddAttachment($image_location);
$mail->From = $gmail_email;
$mail->FromName = $fromname;
$mail->Subject = $email_title;
$mail->Body = $email_body;
$mail->AddAddress($To);
$mail->set('X-Priority', '3'); //Priority 1 = High, 3 = Normal, 5 = low
$mail->Send();

If you are wanting to capture the URL for the newly posted blog after it has been made you can use the following.

sleep(15); // give it enough time to receive and update the post (15 seconds)
$bf = file_get_contents(rtrim($d2s[html_code],'/').'/feed/');
list($t,$b1) = explode("<item>",$bf,2);
list($t,$b2) = explode('<link>',$b1,2);
list($b3,$t) = explode('<',$b2,2);
$bb = trim(str_replace('"','',$b3));
$bb = trim(str_replace("'",'',$bb));
$bb = trim(str_replace(' ','',$bb));
echo '<li>LINK IS='.$bb;

Stop Giving Your Affiliate Link Juice

broken-link

It is no wonder that Amazon and other giant shopping sites that offer affiliate programs rank highest on search engines like Google. The associate that use the affiliate programs are helping drive those stores link popularity up by using the standard links which in turn hurts their own affiliate marketing strategies. There are easy ways you can implement linking to prevent sabotaging your own SEO.

The Problem

When you create a link that points to a product or the associated program for commission referrals, the search engines follow that link even if it is redirected by a 301 or other means. Even if you try and use Google’s “nofollow” rules the link is still observed as a pointer from your site to theirs. Even using a jump gate and robot.txt rules the search engines will still observe the outgoing link to the destination. When you have thousands of other associates using their own links to point to that same product then OF COURSE that drives the authority of the affiliate programs own page to the top of the search engine listings.

Then of course customers are not going to drill down several pages deep in search engine results to click on your link. That is if you get listed on the search engines at all with such tactics. It is counterintuitive to use such direct links for any type of reseller campaign.

The Solution

First you need to stop using the original manufacturer information supplied by the affiliate program for your affiliate link pages. When search engines see the exact same content on a thousand different pages then you will get very little traction if any. I will cover “content mutation” in a future article.

Addressing the problem with links and link juice pouring out of you page to the affiliate program you must eliminate the ability of the search engine to recognize and follow the actual link while not blocking your own web traffic from channeling through the link.

There are several different approaches that can be used, AJAX, Javascript, CSS Dom to name a few but the easiest is to simply use a POST form. Currently search engines such as Google do not try and press on form buttons and follow them, they are completely ignored, except in the case of simple action GET forms.

<form action="http://MY AFFILIATE LINK" method="POST">
<input type="submit" value="BUY NOW" />
</form>

This is not totally ideal as the link can still be picked up from the action tag, however not all affiliates will have the ability to add a jump gate, but it is better than nothing, it won’t be considered a hole in your page for link juice.

This is not totally ideal as the link can still be picked up from the action tag, however not all affiliates will have the ability to add a jump gate, but it is better than nothing, it won’t be considered a hole in your page for link juice.

A better solution is to use a simple jump gate that masks the URL, such as something like this.

<form action="jump.php" method="POST">
<input type="hidden" name="id" value="<?php echo base64_encode(http://MY AFFILIATE LINK); ?>" />
<input type="submit" value="BUY NOW" />
</form>

jump.php

<?php
header('Location: '.base64_decode($_REQUEST[id]));
exit;
?>

NSA Metadata

dreamstime_2470101

What exactly is metadata? Well it is data.

With the current Edward Snowden leak of the NSA projects the media has been slinging some terms around lately such as metadata. That the NSA is only collecting the metadata of phone conversations and emails. What they are implying is that a recorded phone conversation is the “data” and that the phone number that the calling and receiving phone numbers are the “metadata”.
The phone numbers are themselves data, we refer to metadata when a piece of associated data can be used to cross-reference or look up the associated data. So if you want to retrieve the full phone conversation and other related data using the phone number, the phone number in essence becomes a piece of meta data. Yet metadata is not some obscure index key or random file number, it is actually data for the purpose of looking up the rest of the data.

Here is where we start to see through the smoke and mirrors the government wants to throw at us with this terminology and I fear that the media truly is ignorant on. If any piece of data can be meta data, then the conversation itself is also metadata because algorithms can, and are, used for detecting keywords in the conversation. So there you have it, EVERYTHING, including the entire phone conversation, the entire email is all meta data.

So don’t be fooled by this crazy double talk about “we are only collecting metadata”, it means they are collecting ALL OF IT.

Cyberspace is Near

johnny-mnemonic2

Over two decades ago William Gibson coined the phrase cyberspace. Most consider that term today to mean the Internet and online games. However that is not actually as Gibson described it. Cyberspace is more of a virtual landscape that corresponds in relationship to that of the physical world. So if you are sitting at home and want to go check out your bank account you put on your VR and walk or fly down the street in cyberspace to the location of your bank to access your account, you of course physically are still at home.

Of course the actual Internet is a lot of more convenient when it comes to say banking then the one envisioned by Gibson, but it doesn’t mean his vision was wrong. The vision of Cyberspace was to emerge in the early to mid 2010’s, that is now and guess what, that technology is actually emerging today. So Gibson may have been fully correct in his futuristic predictions.

0wyjn1xhufomfxoce6rm

Why would we want this style of Cyberspace? It is all about the new technologies of Augmented Reality (AR). Now with GPS, WiFi, Google Glasses and other technologies such as VR to AR with the Oculus Rift, augmented reality is about to become the next big thing–depending on market demands.

The other key factor that will shape Cyberspace in the next few years in the flood of cheap micro computing. Tiny computers with built in wifi/RF and location that are very cheap that can be put into the wild. Store owners can install several of such devices in their store that will signal specials and where things are to customers as they move through the store using AR devices.
Even cheaper alternatives can be applied as well to go with AR that include QR codes and other types of even invisible to the necked eye watermarks on signs and billboards that only the AR devices can pick up but signal the device to show holographic images, movies, play sound tracks and all kinds of things including interactive games.

Going back to the banking idea above, we can imagine when we walk into our bank we are instantly and securely connected to the banks cyberspace and you maybe greeted with a virtual teller or someone in loans, not that you may even need to goto the bank, just like with the Internet you can goto the banks cyberspace without actually being there but your presence would be recognized as you were there for talking with a real in house agent for say getting a bank loan.

You and your significant other want to dine out tonight on the top of the Eifel tower without leaving the home. Cook up a good meal, set down and throw on your cyberspace devices and your experiencing dinner on the Eifel tower in real time.

Reality is soon to change, Cyberpsace is near.

Mail2Blogger with Images (PHP)

blogger_smash

Blogger allows you to send posts via email, intended for on the go posting via mobile devices and such. To activate this feature you have to update your blog settings with a secret key.

1. Log into Blogger
2. Select “Settings for your Blog”
3. Select “Mobile and email”
4. Where it says “Posting using email” there is a box, in front of the box is your username, following the box is @blogger.com. In the box put your secret key.
5. On the radio selection below that make sure “Publish email immediately” is selected.
6. Click Save Settings

Now all you have to do to send a post to your blog is send it to that email address that contains your secret key. The title of your email will be the title. Keep in mind that if your email automatically adds a signature to your email that it will probably also appear on your post.

You can include an image that appears at the top of the article by attaching an image in your email. Blogger saves this to its server and hosts it (10MB limit for images)
Using PHP we can now easily post new blog articles at any time or even automatically using the PHPMAILER class from Synchro at Github. It is best that you use a gmail account email that is associated with your blog to reduce any imperial entanglements. Also by using gmail account and this method you are not required to have a running mail server or do any other funky relaying (great for those doing projects in XAMPP.)

include('class.phpmailer.php');

$gmail_your_name = "YOUR NAME";
$gmail_username = "YOUR GMAIL USERNAME";
$gmail_password = "YOUR GMAIL PASSWORD";
$gmail_email = "YOUR GMAIL EMAIL ADDRESS";
$blogger_secret_key = "YOUR BLOGGER SECRET KEY";
$blogger_url = "YOUR BLOGGER URL";
$image_location = 'C:/YOUR LOCATION OF IMAGE/IMAGE.JPG';
$email_title = "EMAIL TITLE";
$email_body = "EMAIL BODY"; // HTML OK

$mail = new PHPMailer();
$mail->IsHTML(true);
$mail->IsSMTP();
$mail->;SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = $gmail_username;
$mail->Password = $gmail_password;
$fromname = $gmail_your_name;

$To = trim($gmail_username.'.'.$blogger_secret_key.'@blogger.com',"\r\n");

$mail->AddAttachment($image_location);
$mail->From = $gmail_email;
$mail->FromName = $fromname;
$mail->Subject = $email_title;
$mail->Body = $email_body;
$mail->AddAddress($To);
$mail->set('X-Priority', '3'); //Priority 1 = High, 3 = Normal, 5 = low
$mail->Send();

If you are keeping a database of your posts for other projects such as twittering and other linking you can extract the new posts link with the following code. Just add it after the end of the above code.

sleep(15); // blogger enough time to receive and update the post (15 seconds)
$bf = file_get_contents($blogger_url);
list($t,$b1) = explode("'post-title entry-title'",$bf,2);
list($t,$b2) = explode('<a href=",$b1,2); list($b3,$t) = explode(">',$b2,2);
$bb = trim(str_replace('"','',$b3));
$bb = trim(str_replace("'",'',$bb));
$blog_post_url = trim(str_replace(' ','',$bb));<a href="http://charleshays.com/wp-content/uploads/2013/07/blogger_smash.png"><img src="http://charleshays.com/wp-content/uploads/2013/07/blogger_smash-300x300.png" alt="blogger_smash" width="300" height="300" class="alignnone size-medium wp-image-102" /></a>
echo 'NEW POST AT='.$blog_post_url;
</a>

What is Spinning and a Spin Function (PHP)

dreamstimesmall_2869597

Spinning Basics 101

Spinning generally refers to randomly generating articles, content and data based on option sets. Typically a template or as I call it a “boil plate” is created identify the set. I will address the use of spinning for generating articles and other sentence content but as you will easily derive the content does not need to be limited to just words and sentences, you can spin html, CSS, PHP code, data and more.
Say we have a sentence such as “I love my car.” How else could we say this?

I love my automobile.

I like my car.

I really like my vehicle.

These sentences roughly all portray the same meaning but each is distinctly different. When it comes to unique article generation this technique can be invaluable. All we have to do get all these variations and other combinations is generate a boiler plate for the sentence like so.

I {really |}{love|like} my {car|automobile|vehicle}.

So as you can see above all versions of the sets of words are contained in the curly brackets each version separated by the pipe character (the straight vertical line.) Pipe us used because it one has been a standard data delimiter and two because it also a shortcut for OR in programming logic. There is no so called standardization for spinning but it is widely used.

In our example we can see that when spun the set {love|like} means there is equally likely chance that either word will be chosen and used in this spot. For {really|} we see there is only one word, but there is still a pipe followed by a bracket, this indicates there is a chance that really or “nothing” will be selected. Also the last set contains car, automobile and vehicle all with an equal chance to be chosen.

But say we wanted the word ”love” to have a greater chance then like to be chosen? If each of the two words has a 50/50 chance we can increase the odds for the word like by going {like|love|love} now “love” has 2 in 3 chances or 66% probability of being chosen. Same thing can be applied if we want to reduce the odds of the word “really” we can go {really|||} now we have 3 blank spaces to the one choice for “really” giving the word only a 25% chance of being used.

Nested Spinning

With recursive functions such as the one at the end of this article, you can create boiler plates with nested spins, that is spins within spins.
For example:

Spinning is a {{great|wonderful|good} tool|hot {topic|subject}} for SEO.
When nesting it can start to become confusing to decipher the text but if you break it down like so it is easier to see.

{
	{great|wonderful|good} tool
	|
	hot {topic|subject}}
}

If the first element of the top spin is chosen followed by the second element of the nested spin we get “Spinning is a wonderful tool for SEO.”
Spinning has no restrictions on the levels of nesting you want to add.

Spinning Function for PHP

This has been a very introductory article on the concepts of spinning, most spinning also incorporates deeper elements such as dynamic variables, synonym spinning, adjective and grammar injection and more.

If you are ready to get spinning using some simple PHP code here you go.

function spin($s)
	{
	preg_match('#\{(.+?)\}#is',$s,$m);
	if(empty($m)) return $s;
	$t = $m[1];
	if(strpos($t,'{')!==false)
		{
		$t = substr($t, strrpos($t,'{') + 1);
		}
	$parts = explode("|", $t);
	shuffle($parts);
	$s = preg_replace("+\{".preg_quote($t)."\}+is", $parts[array_rand($parts)], $s, 1);
	return spin($s);
	}

Of course you can create similar functions in almost any language including C++,C#, Perl, Python and so on.

Kicking the Hash Bucket (PHP)

 

If you have ever studied or taken a class that discusses searching and sorting algorithms and their efficiencies you will be familiar with sequential search, binary search and others. However was bucket search ever mentioned? As a PHP programmer you might be using bucket search not even realizing it. Bucket search is absolutely the fastest most efficient and less complex method available. When using a language PHP that supports hash variables it gets even better and more beneficial.

A normal array uses only integers for the keys.

A[0],A[1],A[2]…

A hash array allows you to use strings as the keys.

A[apple],A[orange],A[banana]…

In traditional methods when you want to search an array for an element to be retrieved you must iterate through the array until you find key and retrieve the value.  However bucket searches allow you to instantly retrieve the information based on the key value with no iteration, as the key is a pointer to the location in memory where the value is stored. That is the power of bucket search and I welcome any comments of another method that proves otherwise.

Here is some code with bucket search in action.

$fruit_color = array('apple' => 'red',
				'orange' => 'orange',
				'banana' => 'yellow');

echo 'An apple is '.$fruit_color[apple].'.';

 

There are however limitations and problems that can arise depending on the type of strings you utilize as the keys in your array, such as the use of special characters, binary characters, utf-8 characters, string is too long, white space, unknown upper and lower case conditions, and others.

Using base64_encode and a few other methods to normalize your key almost all of these issues can be resolved.

$quotes[myKey("This is Sparta!!!\n")] = 'The Movie 300';

function myKey($k)
	{
	return base64_encode(strtolower(preg_replace("/[^A-Za-z0-9]/", '', $k)));
	}