Monthly Archives: March 2012

Remove time portion of datetime column Tsql

A subject that is often covered with overuse of casting and converting by many developers , due to lazy – fast programming . There are many approaches on the specific subject . Fastest one I discovered on the web is

 

DateAdd(dd,0,datediff(dd,0,  foodate ))

 

It is the least resource intensive . And to extend this technique you can use it in a whole bunch of other cases

Such us round to :

Whole minute    DATEADD(minute, DATEDIFF(minute, 0, startdate)0)

Whole Hour    DATEADD(hour, DATEDIFF(hour, 0, startdate), 0)

etc…


(Proof of concept is Here and Here )

My usb disk collection ( or in other words BACKUP !!!!)

An ordinary day usually doesn’t start with the coffee maker  refusing to work , and your primary External Disk –call it disk1 from now on ( the one that you always carry with you saving your job) broken . Good thing I always have it synced with a backup disk –the one that ia call a life-saver (disk2 for the story )  ) .

So I started facing the situation . Ok , disk1  has no bad sectors , over a million files on it , and its benchmarks started to be very low . Defragmentation ok , checked it on another machine ok , format does not seem to do anything . Let’s start low level formatting it .

My office machine is a pretty good one ( for my standards ) . A win 7 64bit , with two 500gb disks , 8 Gb Ram and I Core I5 CPU . OK , grab  disk 2 ( backup was only 2 days old ) let’s do some benchmark test to check its status . Benchmark OK , defragmentation as low as 2% files all OK . As a had a time windows not needing anything , started to defrag it to see if I can zero it . A phone call asking me some feature that had to be tested locally , took my thought away from that ( along with the everyday end user support ) . Started local sql server , Internet information manager , set up a small project started debugging , two hours and a hanged debugger later , saw that  process explorer was using more tha 5 GB of ram . What was that . switching to the low level formatter window taught me that you can’t revive a  disk that has intelligence on its own , and gave me no option than stopping the low level format ( the sea tools from Seagate informed me already the the disk has errors and it was on warranty ) . Explorer still on 5 GB ram . Defragmentation still working , stopped it . No difference . The feature I refered earlier was already ftp’d on its correct location as it was built and free of errors ( I hope ) . so nothing currently working , let’s stop the process ( my mistake ) . Explorer restarted , disconnected disk 2 , reconnected it , where the heck are my files ????@#%^@$%^@$ .

Hopefully there was nothing serious that a usual check disk couldn’t handle ( to be sure I started recovering  a third disk I used in the whole process of moving files and I was sure that it was formatted and never used again , so if something went wrong , I could get some important stuff out of it ) .

Conclusion . Always keep a second copy of your important data ( and in different geo places ) . Always think that the worst case scenario is not as far as you hope . Maybe it’s time for an external SSD ( but cost is high for serious capacities ).

 

 

