Jun 082011
 

Easy Content Units usually use JavaScript to write the contents of the unit on your webpage, the trouble with this method is that search engines have JavaScript switched off when they visit your website. This means they never see the contents on the easy content unit, if you have a page with not much content but a nice unit, search engines will not see a lot when they visit. Using the ASP.NET (VB) code below converts the unit and then writes it out to the page before the page is rendered. Because its using ASP.Net, no matter who visits the page, the ASP code will always run, so the easy content unit will be visible to all search engines.

These are the name-space libraries needed.

<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>

I have put this in the page load section, so it only runs on page load. The way code works basically is by calling the unit and then stripping out all the JavaScript that writes to the page using document.write. This then leaves just the bare HTML which can then be written to the page along with any other HTML on the page.

Sub Page_Load(sender As Object, e As EventArgs)

	'Variable declarations
    Dim aSplit, i
    Dim sOutput As String
    Dim objResponse As WebResponse

	'Read the ECU into a variable using a HTTP request
    Dim objRequest As WebRequest = HttpWebRequest.Create("http://www.easycontentunits.com/js_unit.php?ecu_mid=1199&ecu_uid=50564")

	'Get the response from the above request
    objResponse = objRequest.GetResponse()

	'Convert the response into a string using text streaming
    Using sr As New StreamReader(objResponse.GetResponseStream())
        strResult = sr.ReadToEnd()
        sr.Close()
    End Using

	'We now need to get rid of all the JS code

    'Get rid of document.write(unescape("
    strResult = replace(strResult,"document.write(unescape(""","")

    'Get rid of ")
    strResult = replace(strResult,""")","")

    'Get rid of );
    strResult = replace(strResult,");","")

    ' next convert %hexdigits to the character
    aSplit = Split(strResult, "%")
    If IsArray(aSplit) Then
        sOutput = aSplit(0)
        For i = 0 to UBound(aSplit) - 1
            sOutput = sOutput & Chr("&H" & Left(aSplit(i + 1), 2)) & Right(aSplit(i + 1), Len(aSplit(i + 1)) - 2)
        Next
    End If

    'Move finished hex conversion back to original var name
    strResult = sOutput

End Sub

You put the code below on the page where you want the unit to appear.

<%Response.Write(strResult)%>
Jun 072011
 

Getting the sharpest possible pictures from your camera is what most people are after. In this post I will go over how I take images to  get the maximum sharpness. My technique is courtesy of Geoff Simpson Photography and his wonderful workshops. This technique only really works with a tripod,  you can do it hand held but it would have to be a really bright day to maintain a higher enough shutter speed.

 

I use a tripod and a remote release (self timer is fine). I keep my camera in A (Av on Canon) mode 99% of the time, this is Aperture Priority mode. This means I set the aperture and the camera sets the shutter speed, the reason for this is I don’t care what the shutter speed is set at because the camera is on a tripod but I do care what the aperture reads as that helps decide sharpness. If your camera has Mirror Lock Up, then that should be set as well.

 

Set your aperture to 2 stops from the minimum aperture (biggest number), this is where manufactures reckon is the sweet spot for most lenses. Remember the minimum aperture changes on some zoom lenses depending what focal length your at. So at 17mm the minimum aperture might be F32 but at 50mm it might be F22.

 

If apertures confuse you then give www.digital-slr-guide.com/maximum-aperture.html a read.

 

So if your minimum aperture is say F22, then you set your aperture to F11.

 

Now you need to focus your camera onto something in the scene, I try to pick something out that is about one third into the scene. Most of the time this means moving your camera slightly to make sure it locks on with the focus. If you have focus lock, then use that and then recompose the shot. If you have a manual focus override switch, you focus on the point 1/3 in, switch to manual focus and recompose. This is also one of the reasons to use back-button focusing (if your camera supports it).

 

Now you have the aperture set, focusing is locked onto something 1/3 into the scene and your ready to take the picture.

 

You can use self timer or a remote shutter release, either work just fine but I prefer a remote release cord. If you have mirror lock-up on your camera, set that as well (it all helps). Mirror lock-up needs 2 presses of the shutter, the first one locks the mirror and the second one takes the shot. If you are using self timer with mirror lock-up then you should only need to press the shutter once.

 

Hopefully now your images should be a lot sharper, with practise this technique is easy and you won’t even have to think about it.

Jun 052011
 

I written this bit of code for 2 reasons, first was to read whatever was posted onto a Tumblr blog and integrate it into a clients website. The other reason was if Tumblr was to go down, the blog page would still work due to the caching on the Tumblr data.

I always choose Tumblr when setting up a blog for a client where no one really looks direct at the blog, its more a easy way of letting the client create blog post and it magically appears on their website.

Anyway, enough rambling here is code. Please remember there is probably a million ways to do this and mine might not be the best but it works.

 

Header – This tries to load the XML from tumblr and store it in a file on the webserver. It then checks to see if a cached file/xml is present, if not it makes a cached file/xml out of the file stored on the webserver. The way the cache is created using a dependency, so if the file changes, the cache will change. It then loads the cached file/xml in a var called Posts.

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Linq" %>

Dim Posts As XElement
Sub Page_Load(sender As Object, e As EventArgs)

Try
'Read Tumblr Feed and save it locally
Dim xmlMasterUpdateDoc As New XmlDocument()
xmlMasterUpdateDoc.Load("http://*nameofyourtumblrblog*.tumblr.com/api/read")
xmlMasterUpdateDoc.Save("*somewhereonyourhostingspace*\blog.xml")

Catch xmlEx As XmlException
'Catch any XML error and display it.
Response.Write("XML Exception Thrown -> " + xmlEx.Message)

Catch eX As Exception
'Catch the error and display it.
Response.Write("Exception Thrown -> " + eX.Message)
Finally

End Try

If Cache("tumblrXE") is Nothing then

'There is no tumblrXE item in the Cache,  so load it from the local file
Dim tumblrResponse As XElement = XElement.Load("*somewhereonyourhostingspace*\blog.xml")

'Add it to the Cache and make it dependant on the local file (so it if changes the cache will)
Cache.Insert("tumblrXE", tumblrResponse, New CacheDependency("*somewhereonyourhostingspace*\blog.xml"))

End If

Posts = Cache("tumblrXE").Element("posts")

End Sub

This next bit of code, goes through all the posts and depending on the type displays them. I have only done regular, link and image post types.

<%
'if this value is 0, there are no posts.
If Posts.Attribute("total").Value <> "0" Then
'loop around all the posts
For Each itemElement As XElement In Posts.Elements("post")

If itemElement.Attribute("type") = "link" Then

Response.Write(itemElement.Attribute("date").Value)
Response.Write(itemElement.Elements("link-text").Value)
Response.Write(itemElement.Elements("link-url").Value)

End If

If itemElement.Attribute("type") = "photo" Then
          Response.Write(itemElement.Elements("photo-caption").Value)
          Response.Write(itemElement.Attribute("date").Value)
          Response.Write(itemElement.Elements("photo-link-url").Value)
          Response.Write(itemElement.Elements("photo-url").Value)
          Response.Write(itemElement.Elements("photo-caption").Value)
End If

If itemElement.Attribute("type") = "regular" Then
      Response.Write(itemElement.Elements("regular-title").Value)
      Response.Write(itemElement.Attribute("date").Value)
      Response.Write(itemElement.Elements("regular-body").Value)
End If

Next

End If

As I say, not sure if it’s the best way but it works for me so hopefully has given you a helping hand to implement your own solution.