Moved to: WoodyHayday.com
Woody Hayday

Fresh Ideas

Hi there! This is my old blog, I don't hang around here much.
You can now find me trying to mix things up here:
Visit WoodyHayday.com Subscribe To My Email List

MySQL datetime examples – first/last day of the year – dates and unix-times

For some reason I had an abstract memory of SQL SERVER 2000, timestamps and pain. Who knows why. Perhaps its a faulty memory. lol. Anyhow working with timestamps in MySQL/MSSQL these days is nothing short of simple. With MySQL Workbench free its ridiculous how far the barrier of entry for database design has come, its now all pleasant schema’s and error messages that make sense, gone are the days of spending half the time fixing/navigating the database system, they just work now (99% of the time) what a lucky generation of programmers! Anyhow here’s some datetime examples that you might find useful:

Get last day of last year – obvious, but still (+1 this for first day):

SELECT DATE(CURDATE()- INTERVAL DAYOFYEAR(CURDATE()) DAY);

And how useful… FROM_UNIXTIME takes a unix timestamp and makes it a friendly datetime, its like they KNOW I am coding for facebook data acquisition…Anyhow…

To make a GMT UNIX time-stamp for the first day of this month:

SELECT UNIX_TIMESTAMP(CONVERT_TZ(DATE(CURDATE()- INTERVAL DAYOFMONTH(CURDATE()) DAY), '+0:00', 'SYSTEM'));

You can switch out the dates obviously, and there are probably other ways, still, mostly pain free.

Posted in Snippets, SQL Server, Transactional SQL, Web Development, Web Technology Tagged , , , , , , , ,

Fix/Hack to make AutoSuggest JQuery Plugin work

When I came across Drew Wilson’s flashy JQuery Autosuggest plugin I happily downloaded the code and started using it within a recent project, but as I used it more and more I kept hitting a bug – don’t know if its just the version of JQuery I was tied to using or whether everyone using the pretty plugin suffers it. Either way there was peculiar happenings when removing elements, they would remove 75% of the time, but the other 25% they would remove only to not maintain the associated CSV list of objects properly.

Irritating when the thing looks so pretty out of the box. So rather than opt for one of the non-pretty options I just hacked it. Brutally I just added code to maintain an input as a csv, it needs fixing really but this does work, for now.

Click here to download my hack/fixed version which maintains a separate csv (in a designated ID – search replace “csvHolder” if you want to change its ID.)

Hopefully Drew can update his plugin so it works out of the box, its a really useful plugin.

Note: This rar includes my csv quick maintaining functions which are required.

Posted in Javascript, Web Technology Tagged , , , ,

Maintain a CSV with Javascript – keep a hidden list

The situation: Want to build a comma separated list of int’s (or whatever) client-side, in javascript, remove/add items on the fly using JS. Well these tiny functions below are what I use, useful when you just need to get a clever form / app input done.

Using the below you can add/remove items to an input which acts as a csv holder, should be self explanatory, get and set are just shorteners.

function get(a){ //small get
	if (typeof a != "undefined") {
		return document.getElementById(a).value;
	} else { 
		return '';
	}
}

function set(i,v){ //small set
	document.getElementById(i).value = v;	
}

function append(i,v){ //small append
	set(i,get(i) + v);		
}

function appendTocsv(i,v){ //small append csv
	if (get(i).length == 0){
		set(i,v);	
	} else { 
		append(i,', ' + v);
	}
}

function incsv(id,v){ //check a csv (in element with id) for a value (v)
	
	var csv = get(id);
	var csvArray = csv.split(', ');
	var found = false;
	
	if (csvArray.length > 0){
		
		for (i = 0; i <= csvArray.length; i++){
		
			if (csvArray[i] == v){ found = true;  }
			
		}
		
	}
	
	return found;
		
}

function removeFromcsv(id,v){ //removes a val from csv
	
	var csv = get(id);
	var csvArray = csv.split(', ');
	var removed = false;
	var endString = "";
	
	if (csvArray.length > 0){
		
		for (i = 0; i <= csvArray.length-1; i++){
		
				
			if (csvArray[i] == v){ removed = true;  } else { 
			
				if (endString.length > 0){ endString += ', '; } 
				endString += csvArray[i]; 
			
			}
			
		}
		
	}
	
	set(id,endString);
	
	return removed;
	
}
Posted in Javascript, Snippets, Web Development Tagged , , ,

Facebook time in php – Facebook uses GMT not PDT/PST?

I don’t know whether its purely related to my location when I am calling facebooks’ graph API or what, but all the talk about what timestamps facebooks API returns seems to be wrong. Perhaps they’ve changed something, perhaps they are re-adjusting them just for me. If its the latter I wonder why they are giving me GMT when I am in Belgium? Is it based on the USER?

Antique Clock Face
Clock Face by tibchris
Facebook Time in PHP, who the what where?

If you haven’t tried pulling anything time-sensitive out of the graph API yet, don’t, that’s my advice. There is not a single bit of coherent explanation as to how the API hand’s out times, when I first researched it I had written on my pad “Pacific time”…great, did my past (possibly beer holding) self not remember that Pacific time is one thing half the year and another the other half? PDT/PST? Obviously not. What’s more, now when I check (post something on a page, grab it with graph API) – its giving me GMT+00 times, WHEN I’M IN GMT+01.

 

