Category Archives: Programming

OpenVPN One-Command Server Install Script

I have been looking for a script like this for about a year now:

https://github.com/Nyr/openvpn-install

For some reason that I never understood, installing and setting up an OpenVPN has always been a pain in the ass.  I’ve had one I’ve been using for about a year, but it’s on Amazon’s AWS as was installed through an appliance install, and I really wanted to learn how it worked myself.

Every tutorial I saw either didn’t make sense, or the steps didn’t work.  I set about to try and create a one-script install myself, and then thought, “No — somebody has to have done this before.”

And lo and behold — that’s where I found the above github repo.  It’s amazing, and it works.  I’m going to donate to this person, because they saved me a good bit of work.

 

mysql_connect() breaking with an upgrade to PHP7?

mysql_connect() has been finally removed from PHP7 (it was deprecated for some time), and now you have to use mysqli_connect();   The same goes for any other mysql_ commmand.  (I simply did a find/replace for “mysql_” and changed it to “mysqli_” in my php code.

Also, if you’re running your own server, you probably need to install the “php-mysql” after upgrading to PHP7 — it doesn’t seem to be installed along by default anymore.

Using Dreamhost’s VPS as a MySQL Server

[Editor’s Note: Dreamhost no longer allows sudo access on their VPS servers, so the below is no longer possible. If you’re reading this, you might want to check out Amazon’s AWS. Nowhere near as user friendly as Dreamhost, but MUCH more powerful.]

I’ve been a happy customer of DreamHost for many years now — for $9.95 a month, I was able to get loads of diskspace and unlimited bandwidth, all from a great company that was staffed by great people who were very technically competent.

It is “shared hosting,” however — that means you’re getting it that cheap because you’re sharing server CPU power, available RAM, etc, with many other people who are also getting a great deal. You’ll notice this in any WordPress sites you may run on Dreamhost’s shared hosting — there’s about a 7-10 second delay between when you navigate to your site and when your page actually loads, mostly because your server processes are waiting in line behind everyone else’s.

So, Dreamhost does offer a “VPS” service — with this, you’re getting an absolute amount of RAM, CPU power, etc, that will only be used for your sites. It’s a tiny bit more expensive, at $14.95 or so a month, but it’s worth every penny.

If you’ve run WordPress installations on a Dreamhost site, though, you know that your mysql databases are on a seperate server entirely, and that may slow things down as well. Even if you move your WordPress installs to a VPS, your mysql databases will still be on shared hosting. DreamHost offers a “MySQL VPS,” but it costs another $15 a month (minimum), and you have no control over it at all.

A better solution would be to run your own MySQL server on DreamHost’s main VPS, since they give you root command-line access. There are a few hiccups in this process (some put there by DreamHost itself), but otherwise you should be able to do it.

  1. First, create an admin user for your VPS that has sudo abilities, and log into your VPS with that through ssh.
  2. Second, you have to tweak apt so you can even install the mysql-server package. It appears as if part of installing packages through apt involves temporarily storing files in /tmp and then running them from there.Unfortunately, the /tmp directory is mounted on DreamHost’s VPS servers with the noexec option, which means that you can’t run files that are present in that directory. That basically prevents you from installing the mysql-server package until you tweak apt to temporarily stage files in /var/tmp instead. Do this by:Creating a file called apt.conf in the /etc/apt/ directory, and edit it so the contents are the following:
    APT::ExtractTemplates::TempDir "/var/tmp";
  3. Then, install the mysql-server package:
    sudo apt-get install mysql-server;
    

    (When it asks to set a root password, make sure and set one.)

  4. Now, edit the file /etc/mysql/my.cnf and set the following options:
    bind-address=psXXXXX.dreamhostps.com

    (Replace psXXXXX with the name of your dreamhost VPS.)

  5. Restart your mysql service:
    sudo service mysql restart

At this point, you should be able to log in to your new mysql server:

mysql -u root -p

and then perform what SQL functions you need to.

A great thing to do is to install phpmyadmin using the tutorial here: http://wiki.phpmyadmin.net/pma/Quick_Install

First you’ll want to create a user (that isn’t your root user) to log into phpmyadmin:

mysql> CREATE USER ‘newusr’@’%’ IDENTIFIED BY ‘your_password';
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘newusr’@’%’ WITH GRANT OPTION;

At this point, you can sync your old databases to your new mysql server using the built-in sync tool that’s in DreamHost’s installations of phpmyadmin.  Then, just edit the wp-config.php file in the folder of your WordPress installations, and change the line that says the following to your DreamHost VPS:

define('DB_HOST', 'psXXXXXX.dreamhostps.com');

Sources:

Installing mysqld on Dreamhost VPS

https://bugs.launchpad.net/ubuntu/+source/debconf/+bug/90085

http://serverfault.com/questions/72356/how-useful-is-mounting-tmp-noexec

 

 

Unlocking/Rooting the HTC One on Linux

I recently bought a used HTC One that I intend on using on Ting — it’s a phone I’ve been wanting to use for about a year. It’s one of the nicest Android phones, with hardware quality approaching that of an iPhone. (Not to mention a software skin much more “professional” looking than a lot of other Android hardware manufacturers out there.)

HTC One Dimensions Picture
Isn’t it beautiful?

I didn’t want to flash or even necessarily root my HTC One, however, the only way to restore some apps (like the Google Authenticator) require rooting, so I had to do it.  What’s strange is that most tutorials and utilities I’ve found are for Windows (like this one from theunlockr) — I guess it shouldn’t be too surprising, considering most PC’s are Windows, but I’d figure that there would at least be some tutorials for Linux, considering Android’s origins.

Well, the good thing is that unlocking/rooting your HTC One on Linux isn’t really that hard at all, if you’re comfortable with the command-line, and familiar with using the android sdk tools (fastboot, etc.).

I’m not going to go into how to set up the Android sdk, etc, since if you’re doing something like manually unlocking your bootloader, you should already be familiar with it!

Unlocking/Rooting Your HTC One (M7) on Linux

Prerequisites:

  • android sdk
  • htcdev.com account
  • Latest recovery .img file from CWM
  • Superuser Hack .zip file: SuperSU (make sure and get whatever is the latest version of the SuperSU flashable zip — earlier versions found in other tutorials no longer work to root the later versions of Sense)

Unlock Bootloader

  • Boot into bootloader and select Fastboot
  • Run command “fastboot oem get_identifier_token”
  • Copy token as explained on the htcdev page, and await your Unlock_code.bin file in email
  • Copy Unlock_code.bin file to your working directory in Linux
  • Run command “fastboot flash unlocktoken Unlock_code.bin”
  • Follow prompts on screen to unlock/reset your phone

Flash Recovery

  • Boot into bootloader and select Fastboot
  • Run command “fastboot flash recovery <recovery.img>” (replace with .img file downloaded from CWM site)
  • Reboot

Root

  • Copy SuperSU .zip file to phone’s internal memory
  • Reboot into recovery
  • Flash SuperSU .zip file
  • Reboot and enjoy
Other Useful Links

Steve Jobs, 1955-2011

I started programming over 20 years ago on an old Macintosh II computer that my father practically fished out of the trash at his job.

I largely credit that old computer to where I am today — it wasn’t just the Macintosh’s ease-of-use and small learning curve, it was also, literally, the spirit of the designers and tinkerers that worked at Apple computer that existed in that machine.

The Macintosh was a computer that you could delve beneath the surface, when you wanted to — you could modify code, the way applications worked, the modules and extensions that started up when the machine booted — you had, when you wanted to, access to all the tools that the designers themselves used to create that very Macintosh you were using right then and there.

There’s a whole generation of programmers who got their start in this very way, and for that, I do have Apple to thank.

CELEBRATION OVER, CRITICISM BELOW:

And that’s the very reason why Apple’s current practices today kinda scare me. Apple’s products today are precisely not about giving the user tools and control — with each new version of MacOSX, each new iPhone that comes out, there’s less and less that tinkerers like me can do with it.

There’s less and less that the next generation of tinkerers can do with it. How would the next Steve Jobs design anything on an iPod Touch? On an iPad? How would a budding application developer get anyone to use a new application he’s designed, when people can only install apps via a curated, policed, application “store?”

I thank Apple for starting me on the path to where I am today, but I thank companies like Google for keeping that spirit alive, when it becomes increasingly evident that Apple either isn’t able to or just no longer wants to.

Configuring a Server with Ubuntu Desktop

I’ve been getting an Ubuntu server running recently (FINALLY), and in order to make it run headless (without keyboard, mouse, or monitor), there’s a few things one needs to do:

1) Enable Auto-Logins (optional)

