Friday, 8 February 2013

How to use an Apple USB Ethernet Adapter to replace a broken ethernet port on a Mac

The iMac at my work has a problem with it's ethernet port - the cable will not stay plugged in and it can lead to the connection being lost. The ethernet port seems a common 'weak link' with Apple hardware.

We bought a Apple USB Ethernet Adapter (MC704ZM/A), to replace it.

Setting this up was not straightforward, for starters they do not bundle the driver on Mountain Lion for the iMac!

Luckily I've got a Mac Mini at home, so I could copy the driver from there.

The steps you should take are:

  • Find/Download AppleUSBEthernet.kext file (will be within IONetworkingFamily.kext - full path to this is below)
  • In Finder open System > Library > Extensions
  • (To open a .kext file, right click > Show Package Contents)
  • Open /System/Library/Extensions/IONetworkingFamily.kext/Contents/PlugIns/
  • Copy AppleUSBEthernet.kext into the folder IONetworkingFamily.kext/Contents/PlugIns/
  • You will be prompted for your administrator password.
  • Open Applications > Utilities > Disk Utility. Then "Repair file permissions"
  • Open Applications > Utilities > Terminal. Run the following command
sudo kextload /System/Library/Extensions/IONetworkingFamily.kext/Contents/PlugIns/AppleUSBEthernet.kext



  • You will be prompted for your administrator password.
  • Open Applications > System Preferences > Network. You should now have 'USB Ethernet' as a connection on the left hand side. If not you can add it with the + at the bottom of the left pane.
  • You may find as I did that once plugged in your USB Ethernet will show as connected, but you won't be able to use the internet. If this happens, use the Assist Me > Assistant within Network and it should fix it for you.
All being well, you should have replaced your temperamental physical Ethernet port with a USB one.

(Update) This solution does not work after you have restarted your mac.
You need to run


sudo kextload /System/Library/Extensions/IONetworkingFamily.kext/Contents/PlugIns/AppleUSBEthernet.kext

again to load the driver.

I have set up a Unix executable which runs this command on startup. System Preferences > Users and Groups > Login Items. This is far from ideal, as the user is prompted for their password to run this.

Luckily we don't restart the Mac very often, but I will search for a more elegant solution.

Any Mac experts out there who know how to load this driver on startup in a more elegant way, please let me know!

Monday, 10 December 2012

Android - Disabling enter key press for a text editor

//A bug where hitting enter after entering text in a EditText box would clear the box
//the code below prevents this
//disable enter key press
EditText txtEdit = (EditText)view.findViewById(R.id.text_input);
txtEdit.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (event != null&& (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
InputMethodManager in = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
in.hideSoftInputFromWindow(v.getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
return true;
}
return false;
}
});

Wednesday, 31 October 2012

Disabling dates in JQueryUI Datepicker - hooked up to an MVC 3 controller action to provide dates.

//method in controller to return list of dates.
public ActionResult GetDisabledDates(string id) {
//get list of dates separated by comma ...
return Json(new {disabledDatesArray = result }, JsonRequestBehavior.AllowGet);
}