All I can work out is facebook have either been pleasant enough to convert the time to the users original registration locale (likely, and pleasant) and not noted it down ANYWHERE publicly, or they have chosen to use GMT. Probably the former, either way – facebook developers – we need a better solution for working with facebook times.

Posted in Facebook Pages, PHP, Projects, Social Media, Web Development Tagged , , , ,

Unable to drop JQuery sortable onto empty list? Hack solution

The problem: You have a multi column (or area) JQuery UI Sortable (these are neat) which only needs to show a “drop zone” when the user has started to drag a sortable object.

The JQuery documentation for this doesn’t account for the reality of the above, its all very well if you want the empty column/div to SHOW all the time as empty, that is remain as some sort of visible placeholder, but if the empty list should show as empty, until an object is ready to be dropped on it then JQuery sortable’s don’t work. It all comes down to dimensions, if an empty list exists without a height value, you can’t drop onto it.

More specifically, if an empty jquery-sortable list exists without a specific height set at the point of [.sortable start] (that is BEFORE the event is fired) then you just cannot drop the sortable.

the JavaScript Code
Image by Dmitry Baranovskiy

I played with fixing this by adjusting each empty list (in the example belows case #col1,#col2,#col3) to have a defined height (and background, which looks nice) within the sortable “start” option, but this just creates boxes (or landing pads/zones) you can see, but not drop on.

Long and short of it – the solution to being able to drop jquery sortable’s onto invisible empty lists is to bind a function which adds a css class (or sets the height specifically) to the empty (invisible) sortable list when a user clicks one of the goal objects. This is then fired BEFORE the sortable takes hold and so creates drag-droppable landing zones for the users held sortable. It then uses the sortables “stop” property to remove the class it has added to any columns which have it.

function sortAndDrag() {
    
	//show BEFORE sortable starts
     $("#col1, #col2, #col3").bind('click mousedown', function(){
          $(".col").each(function (c) {
                if ($("div", this).size() == 0) {
                    $(this).addClass("colZoneEmpty")
                }
            })
     });
    
	//enable sortable
    $("#col1, #col2, #col3").sortable({
        revert: true,
        connectWith: ".col",
        stop: function (a, d) {
            $(".col").removeClass("colZoneEmpty");
	    //any ajax processing
        }
    });
	
}
//in this example 3 column div's exist with the id's 'col1','col2','col3', all of which have the class 'col' 
//colZoneEmpty is a css class which makes the empty list visible

There are of course improvements you could make here, like checking the users dragging before setting any styling, but this quick hackaround works where it shouldn’t.

Posted in Javascript, Snippets, Web Development Tagged ,

Hosting facebook Apps/Applications/iFrame Pages on 1and1 (SSL)

For those who run facebook fan pages you will likely know about fan gating and the importance of adding your own content to your facebook fanpage. This used to be done with the facebook static fbml app but that’s really the old way, looking forward the best way is to make its own specific app. There’s a bunch of really good stuff out there about setting up your apps but none of it seems to deal with the middle level guys who don’t want to shell out time/capital setting up amazon hosting (probably a good idea either way) or don’t strictly have https for the domain, those that just need an interim/growth testing solution with their current hosts, specifically in this case 1and1.

You can host facebook apps on any host, but hosting somewhere unsecure (not accessible via https) will flag up the following prompt for anyone browsing to the page with secure browsing turned on (high proportion of fb users.) You CAN also use amazon cloud storage (S3) for free https file storage, up to a level, however you cannot run server side code (php/ASP.NET) without setting up a server with their EC service.


Not pretty eh? What will that do to your conversion rates? Yep nothing good.
Posted in Facebook Graph API, Facebook Pages, PHP, Social Media, Web Development, Web Technology Tagged , , , , ,

Facebook Fan Page Branding Template – Illustrator

Facebook Fan Page Branding Template – Creating a facebook fanpage branding with Adobe Illustrator

As I have been dabbling with facebook fan pages I thought I would share a few of the take-away’s, in this case purely to do with the branding of your facebook page, increasingly an important outward factor in all web developments – facebook fan pages are perhaps the building blocks of a good social sprawl. I will post later about the technicalities of using fan-gated iframe apps (hosting them on 1and1/Amazon S3 for no extra cost) and similar but for now lets focus on the looks.

!
At the bottom of this post you can get a copy of the Facebook Fan Page branding template I have made in Adobe Illustrator, it has all the artboards setup so all you have to do is add your graphics and export!

Take a look at these few examples:

Posted in Facebook Pages, Projects, Social Media, Web Development Tagged , , , ,

Why not to use big red arrows in display ads…

A masterful example of Adobe advertising, its almost as if LinkedIn placed it there knowingly!
Posted in Business Tagged ,
The New Blog
WoodyHayday.com
A Quote..
"(days) Come and go like muffled and veiled figures, sent from a distant friendly party; but they say nothing, and if we do not use the gifts they bring, they carry them as silently away"
Emerson
Old Random Projects
    © Woody Hayday 2008-2024