git problems with phpfog, remote end hung up unexpectedly

If you have issues with phpfog, trying to get your repos to clone to your local, so you can upload code, there is a very subtle problem you may run into that I discovered after much beating my head against the wall. The problem was “I am an idiot.”

If you’re using the command line, this is how to get around errors like these:
Fatal: The remote end hung up unexpectedly
R access for yoursite.phpfog.com DENIED to

PHPFOG unwisely does not tell users about this small distinction in the hostname and their server name. This is especially a problem when using the multiple SSH keys setup they recommend in the support pages.

To clone a repos, beware that phpfog is the servername you connect to (the one with git01 on the front) and your servername (the one at the end of this command below) is phpfogAPP. I kept getting this wrong because they should have either alerted me to this, or not made the damn things so similar, like start it with something else.

git clone git @ git01.phpfog.com : yoursite.phpfogapp.com (don’t leave in the spaces, I did this for readability)

be sure to type it correctly, that was my problem. I also had the further abstraction of listing all my rsa keys in the ~/.ssh/config file on the mac, so it was harder to troubleshoot, since my 2 hostnames were not in the same declaration, the config file finds the right rsa id based on the servername alias you enter in the git clone command.

Let me know if you have trouble and I will see if I can help! Enjoy!

PJAX: Speed up every link on every page

This is one of the most amazing jquery functions I’ve seen in a while. It loads your HTML or content that is dynamic without reloading the unchanged bits, making page loads lightning fast. ON that, does anyone know the speed of lightning (and no, Cars 2 is not what I’m asking)?

You’ll need jquery included on your page already (in the head tag). This code uses the latest JQuery 1.6.1 from Google’s CDN (Content Delivery Network) but you can use your own local copy instead if you wish.

 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>

After this, you simply need to decide what links will trigger this, to load pages faster, and the content block the new page should be inserted into.