All depends upon how you set things up, but you may want to run everything easily through a default user account — just go to “System > Administration > Login Screen”, and set it up.  (These instructions are for the GUI of Ubuntu, of course — I’m not a CLI-queen, and would rather edit things quickly through an interface that I’m familiar with than search forums for hours trying to find the esoteric commands necessary to do this stuff manually, sorry.)

2) Enabling Networking With Automatic User Login

Now, you may have set up automatic logins, but noticed that you always have to enter in your account password manually anyway once your network tries to connect — took me a while to figure out this one, but just go to “System > Preferences > Network Connections”, and in the type of connection you’ll be using, make sure the option for “Available to all users” is selected at the bottom.  That’s it.  I feel dumb for not figuring this out long ago.


3) Enabling VNC to Run Headless

As per the instructions I found here, you have to

  1. Edit “/etc/gdm/Init/Default” to include the line “/usr/lib/vino/vino-server &” right before “exit 0”
  2. Edit “/etc/gdm/custom.conf” (or “/etc/gdm/gdm.conf” if older than Ubuntu 10.04) and add “KillInitClients=false” — this will prevent any existing VNC clients from being killed if you do login on the server physically
  3. Do a “sudo vino-preferences” and enable the necessary stuff

More to come, including the Minecraft configuration scripts!

