Git error on ‘git add’ on OS X 10.8.1

So you get the following error:

error: insufficient permission for adding an object to repository database .git/objects

Something has happened to the .git directory within your repository and the database can not be written to. So to fix this do the following command inside your repo.

sudo chown -R  username:staff .git/

Note: Change username to your OS X username.

 

Google Maps API v3 – Fit map bounds to all markers

This is a basic example of how to use google maps api v3 to fit a map’s bounds to all of the markers on the map. It’s almost an exact copy from Alexis Bezverkhyy’s site. I basically put this here for my own use, but hopefully it helps you out.

// Lets create our map
function initMap() {
    //...
}

// Setup markers
function initMarkers() {
    //...
}

var map;
var bound = new google.maps.LatLngBounds();
var markers = new Array();

// On dom ready, lets set things up
$(document).ready(function() {
    initMap();
    initMarkers();

    // Lets loop through the markers and get it's position and extend the bounds of the map
    for(var i in markers) {
        bound.extend(markers[i].getPosition());
    }

    // Now set the bounds for the map
    map.fitBounds(bound);
});
 

Simple Engine

So one of my pet projects is Simple Engine. Its kind of a cross between wordpress and static html files. It allows you to do nice seo urls and manage a global template, so making changes is not a pain. Anyways check it out, let me know what you think. It’s helped me with several sites big and small.

 

 

New site, new year.

Well its a start of a new year. What better way than start it off than a new design. I am slowly working on the design of the site as I have time. So keep checking back for more updates.

 

Posting JSON with jQuery and PHP

After looking around the net some, and having this issue before, I decided to put this up for anyone who might be having the same trouble as I once had. Posting JSON with PHP can be a bit tricky if it’s your first time doing this.

So for starters, lets download some scripts we’ll need to make this work.

  • https://github.com/douglascrockford/JSON-js/blob/master/json2.js
  • http://code.jquery.com/jquery-1.6.4.min.js

json2.js

This file will be used for taking a javascript object and converting it to a string.

jQuery

This is my javascript library of choice. So for this example I will be using this.

Javascript Time!

So lets get our hands dirt with some javascript. Here is a simple AJAX post using javascript and using the JSON.stringify to convert our object to a string so we can post it. While I don’t actually show it. Make sure to include the json2.js file and in this case, jQuery on the page.


// Declare a variable
var jsonObj = {demo: 'this is just a simple json object'}

// Lets convert our JSON object
var postData = JSON.stringify(jsonObj);

// Lets put our stringified json into a variable for posting
var postArray = {json:postData};

$.ajax({
    type: 'POST',
    url: "http://somedomain.local.com/phpfile.php",
    data: postArray,
    success: function(data){
        // Do some action here with the data variable that contains the resulting message
    }
});

PHP in The House

In our php file, we can process the post variable. First we check and see if we actually have post variable. Next, we need to strip the slashes out of the string which were put in for transport. Then we just run the json_decode php function. After that we can access the php object and use it however we like.


if(isset($_POST["json"])){
    $json = stripslashes($_POST["json"]);
    $output = json_decode($json);

    // Now you can access your php object like so
    // $output[0]->variable-name
}

This is a pretty basic and watered down example but hopefully it will help you.

 

Lion on Rails

So I am always interested in working on a rails app, but I always run into the same issues. Hosting. I am hoping with my little know how, and my awesome abilities are hacking the the English language to pieces I can help guide you through setting up a rails environment on your OS X machine.

So for my setup, I am using a new Mac Mini with 8GB of Ram running Lion. Hardware requirements are not that important though, so even if you have a 5 year old machine, you’re good to go. We’re programing, not trying to play Crysis.

Here are a couple things you need to download.

Pow

http://pow.cx/

Is a self contained enviroment for running ruby on rails applications.

Powder

https://github.com/Rodreegez/powder

It is used for turning off and on POW with ease. This is especially helpful if you are wanting to run MAMP as well, since both of these apps like to play with your port 80 and hosts file.

Xcode

http://itunes.apple.com/us/app/xcode/id448457090?mt=12

Download and isntall the latest version of Xcode as we will need this to update your ruby version locally.

I ran out of time to finish this write up tonight, but I should be able to finish it over the course of this week. So check back here for a completed version soon.

 

Posting form data with Curl

So this is something I struggled with for whatever reason. Taking form data that  was posted and re-posting to another server. I am just going to post up the code first and then kind of step through it.

$ch = curl_init();

// Lets setup the data we need to pass
$postValues   = array('postedData' => $someArrayOfData);

// define the URL for upload file
curl_setopt($ch, CURLOPT_URL, 'http://yourdomain.com/api/somefile.php');
curl_setopt($ch, CURLOPT_POSTFIELDS, $postValues);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_ENCODING, "");
$response = curl_exec($ch);
curl_close($ch);

header ("Content-Type:text/xml");
echo($response);

So basically what is happening is at first we build an array of all the values we want to post. Then we pass that variable into the config for Curl. At that point we set, the URL, and the “RETURNTRANSFER” setting, letting Curl know we want any response back from the server that we posted to. Once that is done, we can just set the header and echo out the results, or we could pass that info back into a variable to be used elsewhere.

While this is pretty brief, it was more so just to get a couple thoughts down for myself. if you have any questions though, please feel free to leave a comment or jsut email me.

 

Still around…

Been so damn busy the past 3 months, I almost forgot I have a website!

I have a ton of things I should add on here but I keep forgetting. I will try to add some new things soon.

Ok, back to working, or sleeping I guess.

email

 

CSS word-wrap on a legend

Legend elements are extremely tricky to get styled right across browsers. I’ve come across the issue on several occasions where I need the text inside the legend to wrap lines when it’s too long. Here is an example:

<fieldset>
  <legend class="someclass">Some text that needs to wrap because its too long.</legend>
</fieldset></code>

All we need to do now is just wrap the text inside the legend within a span tag like so:

<fieldset>
  <legend class="someclass"><span>Some text that needs to wrap because its too long.</span></legend>
</fieldset>

Add some css to target the span:

legend.someclass span {
  word-wrap: normal;
  white-space: normal;
}

That’s it!

 

Shelby GT500 Fog Light Replacement Bulb

Updated: Ford changed the part number for this recently. I have added the new one below.

This is more of a post to myself so I have someplace to keep it, but if you are looking to replace a burnt out fog light bulb on your 2007-2009 Shelby GT500 then this might come in handy for you.

The bulbs are completely different from the regular Mustang GT, so if you go into AutoZone, their little computer will tell you that you need a 9145 Light bulb which is incorrect. As far as I know you can only get them from Ford for like $30 a piece.

Part Number: 8L8Z-13466-B (One Bulb and Socket Assembly)
Part Number: 8L8Z-13N021-A (One Bulb and Socket Assembly)

If anyone else knows of where to get replacement ones besides Ford, please let me know.