If you’re doing all a tags (all links everywhere on your site, without scrutiny, here is the code for that (put this in the head tag, after you include jquery):

 
<script type="text/javascript">
     $(document).ready(function(){
          $('a').pjax('pjaxtarget');
     });
</script>

And finally, make sure the div or other block element (li, span, etc.) is in your page, so the PJAX can insert the page content.

 
<div id="pjaxtarget">
     <!--the inserted content will be put here and wipe out anything that is already here-->
</div>

Done right, all your links should load super fast, as it only grabs the parts that are dynamic and leave the other elements alone, without loading them.

PHP: Gzip compression made easy

If you want to speed up your php pages with minimal trouble and maximum results, do this:
Source: [Webcodingtech]

Put this code in your main header or template file, before EVERYTHING, even doctype.

<?php
function print_gzipped_page() {
 
    global $HTTP_ACCEPT_ENCODING;
    if( headers_sent() ){
        $encoding = false;
    }elseif( strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false ){
        $encoding = 'x-gzip';
    }elseif( strpos($HTTP_ACCEPT_ENCODING,'gzip') !== false ){
        $encoding = 'gzip';
    }else{
        $encoding = false;
    }
 
    if( $encoding ){
        $contents = ob_get_contents();
        ob_end_clean();
        header('Content-Encoding: '.$encoding);
        print("\x1f\x8b\x08\x00\x00\x00\x00\x00");
        $size = strlen($contents);
        $contents = gzcompress($contents, 9);
        $contents = substr($contents, 0, $size);
        print($contents);
        exit();
    }else{
        ob_end_flush();
        exit();
    }
}
 
ob_start();
ob_implicit_flush(0);
?>

Then put this after everything, at the very end of your page.

<?php print_gzipped_page(); ?>

ASP.NET: Nested Web.config files in conflict

If you have a child app configured in IIS, and you don’t want the web.config of the parent application to affect your child app, here is how you tell the parent app’s config file to go chill down by the river alone.

Example:
blah.com/web.config <= Parent file
blah.com/child/web.config <= child file

Add this code around your section IN YOUR PARENT web.config.

<location path="." inheritInChildApplications="false">
     <system.web>
         ...whole bunch of other stuff is here already (most likely)
     </system.web>
</location>

This will make the parent ignore the child, and not try to handle it and mess with it. Boy don’t you wish you had a parental mute button and cease and desist they couldn’t remove as a kid? That would be nice.

WordPress: GeoLocation JS Plugin

Have you ever needed to change a background image based on the state or IP address the visitor comes from? Here is the fastest, easiest, and most effective WP Plugin for that. I was blown away with how fast I got what I needed. This uses the very awesome MaxMind GeoIP web service.

WP GeoLocation JS Plugin

This plugin uses “the MaxMind GeoIP Javascript Web Service to return the Country, Region, City, Latitude, and Longitude for your web visitors…” (from the plugin’s description on WordPress.org.

It fills js variables so you can use them on your pages, or via WP shortcodes. Here is something I built using it on a site to change the homepage background based on the state (RegionName) that is detected using jQuery.

The GeoLocation plugin fills these variables that can be used in javascript, see the mmjsRegionName (State) in the code below:

  • mmjsCountryCode
  • mmjsCountryName
  • mmjsCity
  • mmjsRegion
  • mmjsRegionName
  • mmjsLat
  • mmjsLong
  • mmjsPostalCode
  • mmjsIPAddress
// must be inside <script> tags
$(document).ready(function(){
     if(mmjsRegionName=="Colorado"){
          $('#bg').html('<img id="bgimg" src="wp-content/themes/acme/style/images/denver.png">');
     }else{
          $('#bg').html('<img id="bgimg" src="wp-content/themes/acme/style/images/chicago.png">');
     }
});

IIS: HTTP Error 500.19 – Internal Server Error

If you’ve ever seen this error, you probably pulled your hair out (if you still have some) and can’t figure out why IIS won’t just serve up your page. What is this madness about “There is a duplicate ‘system.web.extensions/scripting/scriptResourceHandler’ section defined” nonsense? Well, this is one of those things that is super simple to fix (most times) but can cost you a day of development to figure out what is wrong.

 

 

 

 

 

 

 

 

 

 

 

All you have to do is change the Application Pool’s .Net Framework version from 4.0 to 2.0. Caveat: Only do this if you need to use 2.0 (which also includes 3.5, since 3.5 is 2.0 extended, essentially), if you need 4.0 you normally won’t see this error, as it has to do with the web.config being the wrong version for the configured IIS version. Here’s how to fix it:

Open IIS Manager and Click “Application Pools” and find the one that matches your website. ACME Co, for example. Double-click it and you’ll get the Pop-up window. Change the .Net Framework version to 2.0.50727. It should look like this:

 

 

 

 

 

 

 

 

 

 

 

HTML: Remove blue border on links with images

Sick of that blue or purple box around your linked images? Here’s how to kill that stubborn thing. Simply place this bit of code in your CSS file or inside

tags inside the head tags on your page. This applies the transparent “color” to all the states of a link, visited is usually purple, hover is as the mouse is over the link or image, active is any link not yet clicked.

The css file version

     a,a:visited,a:hover,a:active{color: transparent;}

The style-in-head tags version

<head>
     <style type="text/css">
          a,a:visited,a:hover,a:active{color: transparent;}
     </style>
</head>

ASP.NET: How to avoid IE8 issues with one line of code

Internet Explorer is nearly always half-baked, never having decent support for the latest language syntax and causes more problems than it solves. IE8 is no exception, really causing ridiculous problems that it shouldn’t. Developers spend days on things that should normally take minutes, because Microsoft teams make a habit out of ignoring best practices and listening to their users.

Here’s how to make IE8 behave as IE7, which eliminates most of the strange display and other issues in IE8 that shouldn’t be there. Stick it to the man with this one line, placed inside your tags.

<head>
     <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
</head>

Confessions of a dummy: partial classes

So I am really dumb sometimes. Other times it is my obliviation to the obvious, otherwise known as true ignorance and unexplored knowledge, but certain things CAN be done in code that are allowed but should not be done. For example, there should only be one public partial class per page (as far as I can tell) and you can add multiple control types with it, for example:

instead of having 2 declarations in the page, it should look more like this:

public partial class App_UserControls_forms_Contact : System.Web.UI.UserControl, IGenericContent

Where the iGenericContent is added onto the end, making it a part of the partial class’s member list (I think). How you learn this stuff I have no idea. I’ve read documents, done searches, took a massive class on c# and .net and still don’t know a lot of what talented programmers consider basic easy common knowledge. I also have a learning disability which makes this hard as well.

I am not dumb, and programmers are not generally forthcoming when it comes time to help someone else out, especially not in the .net world. Open source is much more friendly and well, open to collaboration, even when the collaboratees are dumb as a box of sunblock. That whole teach a man to fish thing…anyway.

Any suggestions on how to learn all this “ethereal knowledge” crap easily without the head-banging?

Rails: What is new and awesome in Rails 3.1 beta 1

The new hotness of 3.1 beta 1 is the concept of Asset Template Engines (ATE if you condense that) which basically allows you to not have to deal with piles-o-files with javascript, css, images, etc. You can still have tons of them, but now you don’t have to figure out how to include them all. Rails does it for you.

This is accomplished via a filetype specific application “controller” which handles all the files in the respective folders and is consumed into the core guts of rails 3.1 by using “load path“, which I don’t fully get yet, it’ll come soon. I’m riding on a very sketchy 3-5 ish hours of sleep due to kiddo 4.0 not sleeping and being 3 weeks old. That never equates to prod quality baby sleeps. The framework must mature some more for that. Oh yeah, mention: …is prone to tangents. About babies and other stuff. Oh look, in the corner, stuff! Cool.

The new locations for all your fileage makes a lot of sense, place css, js, and img files in app/assets/javascripts, app/assets/stylesheets, and app/assets/images, not respectively. Once you do this, the application.js and .css files will take over. Images doesn’t have one.

The other things now included in rails 3.1 is the CoffeeScript and Sass languages, and though they look sexy like a backyard swingset, you can easily exclude them by adding the obligatory # in front the of their declaration in the gemfile, like remming out batch script code in the good old (albeit ruby free) days. You can do the same thing with jquery-ruby, and use prototype instead, but of course stupidity is your problem on your own time. NOT using jQuery would need a decidedly good reason, which I can’t conjure even not sleep-deprived.

In general, the move to split off the js frameworks from rails and head the ‘vendor’ route, like CakePHP and tons of other frameworks have is an excellent one. That way everyone gets what they want and no one is tied down. Defaults with override-able preferences is a development pattern. It also helps noobs trying to learn the language.

Here’s the Keynote by DHH at RailsConf 2011

YouTube Preview Image