| | Stumble It! | Add to Mixx! | | diigo it | | Slashdot |

Monday, January 10, 2011

Querying Oracle 10.2 from XAMPP on Ubuntu

Just a quick note on how I got my XAMPP install talking to an Oracle 10.2 db:
  1. Get Oracle InstantClient (you'll have to register):
    - http://download.oracle.com/otn/linux/instantclient/10205/sqlplus-10.2.0.5.0-linux.zip
    - http://download.oracle.com/otn/linux/instantclient/10205/basiclite-10.2.0.5.0-linux.zip
  2. Unzip both to /opt/lampp/var/oracle
  3. Tell XAMPP where to look for the Oracle client:
    sudo /opt/lampp/lampp oci8
  4. Give the following path:
    /opt/lampp/var/oracle/instantclient_10_2
  5. Restart Apache:
    sudo /opt/lampp/lampp restartapache


You should now be able to make PHP calls to Oracle functions.

Monday, December 20, 2010

Day Glow Background for Ubuntu

I work in a cubicle. Waa, waa, poor me. To combat this, I got the idea to write a script that will raise and lower the brightness of my desktop background with the time of day. When it's dark outside, my desktop is dark. When it's light outside, so is my desktop. Below is the script to accomplish this and the content of an HTML file to help you find your WOEID:

day_glow.sh

#!/bin/bash
#
# to make this work:
# 1 - $ sudo apt-get install imagemagick
# 2 - Extract this ZIP to your hard drive
# 3 - $ chmod +x day_glo.sh
# 4 - $ ./day_glo.sh picture max min woeid
# - picture = path to the background picture that you use \
# this script will create a <picture>.glow file \
# which should be set as your background
# - max = an integer value for the maximum brightness you \
# want during the brightest part of the day
# - min = same as max, but during the darkest part of the day \
# I find that a max of 100 & min of 25 do nicely
# - woeid = this is your location identifier as Yahoo understands it \
# you can fire up the included 'woeid.html' file to find \
# the number for your location
# 5 - $ crontab -e
# - every hour = "0 * * * * /path/to/day_glow.sh /path/to/background.jpg 100 25 12799337"
# - this will run the script on the hour, every hour
# - "/path/to/day_glo.sh" = file path to this script
# - "/path/to/background.jpg" = the image to be used as the backgorund \
# the script will output to "/path/to/background.jpg.glow" \
# which should be set as your background
# - "100 25" = this sets the max brightness to 100 (midday) & min to 25 (midnight)
# - "12799337" = WOEID for Vancouver, Washington - check woeid.html for yours

NOW=$(date +%s)
PIC=$1
MAX=$2
MIN=$3
WOEID=$4

wget -q http://weather.yahooapis.com/forecastrss?w=$WOEID -O- | \
grep astronomy | \
sed -E 's/.*sunrise="([^ ]*) am" sunset="([^ ]*) pm"\/>/\1 \2/' | \
while read -r SUNUP SUNDN; do
SUNUP_DTS=$(date "+%Y-%m-%d $SUNUP:00")
SUNDN_DTS=$(date "+%Y-%m-%d $(( ${SUNDN%${SUNDN: -3}} + 12 )):00")
SUNUP_EPC=$(date --date="$SUNUP_DTS" +%s)
SUNDN_EPC=$(date --date="$SUNDN_DTS" +%s)

HALFDAY=$(( ($SUNDN_EPC-$SUNUP_EPC)/2 ))
MIDDAY=$(( $HALFDAY+$SUNUP_EPC ))

if [[ $NOW > $MIDDAY ]]; then
DIFF=$(( $NOW-$MIDDAY ))
elif [[ $MIDDAY > $NOW ]]; then
DIFF=$(( $MIDDAY-$NOW ))
fi

# UPDATE - ADDED THIS BLOCK TO PREVENT FULL BLACKNESS
if [[ $DIFF -gt $HALFDAY ]]; then
DIFF=$HALFDAY
fi

PERC=$(( 100-(100*$DIFF/$HALFDAY) ))

SCALE=$(( $MAX-$MIN ))
VAL=$(( ($PERC*$SCALE/100)+$MIN ))

convert -modulate $VAL,100,100 $PIC $PIC.glow

done



woeid.html

<html>
<head>
<title>Ben's Really Simple WOEID Converter</title>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.4.4.min.js'></script>
<script type='text/javascript'>
function lookup_woeid() {
var place = encodeURI($('#place').val());
$.getJSON(
'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.places%20where%20text%3D%22'+place+'%22&format=json',
function(data) {
$('#output').html('');
if (data.query.count == 0) {
return false;
} else if (data.query.count == 1) {
var place = data.query.results.place;
$('<tr><td>'+place.woeid+'</td><td>'+place.name+'</td><td>'+place.admin1.content+'</td></tr>')
.appendTo('#output');
} else {
var places = data.query.results.place;
for (var p in places) {
place = places[p];
$('<tr><td>'+place.woeid+'</td><td>'+place.name+'</td><td>'+place.admin1.content+'</td></tr>')
.appendTo('#output');
}
}
}
);
}
</script>
</head>
<body>
<table style='height:100%;width:100%;'>
<tr style='height:50%;'>
<td valign='middle'>
<center>
Place Name or ZIP:
<input type='text' id='place' />
<br>
<button onClick='lookup_woeid()'>find it</button>
</center>
</td>
</tr>
<tr>
<td>
<center>
<table border='1px'>
<thead>
<tr>
<th>WOEID</th><th>Name</th><th>Place</th>
</tr>
</thead>
<tbody id='output'>
</tbody>
</table>
</center>
</td>
</tr>
</table>
</body>
</html>

Tuesday, November 9, 2010

Cross-Origin Javascripting with PHP

I had an awesome moment of WIN today when my boss asked me if we could add a drop-down selector to a SharePoint form that was populated with information from an SQL database. I have already set up my LAMP server to talk to the SQL database so I figured the easiest way to get this done would be to have an Ajax request sent to my LAMP server and forward that on to the SQL server and return the results to the SharePoint form.

Simple right?

Except that my LAMP server is on a different domain than the SharePoint server so that would classify as Cross-Origin and my Ajax would fail.

After a bit of research, I found that I can manipulate the headers sent out by the PHP pages served by my LAMP server to allow for Cross-Origin scripting!

Here's how:
http://LAMP/sql.php
<?php

header('Access-Control-Allow-Origin: http://sharepoint/');
...
# more PHP to query the SQL server & build the resulting page
...
http://SharePoint/List/NewForm.aspx (in CEWP)
<script src='jquery.js'></script>
<script type='text/javascript'>
...
$('#drop-down_id').load('http://LAMP/sql.php');
...
</script>

Thursday, November 4, 2010

jQuery Manipulation of SharePoint Lists

Wooh, it's been a while. Adding a new kiddo to the family has had a ripple-effect on my online activity as I've been busy with family and catching up at work. Hopefully, I'll be able to start posting regularly again now that things are starting to become routine again.

I got an email earlier today asking about how to do some manipulation of a list in SharePoint using jQuery. As I was answering the question, it occurred to me that I had done this once before with vanilla JavaScript and I was curious to see how much less code I could write to accomplish the same thing.

Here's what I came up with:
<script src='jquery.js'></script>
<script type='text/javascript'>
var col_names = [];
var tbl_id = ''; // the id for the table that you want to manipulate goes here
tbl_id = tbl_id.replace(/{/g,'\\{').replace(/}/g,'\\}'); // cleanup to handle the curly braces

$(document).ready(function() {
$('#'+tbl_id+' > tbody > tr > th').each(function() {
if ($(this).hasClass('ms-vh-icon')) { col_names.push('Attachments'); }
/** OTHER 'else if' statements may be required to handle future columns without text names **/
else { col_names.push($(this).text()); }
$(this).attr('COL',col_names[col_names.length-1]);
$(this).attr('ROW','0');
});

var c=0;
var r=1; // the header row is row 0
$('#'+tbl_id+' > tbody > tr > td').each(function() {
$(this).attr('COL',col_names[c]);
$(this).attr('ROW',r);
r = (c == col_names.length-1) ? r+1 : r;
c = (c == col_names.length-1) ? 0 : c+1;
});
build_options();
});

function hide_cell() {
/**** THIS IS A SAMPLE OF HOW TO ITERATE THROUGH THE ROWS ****/
$('#'+tbl_id+' > tbody > tr').each(function() {
$(this).find('[COL="'+$('#cols').val()+'"]').hide();
});
}

</script>

This code will assign ROW and COL attributes to each cell in a given table with an id of "tbl_id". These can then be used later in the code to reference a particular cell in your code.

Enjoy

Tuesday, August 17, 2010

Unofficial Slacker Player Chrome Extension

So I scraped together my coding skills long enough to put together this little Chrome Extension that will launch just the Slacker.com player less all the ads. It's small, sleek, and functional =)

or

Tuesday, July 27, 2010

Virtualizing Windows XP to KVM on Ubuntu 10.04

I've been struggling lately with how to convert an existing physical Windows XP based laptop to a virtualized machine that can be run on KVM. I've followed a few How-To's and by combining elements of each, I've finally been able to boot the virtualized image, though now I have to re-authenticate (more on that as I figure it out).

Setup:
  • Virtual Server (VS) - The host server running KVM
  • Test-Laptop - The WinXP laptop that I'm trying to virtualize
Procedure:
  1. Follow the steps on Microsoft's KB to enable IDE on the WinXP machine.
  2. Download, install, and run VMWare Converter on the WinXP machine.
  3. I used the defaults with "VMWare Workstation 6.5.x" as the type & stored the resulting image on a file share on the Virtual Server host.
  4. While (or before) the image is being created, download & install VMWare Server on the Virtual Server host.
  5. Once the image of the WinXP machine is created, use vmware-vdiskmanager to create a single file:
    vmware-vdiskmanager -r test-laptop.vmdk -t 0 test-laptop-single.vmdk
  6. Download the fixntldr.iso to the Virtual Server host and use it as the boot CD for the image you just created:
    kvm -hda test-laptop-single.vmdk -cdrom fixntldr.iso -boot d

Wednesday, June 23, 2010

snmpset To the Rescue!

A big, ugly, hairy, monotonous task recently fell in my lap at work. I had to update a couple configuration settings in approximately 900 menu-driven network devices. Each device had an independent authentication method with four or five possible username/password combos, and different menu options depending on firmware version. Completing one box would take about 2-3 minutes. Multiply that by 900 and you're looking at a solid week of nothing but menu navigation and data entry.

This ranked very high on my "List-of-things-that-make-me-want-to-stab-my-eyes-out".

The disparity of versions and lack of a single configuration standard rendered my usual methods of scripting useless. A dark little rain cloud settled over my cube.

Then my boss made the comment, "These things have SNMP, right?"

I heard, "These things have SNMP write?"

I immediately started researching and sure enough, I could use the "snmpset" command to script the updates for me!

WIN!

Here is a copy of the 'bulk_snmpset.sh' script that I used to do the updates:
#!/bin/bash

while read HOST RWSTR; do
snmpset -v 2c -c $RWSTR $HOST <snmp_oid_here> a "192.168.100.100"
done < $1
I fed this script a flat text file (hosts_to_update.txt) with the 900 host names and their respective SNMP read/write string that looked like this:
10.10.10.1 SNMPrwSTRING1
10.10.10.2 SNMPrwSTRING2
10.10.10.3 snmpRWstring3
...
Actually making it worked, looked like this:
me@ubuntu:~/scripts $./bulk_snmpset.sh hosts_to_update.txt
All that remained was to capture the ones that failed and either adjust the script accordingly or take care of them manually