neynar's place of webtronika

Quantum GIS - Using regex_replace

I found using regex_replace(string, search regex, replaced value) a little very confusing the first time I played with it, so as to avoid making the same mistake twice, here are my notes around this crazy function.

Firstly the replaced value is the opposite to what you are searching for. It sort of makes sense if you consider the replace(string, before, after) function, where the before is what you are searching for, and the after is what is left. 

Secondly, you’ll need to double backslash any regex syntax. For example \w, \s, \d.

An example:

Assume we have a column called Address, and our data is comma separated: 12 Someplace Street, Some Suburb

We want to create two new columns, one to hold the street name and number and the other the suburb.

To get the street value, we will use: 
regexp_replace( “Address” , ‘,([^,]+$)’, ”)

While to get the suburb value, we will use:
regexp_replace( “Address” , ‘^([^,]+,)’, ”)

Anway, I hope this helps shed some light on a potential problem someone is experiencing.


HTML5 Cross Browser Polyfills

Via https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-browser-Polyfills

So here we’re collecting all the shims, fallbacks, and polyfills in order to implant html5 functionality in browsers that don’t natively support them.

The general idea is that: we, as developers, should be able to develop with the HTML5 apis, and scripts can create the methods and objects that should exist. Developing in this future-proof way means as users upgrade, your code doesn’t have to change but users will move to the better, native experience cleanly.


Android: Using LocalBroadcastManager for polling

I’ve been developing an Android application that uses the magnetic sensor built in to my mobile phone. The SensorManager Class implements its own SensorEventListener that receives system messages whenever the sensor: onAccuracyChange, onSensorChange and other required methods onPause, onResume, onDestroy.

In my application I incorporated this class in to a singleton class, but needed to send the sensor updates back to my main activity. My initial thinking was to create a thread in the main activity and retrieve the results this way. However, it seemed a little overkill, since the SensorManager class already seemed to run its own thread.

A solution to my problem was to use the LocalBroadcastManager Class to send messages from my singleton and then handle the message in the main activity. This class uses the same concepts found in BroadcastReceiver Class, but restricts the messaging to local objects instead of across applications. 

This is how I did it:


CSS IE hacks

Yup, love it or hate it, Internet Explorer 6,7,8 are here and they’re not going away as quick as we’d like them to. There are a bunch of different ways you can target specific browser vendors from using conditional statements, expressions or Javascript. But a method I’ve never seen before - using _underscore and *stars before the selector - seems to work quite well.

Take a look at Brian Cray’s post on targeting IE6 and IE7 with 1 extra character, to get the low-down.


Showing and hiding content to editors in SharePoint 2010

There are times when I need to show content specifically to editors and publishers - things like instructions or formatting tips - but hidden to public users. In SharePoint there are a couple of ways to do this, but one method is using PublishingWebControls:EditModePanel with the PageDisplayMode attribute.

For example, if I wanted to add some instructional text for editors to see on the page I could add a <p> // content </p> block inside the PublishingWebControl tag:

<PublishingWebControls:EditModePanel runat=”server” PageDisplayMode=”Edit” SuppressTag=”true”>

<p>Instructional text</p>

</PublishingWebControls:EditModePanel>

The above example will show the instructional text only when the page is being edited; that is, the text fields are available and edited. To show the instructional text to editors, even if the page isn’t in edit mode, add another block with the PageDisplayMode set to display. For example:

<PublishingWebControls:EditModePanel runat=”server” PageDisplayMode=”Edit” SuppressTag=”true”>

<p>Instructional text</p>

</PublishingWebControls:EditModePanel>

There are a bunch of different methods and ways that content can be hidden or shown depending on the user’s rights. Chris O’Brien has an excellent article: Great controls to be aware of when building SharePoint sites, which goes into detail about each of these.