( Still don’t have a clue why the filesystem had trouble handling over 2 hundred thousand files ( am I missing something ??) under my xampp directory – disk 2 ( the that for now I promoted to my disk 1 for now ) had also trouble giving enough performance writing to it but it was something that I could live with it . Xampp was used mainly for debugging joomla installations that was already backed up from original sites by this wonderfull module ( Akeeba ) and I deleted and set up a new one

CMYK images not supported in IE (untill version 9)

Got myself browsing through a bunch of recently finished sites from our team when I discovered a new banner image in one of them. Cool i thought , nice one . A professionaly looking banner always gives a great look on your site .

While i am used in using Mozilla Firefox , i opened an IE 8 to get the feeling on the same jobs .
Number 1 ok , number 2 , ok , number 3 ?? where the heck is the banner .????!!!!!

Checked html source , the paths where ok . Why should a picture show in firefox and not IE ??? .
A little googling revealed a nice article . CMYK images are not rendered in older versions ( pre 9 ) of Internet explorer . OK opened the image in Gimp , changed color mode , uploaded , and there it is .

Have a look at the source article here  , and try it out .

Hint Mode On.

There is a fine tool checking browser compatibility for  IE .You can find it here

Hint mode Off.

 

Solution for delay on loading images

As i was dealing with a legacy site built on a mix of plain html and classic asp framework , i found out that we where nearly out of space on the ISP due to thousand of images uploaded through the years serving a function where the user can select a specific date and that dates image is served .

The solution was obvious . We have to move all or part of the images to another location .

That was the easy part . OK .  I can easily change the tag’s value img src depending on the users selection .

The hard part was that when the image served was locally it appeared with no delay . When it was away ( on another location , another ISP , another domain ) we had a delay opening it .

OK let’s do some tricks . For start find a nice image to show right away to the user while loading  ( here )

Find a way to hide it when the requested  image loads

<script type=”text/javascript” src=”https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js”></script>
<script language=”javascript” type=”text/javascript”>
$(window).load(function() {
$(‘#loading’).hide();
});
</script>

 

Place an image to a respective  div

<div id=”loading”>
<img id=”loading-image” src=”loadanimation.gif” alt=”Loading…” width=”80″ height=”80″ />
</div>

Response.write the canonical image as soon as you know what you have to serve

and finally the magic word .

Response.flush !!!!!!!!!!!!

( According to w3schools the Flush method sends buffered HTML output immediately.)

Works smoothly and fast . Guest see the loading animation until the requested image is ready to be served .

Am i missing something . Yeap a little inline css i used

<style>
#loading {
width: 100%;
height: 100%;
top: 150px;
left: 0px;
margin:auto;
position: fixed;
display: block;
opacity: 0.7;
background-color: transparent;
z-index: 99;
text-align: center;
}
</style>

 

 

Can I Get PageNumber of Cell in Excel ?

Phone Ring ……… Phone Ring ……… The CID informed me that it was my good friend Timos on the other end .

Timos : Hey Nickos , Good morning can you tell me if there is an easy way to get the page number of a cell ??? I want to summarize a column based on page breaks

Me: Hmmmmm . Interesting problem . Let me get back to you in a while.

I must admit . that was a thing i could easily name , an interesting problem . Until that time the page number in excel for me was something that existed in the sphere of print settings and i had never involved it in and calculation inside the sheet .

That was surely an interesting problem !!!

Did some search and found some interesting stuff in forum posts .

The best one i found was mentioned in ( http://groups.google.com/group/microsoft.public.excel.programming/browse_frm/thread/8ca260935d83f46a )

Here is the solution transformed in VBA Function you can easily insert into Excel VBA Editor .

Public Function getpagenumber(CurrentCell As Range) As String

 Dim VPC As Integer, HPC As Integer

Dim VerticalPageBreak As VPageBreak, HorizontalPageBreak As HPageBreak

Dim NumPage As Integer

 If ActiveSheet.PageSetup.Order = xlDownThenOver Then

  HPC = ActiveSheet.HPageBreaks.Count + 1

  VPC = 1

Else

  VPC = ActiveSheet.VPageBreaks.Count + 1

  HPC = 1

End If

NumPage = 1

For Each VerticalPageBreak In ActiveSheet.VPageBreaks

  If VerticalPageBreak.Location.Column > CurrentCell.Cells.Column Then Exit For

  NumPage = NumPage + HPC

Next VerticalPageBreak

For Each HorizontalPageBreak In ActiveSheet.HPageBreaks

  If HorizontalPageBreak.Location.Row > CurrentCell.Cells.Row Then Exit For

  NumPage = NumPage + VPC

Next HorizontalPageBreak

getpagenumber = NumPage

 End Function

Html stuff .Enable url link on an allready build flash object

Yesterday I came across a very interesting problem . We had to enable an href to a flash object which was not built in to it .

A small survey showed that we had no luck on that effort without building the flash from the  beginning and enable the url link with actionscript’s GetUrl() .

While reading many forum posts i came across an interesting solution ( or at least the path to an interesting solution ) to try with .

First of all we have to us to divs , one inside another .

The first on has to have a z-indez greater the the second one, and we have to declare the onclick event on it .

The second one , holds nothing but the flash object itself , with an interesting parameter . Wmode = Opaque . ( or transparent )( here is a link to the adobe’s knowledge base )

This make the object rendered in the same window with the html by the browser .

Bellow is the full code . Hope it would be of any use ,

<div style=”z-index: 1;” onClick=”window.open(‘http://www.yourlink.com’,’_blank’);”>

<div style=”z-index: -6;”   >
<object        width=”520″ height=”70″ border=”0″ codebase=”http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0″ classid=”clsid:D27CDB6E-AE6D-11cf-96B8-444553540000″>
<param value=”/yourflashmovie.swf” name=”movie” >
<PARAM name=”quality” value=”high”>
<embed   wmode=”opaque” width=”520″ height=”70″ type=”application/x-shockwave-flash” pluginspage=”http://www.macromedia.com/go/get/flashplayer” loop=”false”
src=”yourflashmovie.swf”>
</object>
</div>
</div>

 

 

 

Is it Joomla ?? Or not

Hmmm, in seeking of the plaform used for a web site , did some research about How to tell if a website is joomla or not .

Here are the results .

a) Check for meta-generator in a web page source ( Joomla reveals there it’s identity )

( It is easy to hide it , just add JFactory::getDocument()->setGenerator(''); in default’s template index.php just after defined(‘_JEXEC’) or die; )

b) add /?tp=1 in url . If it is Joomla 1.5 , it will present you with templates positions ( In 1,6 and above this is off by   default and can be turned in in templates option .

c) add /administrator in URL .You will be presented with the Joomla Control Panel’s login screen  ( Can be hidden with a bunch of usefull plugins ) .

d) add ?template=beez ( one of the provided template ) to the http://www.yoursite.com/index.php URL .You will see a different view of it !!  ( you can always remove unnecessary templates from your installation

e) Check for robots.txt file ( http://www.yoursite.com/robots.txt ) you will see a bunch of joomla’s directory’s that the webmaster want to keep away from web spiders eyes .

f) Check a components xml file  ( www.yoursite.com/adminstrator/components/com_content/content.xml ) if its there , Yeap it is Joomla

g) Search for a forgotten distribution configuration file ( http://www.yoursite.com/configuration.php-dist ) . Yes , Yes it had to be removed after install 🙂 .

to be continued