$(document).ready(function () {
 //Call GetDisabledDates in the controller, passing id
 $.getJSON("GetDisabledDates", { id: "identifier" },
 function(data) {
 //write date values to hidden field for retrieval later.
 //and to ensure we only have to call server side method once. $('#hiddenDates').val(data.disabledDatesArray); });

 function IsDateAvailable(date) {
 //we have to pad the date, to ensure we can compare with the dates we retrieve from serverside.
 var dmy = padDate(date.getDate()) + "/" + padDate(date.getMonth()+1) + "/" + date.getFullYear();
 //remove dates in array from datepicker. if (IsDateInUnavailableList(dmy)) {
 //date exists in list of those not allowed. return [false,"","Unavailable"]; } else { return [true,"","Available"]; } }

 //pad out dates to allow comparison, 1/1/2012 will become 01/01/2012
 function padDate(i) { return (i < 10) ? "0" + i : "" + i; }
 //define datepicker
$("#datepicker").datepicker({ dateFormat: 'dd/mm/yy', minDate: 0, beforeShowDay: IsDateAvailable });
EnableOrDisableSaveButton();


$("#datepicker").change(function () {
            EnableOrDisableSaveButton();
        });



 function IsDateInUnavailableList(date) {
 var dateValues = $("#hiddenDates").val();
 //convert back into an array.
 var dateArray = dateValues.split(",");
 //check date against dates in array
 if ($.inArray(date, dateArray) < 0) { return false; } else { return true; } }

 // Function to enable or Disable the Save Button
 function EnableOrDisableSaveButton() {

 var date = $('#datepicker').val();
 // Now enable the button if the above two values or not empty
 if (date != "") {
 //prevent save button click if date selected in list of disallowed dates.
 if (IsDateInUnavailableList(date)) { $("#Save").attr("disabled", true); }
 else {
 $("#Save").attr("disabled", false); } }
 else {
 $("#Save").attr("disabled", true); } }

 //hidden field to store date values.
<input id="hiddenDates" name="hiddenDates" style="display: none;" />

//datepicker
@Html.TextBoxFor(m => m.Date, new { id = "datepicker", @maxlength = 10, style = "width:65px" })

<input id="Save" title="Click here to save" type="submit" value="Save" />

Tuesday, 12 October 2010

Intellisense.

Intellisense in visual studio decided to turn itself off for my project.

The following blog post tells you how to fix it...

Intellisense not working in Visual Studio...
"IntelliSense is Microsoft's implementation of autocompletion, best known for its use in the Microsoft Visual Studio integrated development environment. In addition to completing the symbol names the programmer is typing, IntelliSense serves as documentation and disambiguation for variable names, functions and methods using metadata-based reflection." (Wikipedia)
So, I can't quite remember when exactly Intellisense stopped working for me in Visual Studio 2008, but I know I have been without (automatic) Intellisense for quite a while.When typing a dot after an object or method, it used to just show up automatically... I could however have it come up by pressing and eventually got in the habit of just doing that when I needed it, without attempting to find out exactly why it was broken in the first place...
So, several months later, I stumble upon an entry by Richard Fennell, who explains how to fix it. I thought I'd post it for when it breaks again, I know where to find the answer...

In Visual Studio 2008, select Tools > Options > Text Editor > All Languages. Ensure that the checkboxes in the Statement Completion section are actively checked (not grayed out).
That is it!. Click Ok and try it.

By Miguel Moreno
http://miguelmoreno.net/post/Intellisense-not-working-in-Visual-Studio.aspx

Wednesday, 6 October 2010

Image Copyright. C#

I needed to write some code to prevent images being copied.
Although not ideal (user can still view source, or use PrintScreen), this at least makes it harder for users to copy images directly.

public static void PreventRightClickOnHtmlControl(HtmlControl htmlControl)
{
htmlControl.Attributes["onmousedown"] += "return false";
htmlControl.Attributes["onclick"] += "return false";
htmlControl.Attributes["oncontextmenu"] += "return false";
}

Page.ClientScript.RegisterClientScriptBlock(GetType(), "DisableImageDrag", "document.ondragstart = function () { return false; };", true);

Wednesday, 8 September 2010

‘Sys’ is undefined error – How to solve

This week, while testing some pages featuring AJAX controls using IE6, I encountered the dreaded ‘Sys’ is undefined javascript error, which caused the AJAX on the page to stop working.

Normally when encountering such an error, one would Google and then attempt the suggestions. From the abundance of results returned it seems that this error is quite prevalent and also can be quite tricky to solve as there are multiple differing solutions – most not giving as much detail as would be helpful. A lot of solutions dealt with individual web.config lines, which did not fix the error.

The key things to note in my experience of this error are:

· The error only occurs when running in IE6 - when debugging locally using IE7, the error does not occur.
· The application uses .net 2.0 with ASP.net AJAX Extensions 1.0.
· The application uses master pages.
· I am not debugging the website locally; it is running off of a server.
· Due to the use of the application when it goes live, it must work on IE6 without any browser upgrades.

The first thing to do is run Fiddler to see exactly what is causing the error - in my case an error is caused by ScriptResource.axd. Unfortunately, this did not provide me with a more comprehensive set of search results. I simply had to read through as many articles as I could until a solution presented itself.

After reading this article, I noticed that each page had an individual script manager. I decided to remove these and add one to the master page instead. Even if this didn’t immediately fix my problem, it would clean up the code and make it more manageable.

This article also proved helpful, as a comment gave a link to a local example file of a correctly configured AJAX web.config - C:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\v1.0.61025\web.config (this file may be in a different location depending on .net version)

This would prove useful, as I could compare every line within the example to the application’s web.config file and ensure that every line existed correctly.

The most important line was:



When compared to the application’s web.config, the last section was missing. When this line was amended, the javascript error was fixed, and the AJAX controls worked correctly again.

Friday, 3 September 2010

Sharepoint

I have recently started developing webparts using Sharepoint 2007. Some *fun* things I have encountered along the way...

Styling in sharepoint was tricky, until I started using 960 Grid System

I wrote a method to take in either one or two controls, and a main div to hold them. Styles for the control divs can also be passed.

I then wrapped each control in a div, gave it the gs class it needed i.e. "grid_12" as well as any styles passed in.

Then I added these divs to a container div and returned this so it could be styled independently.

(Main Div Holds Container Div, which holds Control Divs.)