PHP bar graph script
Jul 2nd
It’s time for another code freebie from yours truly.
This is a little script that creates bar graphs with a length and title you specify.

As many as you want, for whatever you want. Like breakfast!

I made the design in Excel 2007 and copied it over to Adobe Fireworks, keeping even the transparency, where I resized it and cut it into pieces. If you want to use my design you can grab the CSS and from there find the URLs to the PNGs.
Do note that the colored part is not to the pixel precise the value you give it. That was impossible, to have the 3d effect in the graphics they obviously had to be wider than 1px, which means we give up some accuracy by not measuring in the width of the graphics. This is most noticeable when you compare 0 (empty) to 1 and 99 to 100 (full), but for non-scientific purposes it should do fine.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | <?php
function bargraph ( $rating=0, $title='' )
{
// maximum free width (excl. switch)
$size['max'] = 535;
// switch width (for exceptions)
$size['switch'] = 13;
// some maths
$size['fill'] = $rating * ( $size['max']/100 );
$size['fill'] = round( $size['fill'], 0 );
$size['empty'] = $size['max'] - $size['fill'];
//
$result = '';
$result .= '<div class="bargraph">'."\r\n";
$result .= ' <h4>'.$title.'</h4>'."\r\n";
// decide if we have an exception
switch ( $rating )
{
// rating of 0, we'll have to end empty
case 0:
$size['empty'] = $size['empty'] + $size['switch'];
$result .= ' <div class="empty_start"></div>
<div class="empty" style="width:'.$size['empty'].'px;"></div>
<div class="empty_end"></div>'."\r\n";
break;
// rating of 100, we'll have to start filled
case 100:
$size['fill'] = $size['fill'] + $size['switch'];
$result .= ' <div class="filled_start"></div>
<div class="filled" style="width:'.$size['fill'].'px;"></div>
<div class="filled_end"></div>'."\r\n";
break;
// rating somewhere in betweeen, start empty, switch and end filled
default:
$result .= ' <div class="filled_start"></div>
<div class="filled" style="width:'.$size['fill'].'px;"></div>
<div class="switch"></div>
<div class="empty" style="width:'.$size['empty'].'px;"></div>
<div class="empty_end"></div>'."\r\n";
break;
}
$result .= '</div>'."\r\n";
echo $result;
}
?> |
1 | <?php bargraph(75,'INSERTTITLE'); ?> |
If you like it please leave a comment below. I’ve just installed Disqus so your comments will be in good hands.
The music manager of my dreams, have you seen it? (with answer)
Oct 14th
I’m looking for a music manager that does not do a lot, mostly as a replacement for Windows Explorer. There’s a lot of software out there that claims to be your best friend when it comes to music. It also wants to do almost everything for you: ID3 tagging, ripping a CD, browsing through your files, renaming them, moving them and oh yes, let’s not forget playing them! Well, that’s not how I roll.
Part perfectionism part habit I would describe my music tool-set as. I play everything with Winamp (there’s your habit) because I’ve used the program since 1997 and I know the plugins and hotkeys by heart. I repair ID3 data and rename files with Tag&Rename, and a sometimes a little help from Bulk Rename Utility. All info coming from the near-flawless music database of Discogs.
tmbr tries tumblr
Sep 7th
Today I want to share with you my rediscovery of Tumblr. Tumblr brands itself as a miniblogging platform. Where microblogging services like Twitter keep it really really really simple, Tumblr wants to do multiple things but still keep it small.
Yesterday I heard of Tumblr again when watching some videos of Gary Vaynerchuck and I decided to check it out once more. Once more because I remember that I had already seen it before when it launched – but I didn’t use it for some reason.
mIRC Auto Reply remote script
Apr 21st
Over at H2kTV we help people who have never used IRC (Internet Relay Chat) get passed the barrier of installing an IRC client by embedding QuakeNet‘s webchat application. In the flood of IRC beginners this creates there are always people sending the moderators private messages, but then they don’t wait for an answer, because they are in a browser after all, and browsers are always on the move.
So I asked myself, why don’t I have an autoreply script yet? That would explain to them that we are not watching chat 24/7 and they will have to wait a bit if they want an answer. Well that’s almost as easily done as said.
1. Open your remote scripts editor in mIRC (ALT+R).
2. Start a new file (File > New).
3. Copy-paste the code below in the window and customize it to your liking.
4. Save the file with a name you can remember and ‘Save & Exit’ the remote scripts editor.
1 2 3 4 | On *:Open:?:*: {
msg $nick [AUTOREPLY] Thank you for your message $nick I will read it asap and respond if needed.
msg $nick [AUTOREPLY] If you close IRC I cannot respond, so please stay online or email me your question instead.
} |
Credits go to tv3636 and FordLawnmower for feeding this knowledge to Google.
An update to ‘SuperPopup’ by Eric Webster
Mar 21st
Even though I hate Javascript I managed to fabricate an updated version of Eric Webster‘s Super Popup. Probably because of it’s age, published in 2007, the sizing and positioning functions don’t work anymore and those are pretty essential to a popup script. I also added a default positioning feature that centers the popup when no vars are given. Hope you like it.
1 2 3 4 | <script type="text/javascript" src="superPopup.js"></script>
<a href="popup.php" onclick="superPopup({ url:this.href, width: 640, height: 386, left: 25, top: 150 }); return false;">popup in the top left corner</a><br />
<a href="popup.php" onclick="superPopup({ url:this.href, width: 960, height: 540 }); return false;">popup in the center</a> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | /* Super Popup v1.1 by Tim Brugman www.timbrugman.com March 21st 2010 Changelog: * Positioning (top & left) was not working. Adjusted the build statement to make it work (again). * Made the default position (when no values are entered) be centered. Super Popup v1 by Eric Webster www.ericwebster.net March 26th 2007 Super Popup: When using this function on multiple links across a site its best to define a 'type' within your initiate function, if you are defining a popup on a single page you can pass in the options you want as arguments. */ function f_clientWidth() { return f_filterResults ( window.innerWidth ? window.innerWidth : 0, document.documentElement ? document.documentElement.clientWidth : 0, document.body ? document.body.clientWidth : 0 ); } function f_clientHeight() { return f_filterResults ( window.innerHeight ? window.innerHeight : 0, document.documentElement ? document.documentElement.clientHeight : 0, document.body ? document.body.clientHeight : 0 ); } function f_filterResults(n_win, n_docel, n_body) { var n_result = n_win ? n_win : 0; if (n_docel && (!n_result || (n_result > n_docel))) n_result = n_docel; return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result; } function superPopup(args){ // URL is the only required field. we cannot continue without it. if (args.url) { var url = args.url;} else { alert('url is missing'); return; }; if (args.type) { var type = args.type;}; // option = (if it was passed in as an argument)? use that value : [IF NOT] use this default value; var directories = (args.directories)? args.directories : directories = "no"; var location = (args.location)? args.location : location = "no"; var menubar = (args.menubar)? args.menubar : menubar = "no"; var resizable = (args.resizable)? args.resizable : resizable = "yes"; var scrollbars = (args.scrollbars)? args.scrollbars : scrollbars = "no"; var status = (args.status)? args.status : status = "no"; var toolbar = (args.toolbar)? args.toolbar : toolbar = "no"; var width = (args.width)? args.width : width = "50"; var height = (args.height)? args.height : height = "50"; var left = (args.left)? args.left : (screen.width/2)-(width/2); var top = (args.top)? args.top : (screen.height/2)-(height/2); var winName = (args.winName)? args.winName : winName = "popup"; /* DEFINE POPUP TYPES */ if(type == "_blank"){ //created to imitate the target='_blank' behavior in html var randomNumber = Math.floor(Math.random()*1000); var winName="blank" + randomNumber; width=f_clientWidth(); height=f_clientWidth(); scrollbars="yes"; menubar="yes"; toolbar="yes"; directories="yes"; location="yes"; top="0"; left="0"; } if(type == "copyright"){ height = "500"; width = "70"; scrollbars = "yes"; } /* build our complete window options statement */ var newWindow = window.open( url, winName, 'width='+width+', height='+height+', directories='+directories+', location='+location+', menubar='+menubar+', resizable='+resizable+', scrollbars='+scrollbars+', toolbar='+toolbar+', status='+status+', toolbar='+toolbar+', top='+top+', left='+left ); if (newWindow == null){ //alert('A popup containing important information was blocked by your browser. Please enable popups for this site in order to view this information.'); } else { if (window.focus && newWindow) { newWindow.focus() } } } |
For a listing of all the options visit Eric’s website or just read the Javascript.
ps. Don’t rely on some features like disabling resizing or disabling the status bar. These do not work anymore in today’s browsers. Tested in Firefox 3.6, Chrome 4.1 and Opera 10.
Hello world
Mar 1st
You’ve reached your destination. What are you here to find? Well, gee. Not much. But in today’s society it’s a good idea to register your name as a domain, so that’s why you are reading this and not a 404 error.
I’m not a big blogger, I use Twitter for my daily 2 cents that, I feel, deserve some attention. Since the beauty of Twitter, the 140 character limit, can also be it’s downside I will use this blog mainly to publicize the things that don’t fit in a tweet.
kind regards,
Tim