Retired WoW Addons: November 2010

Just a few more that have been abandoned since the 4.0.1 patch:

Mapnotes

Apparently, MapNotes is no more.  Trying to find an addon that will import my many years of notes that I’ve made with this addon.  (It’s seriously been one of the most helpful for questing with alts.)

I have a long history with this addon — for the longest time, I used it WAY back in the day, and then with the release of TBC, it stopped working.  Thankfully, there was “Metamap,” which imported MapNotes map points just fine. (Metamap doesn’t even have a Curse page — I used to have to download it directly from the author’s website.)

However, it in turn stopped working with version 3.0 of WoW, but MapNotes came back with a fan update!  (A fan update is where a fan of a defunct addon is able to get in contact with the original addon maintainer, and gets them to give them control over it.)  But, now MapNotes no longer works anymore, either, and I’m stuck trying to find a replacement.  Looking at HandyNotes for now — apparently there’s some way to get it to import MapNotes points.

SellValue and SellFish

Long live SellValue!  I used this addon for the LONGEST time, and it was an absolute lifesaver.

Out questing and need to know if that stack of gray shit you’ve been collecting is worth it to keep?  SellValue would tell you how much it was worth (dependent upon prices you had seen before).  This addon worked for the longest time, even though it hadn’t been updated since forever.

Even though it was still working wit version 3.0, I started using an updated addon called “SellFish” — however, as you can see, WoW integrated this functionality into the core game with version 3.2, so there’s no need for either addon anymore!

AnnoyRP

AnnoyRP was a neat little plugin everyone started using back in my heavy guild-RP days (god, that sounds so dorky). It had amazing functionality — based upon certain events in the game that you set it to notice, i.e. mounting up, casting a certain spell, it would /s certain things.

For instance, you could set it to say “Hi Ho, Silver, Away!” every time you mounted up (or a certain random amount of times, or even a certain random choice out of a group of phrases).  As you can imagine, it was LOADS of fun.

It stopped working some time ago, but the author made Chatterbox to make up for it.  Did the same thing, worked great.  However, now the author has left WoW (back in July over the whole RealID thing, which sadly enough didn’t even happen!), so who knows?  It seems to work fine for now, but that could stop at any minute with version 4.0.2 of WoW.

Integrating Picasa Web Photos with WordPress

OMG is this so much harder than it needs to be.

Picasa (or Google) offers nothing in the way of little blog widgets (unlike Flickr’s great support for everything), nor is there really any third-party support for this kind of thing out on the web.

I don’t understand why, since — at least to me — what Picasa offers for free is so much better than what Flickr offers, still, even to this day. :

Every third-party WordPress plugin I’ve tried either doesn’t work, doesn’t work right, or needs so much configuration on the server side — and I’m talking about editing raw PHP here (unacceptable) or creating farking CURL scripts for the server (why did you even release this plugin?).

Sadly enough, the BEST solution I could find for the problem of integrating Picasa was actually done in straight JavaScript (yay!), found here: http://www.bloggingtips.com/2009/03/23/picasa-widgets-and-plugins-for-your-blog/

Her code works great, works fast, requires almost no configuration (besides your Picasa username), and uses JQuery, so pretty much anyone can edit and customize it.

Which I did. ^_^ Though the code works, it doesn’t appear to always grab your latest photos from Picasa. (I’m guessing it has something to do with the “max-results” flag in the URL string — you have to restrict the number of photos that Picasa feeds up for you to get the latest.) I also made each photo be a link to the Picasa page where it’s at, as well as cleaning up the code a little.

There’s basically two parts:

First, put this code in a widget text block where you want it to be in your wordpress blog (this is also where you can edit the style):

<style>
#picasaStream img {border: 1px solid #000; margin: 0 5px 5px 0;}
</style> 

<div id="picasaStream"></div>

Second, put this code either right after the widget, or wherever you put your JavaScript (if you choose to put it in another place, like a footer):

<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>

<script type="text/javascript">
/*
****	Uncomment this line if you are using other JavaScript libraries
****	(Prototype, Scriptaculous, etc.)
*/
// jQuery.noConflict();

