Tuesday, April 12, 2011

Getting web request with GET request in Excel

I found a cool easy way to do a GET request to any website and use any parameters needed.
One method to get code from a webpage and use it is here:
http://scriptorium.serve-it.nl/view.php?sid=40
and another I use is here:
Function testHttpGet()
Dim oHttp As Object
Set oHttp = CreateObject("Microsoft.XMLHTTP")
MyUrl = "http://10.0.21.130/test.php?name=mikeqq"
oHttp.Open "GET", MyUrl, False
oHttp.send
'MsgBox oHttp.Status
If oHttpPost.Status < 300 Then
SomeVar = oHttpPost.responseText
MsgBox SomeVar
End If
End Function

Just put this code in a module in Excel and then call it from in the spreadsheet somewhere. So now I can have excel give and get commands from a PHP script and could even act like a cron job by executing every once in a while!

Mysql Master - Slave replication server

I put together an Ubuntu 10.10 server with MySQL on it. I did it in VmWare Player and made it so what ever inserts I put in the master computer database gets put into the slave instantly. I'm going to try doing lots of inserts to see how long till it catches up. I can use PHP to programatically decide what SQL queries go to which database.
A great article I found this in is here
http://www.oracle.com/technetwork/articles/dsl/white-php-part2-355138.html

Friday, April 8, 2011

Dynamic caching of webpages

I read an interesting article on Oracles site on how to scale PHP pages for high traffic to scale web applicatons
I can see how this would be powerful. I have made php pages before that are very complex and if there were thousands of people coming every minute it would kill the sever unless it only had to load a certain page once every hour or so. Then if there are any updates they will only be updated and seen by everyone visiting once an hour instead of the instant they appear.

instead of having to run php all the time you just run it once an hour and write the content to a textfile with the name of the file being the url of the file plus any variables or get parameters that make the page unique or look different. All requests for the next hour will just read a text file with the webpage in it.
I will try an example in php and put it here.

<?php
$timeout = 60; // One Hour is 3600
$file = 'C:/Users/mike/Desktop/webhome/cachingtest/tempcache/'.sha1($_SERVER['REQUEST_URI']);
if (file_exists($file) && (filemtime($file) + $timeout) > time()){
//only show the cached copy of the page
readfile($file);
exit();
} else {
// Setup saving and let the page execute:
ob_start();
register_shutdown_function(function (){
Global $file;
$content = ob_get_flush();
file_put_contents($file, $content);
});
}
?>
<h2>Testing saving the current page from cache and only loading a fresh copy after a certain time limit has passed.</h2>

Tuesday, March 15, 2011

javascript attributes

I was trying to find a way to make an image grow big and then small each time you click on it. I used these functions

function open_enlarge(plan){
$('#'+plan).addClass('largemap');
$('#'+plan).removeClass('smallmap');
document.getElementById(plan).setAttribute('onclick', 'close_enlarge("'+plan+'");');
$('#addjob_floorplan').attr('onclick', 'close_enlarge("addjob_floorplan")');
}

function close_enlarge(plan){
$('#'+plan).removeClass('largemap');
$('#'+plan).addClass('smallmap');
document.getElementById(plan).setAttribute('onclick', 'open_enlarge("'+plan+'");');
$('#addjob_floorplan').attr('onclick', 'open_enlarge("addjob_floorplan")');
}

Then it didn't work in internet explorer so I decided to go with a simpler way with jQuery with only 1 function call toggling 2 classes back and forth instead of having to change the onclick event and having to make it different for Internet explorer 7:

function open_enlarge(plan){
$('#'+plan).toggleClass('largemap','smallmap')
}

Test case Idea for php, javascript and mysql

I want to make some kind of test case for my websites

It automatically runs a script to recreate the test database each time abd then run the same javascript commands that a user would run normally.

The script would pretend to be a user and then analyze the finished data and expect the same result every time and if its different then it will report an error with details after the test. It will log errors during the test as well. It could be logged on a file or emailed or in a database you can look at from in the admin of the website and have the test done everyday or manually started.
My sites usually have alot that goes on and if there was something to run that tests everything or at least the hardest problems to catch then it would be worth the effort
especially when the changes I make can break something only the customers would see.

Sunday, February 6, 2011

script in CMD to copy only files that don't already exist

The following script will be written to copy.bat or something like that. When it runs it will copy the files that don't exist yet and skip them if the file does exist. This way it won't accidentally overwrite the file after you make changes to it.
set file=copy_mike.pdf
call:copy
set file=copy_jim.pdf
call:copy
set file=copy_bob.pdf
call:copy

echo done
pause
goto :EOF

:copy
if not exist %file% (
call:process
)
goto :EOF

:process
copy blank.pdf %file%

Tuesday, November 23, 2010

Facebook BigPipe is great!

BigPipe has been around for a while in Facebook. I love how the pagelets load all at once so that the first one to get loaded comes first. Also the idea of prolonging the javascript until all page content is loaded it a great idea.
Here is the page about BigPipe:
http://www.facebook.com/notes/facebook-engineering/bigpipe-pipelining-web-pages-for-high-performance/389414033919
I love this idea and may implement it on a site next time I am building a multimedia site. The nice thing is the main parts of the site are loaded very fast and then the rest are loaded with AJAX.