jQuery(document).ready(function(){
	/*
	****	Change your Picasaweb username here,
	****	as well as how many thumbnails you want to show
	*/
	var _userName = "captainskyhawk",
		_count = 6
		
	/*
	****	Choose your thumbnail size here:
	**** 	"0" for small, "1" for medium, and "2" for large
	*/
	var _thumbnailSize = 0;
	
	/*
	****	Script Code
	****	No need to edit any further
	*/
	jQuery.getJSON("http://picasaweb.google.com/data/feed/api/user/" 
		+ _userName + "?kind=photo&thumbsize=72c&access=public&alt=json&max-results="
		+ _count + "&callback=?",
		function(data){
			jQuery.each(data.feed.entry, function(index, pic) {
				jQuery('<a href="' + pic.link[1].href + '"><img src="'
					+ pic.media$group.media$thumbnail[_thumbnailSize].url
					+ '" alt="' + pic.summary.$t + '" /></a>')
				.appendTo("#picasaStream");
			});
		}
	);
});
</script>

Just change your name in the code from “captainskyhawk” (that’s me!), and it should work!

Finally got a Windows share to share

For years, our main gaming computer (which we call the “Titan”) would just not share with any other computers.

It couldn’t host multiplayer games.

It couldn’t share a printer.

It wouldn’t share files.

You couldn’t access multimedia of any sort over it.

I had absolutely no idea what the problem was — it was a very old Windows XP installation, probably four years or more, and had gone through Windows XP SP1, SP2, and SP3, so there’s no telling.

It might’ve been some service I turned off years ago, or (more than likely) an old remnant  of Norton Antivirus (a horrible, horrible program) that refused to let go.

I noticed that my much newer gaming PC would work just fine, and that it was running the exact same services that the Titan was running, so I was stumped.  You couldn’t even ping the Titan if you wanted to.

So, on a whim, I search for “cannot ping Windows XP computer” on Google, and found this:

Try this to reset TCP/IP in XP:

Click Start -> Run -> CMD

At the prompt type:

NETSH INT IP RESET C:IPRESET.TXT

via Help! Unable to ping machine on the network – Windows NT / 2000 / XP / 2003.

And it worked.  I don’t know what it did, but it worked.  I think it reset completely the way that TCP/IP worked on Windows, because when the Titan restarted, my IP settings were completely reset, but I could ping it. And it shared files.  And it could host games (I think).

Either way, I’m happy!

Various Browser Benchmarks

I’ve been installing/reinstalling/testing a lot of browsers recently, so I thought I’d provide a little bit of data back to the programming community.

I tested on two different computers — my venerable Dell laptop and my largely MSI-powered gaming PC.

Some thoughts:

  • The newest Opera 10 build on Linux does not like the SunSpider benchmark.  Understandably, it’s a benchmark put together by the WebKit browser team, but still — it performed about as bad as I’d suppose Internet Explorer would (were it to run on Linux).  I ran it twice just to make sure, and it was about 10k milliseconds each time.
  • Chromium, whether it’s on Windows XP, or the pre-alpha build I’m using on Linux, is pretty damn fast.  Like scary fast.  Though, like I said, it is their own benchmark.
  • Seamonkey on Linux is consistently faster than Firefox 3.1b3 on Linux.  I have no idea why, since they’re supposed to be powered by the exact same engine.
  • It’s amazing how much faster an older computer (Like my Dell laptop) can feel when you use a browser that’s optimized to render JavaScript faster.  It seriously feels like an entirely different computer.
  • I tried running this test in Internet Explorer 6.0 via Wine, on Ubuntu.  I figured it’s not exactly emulation (since Wine Is Not an Emulator and all), but it kept freezing on one of the “base64” tests, and I got tired of waiting on it and killed the process.  Imagine that.

And now, the benchmark numbers, utilizing the SunSpider JavaScript benchmark (smaller numbers are better, all numbers in thousandths of a second):

Computer #1

Hardware:  Dell Laptop, Pentium 4-M 2.6 GHz, 1.5GB DDR Ram

Software:  Ubuntu 8.04 (x86)

  • 10572.4ms:  Opera 10 Alpha, Build 4214
  • 8435.8ms:  Flock 2.0.3
  • 8171.8ms:  Firefox 3.0.8
  • 5243.6ms:  Firefox 3.1 Beta 3 (Shiretoko)
  • 4701.4ms:  Seamonkey 2.0 Alpha 3
  • 1506.4ms:  Chromium Dev Build

Computer #2

Hardware:  MSI Mainboard, Athlon X2 2.5GHz (Brisbane), 2GB DDR2 RAM

Software:  Windows XP SP3 (x86)

  • 6930.8ms:  Internet Explorer 8
  • 2097.8ms:  Firefox 3.1 Beta 3
  • 952.4ms:  SRWare Iron 2.0 (Chromium)