Brent Dodson

Web Programming Page

eightball Register
Unregistered users click here to register registered users can post their website here
eightball Science Humor:
One day this guy is finally fed up with his middle-class existence and
decides to do something about it. He calls up his best friend, who is a
mathematical genius. "Look," he says, "do you suppose you could find some
way mathematically of guaranteeing winning at the race track? We could
make a lot of money and retire and enjoy life." The mathematician thinks
this over a bit and walks away mumbling to himself.
A week later his friend drops by to ask the genius if he's had any
success. The genius, looking a little bleary-eyed, replies, "Well, yes,
actually I do have an idea, and I'm reasonably sure that it will work, but
there a number of details to be figured out.
After the second week the mathematician appears at his friend's house,
looking quite a bit rumpled, and announces, "I think I've got it! I still have
some of the theory to work out, but now I'm certain that I'm on the right
track."
At the end of the third week the mathematician wakes his friend by
pounding on his door at three in the morning. He has dark circles under his
eyes. His hair hasn't been combed for many days. He appears to be wearing
the same clothes as the last time. He has several pencils sticking out from
behind his ears and an almost maniacal expression on his face. "WE CAN DO
IT! WE CAN DO IT!!" he shrieks. "I have discovered the perfect solution!!
And it's so EASY! First, we assume that horses are perfect spheres in simple
harmonic motion..."
eightball Chuck Norris Humor:
Chuck Norris can win a game of Connect Four in only three moves.
eightball Jobs:
Need a Job?
Check these out!!!!!
Jobs available
Calculate Time Progression for Best Lap Times -
I've used @tmpTable to hold the Data for now


DECLARE @driverName varchar(50);
DECLARE @tmpRace INT;
DECLARE @tmpLapTime FLOAT;
DECLARE @tmpDiff FLOAT;

DECLARE @tmpTable TABLE(
Race INT,
LapTime FLOAT,
driver VARCHAR(50)
)

DECLARE @timeProgression TABLE(
Race INT,
LapTime FLOAT,
driver VARCHAR(50),
diff FLOAT
)

INSERT INTO @tmpTable
SELECT 1, 52.787, 'Steele'
UNION SELECT 2, 50.931, 'Steele'
UNION SELECT 3, 50.430, 'Steele'
UNION SELECT 4, 51.304, 'Steele'
UNION SELECT 5, 53.980, 'Steele'
UNION SELECT 6, 51.029, 'Steele'
UNION SELECT 7, 49.706, 'Steele'
UNION SELECT 8, 53.574, 'Steele'
UNION SELECT 9, 50.668, 'Steele'
UNION SELECT 1, 59.523, 'Ashley'
UNION SELECT 2, 57.868, 'Ashley'
UNION SELECT 3, 56.227, 'Ashley'
UNION SELECT 4, 55.951, 'Ashley'
UNION SELECT 5, 56.327, 'Ashley'
UNION SELECT 6, 57.200, 'Ashley'
UNION SELECT 7, 58.714, 'Ashley'
UNION SELECT 8, 53.825, 'Ashley'
UNION SELECT 9, 57.043, 'Ashley'

DECLARE Driver CURSOR FOR (
SELECT DISTINCT Driver
FROM @tmpTable
)

OPEN Driver

FETCH Driver into @driverName

WHILE @@Fetch_Status = 0
BEGIN

DECLARE Laps CURSOR FOR (
SELECT Race, LapTime
FROM @tmpTable
WHERE Driver = @driverName
)

OPEN Laps
FETCH Laps INTO @tmpRace, @tmpLaptime
WHILE @@Fetch_Status = 0
BEGIN

IF NOT EXISTS (
SELECT 1
FROM @timeProgression
WHERE Race <@tmpRace
AND LapTime <@tmpLapTime
AND Driver = @driverName
) BEGIN
IF EXISTS(
SELECT 1
FROM @timeProgression
WHERE driver = @driverName
) BEGIN
SET @tmpDiff = (
SELECT TOP 1 min(LapTime) - @tmpLapTime
FROM @timeProgression
WHERE driver = @driverName
)

SET @tmpDiff = ROUND(@tmpDiff * 1000, 5) / 1000
END ELSE
SET @tmpDiff = NULL

INSERT INTO @timeProgression ( Race, LapTime, Driver, Diff )
SELECT TOP 1 @tmpRace, @tmpLapTime, @driverName, @tmpDiff
END

FETCH Laps INTO @tmpRace, @tmpLaptime
END
CLOSE Laps
DEALLOCATE Laps

FETCH Driver into @driverName
END
CLOSE Driver
DEALLOCATE Driver

SELECT *
FROM @timeProgression
ORDER BY Driver, Race

RETURN
used space in tablespaces without admin rights -


select t.tablespace_name "Tablespace",
count(*) "Tables",
sum(bytes/1024/1024) "Megabytes",
t.max_megabytes "Max_Megabytes",
t.quota "Quota"
from user_segments s,
(select tablespace_name,
(case when max_bytes = -1
then null
else max_bytes/1024/1024
end) max_megabytes,
(case when max_bytes = -1
then 'UNLIMITED'
else null
end) quota
from user_ts_quotas) t
--where segment_type = 'TABLE'
where t.tablespace_name(+) = s.tablespace_name
group by t.tablespace_name, t.max_megabytes, t.quota;
SQL COPY TABLE Command -
// duplicate sql table directly from console


CREATE TABLE selary_new SELECT * FROM selary
Slide show screen saver from the command line -
// description of your code here


# create a custom slide show screen saver in "${HOME}/Library/Screen Savers" (on Mac OS X)
# usage: cslidesaver [name] [pics]

function cslidesaver() {

declare EmptySlideSaverDir NewSlideSaverDir slidesaver_name
declare -i disable_pathname_expansion=0

if [[ $# -lt 2 ]]; then echo 'Minimum number of arguments: 2'; return 1; fi

#set -e # exit immediately if a command exits with a non-zero status

slidesaver_name="${1}"
shift

EmptySlideSaverDir="${HOME}/Library/Screen Savers/Empty.slideSaver"
NewSlideSaverDir="${HOME}/Library/Screen Savers/${slidesaver_name}.slideSaver"

# make sure there is no trailing slash
EmptySlideSaverDir="${EmptySlideSaverDir%/}"
NewSlideSaverDir="${NewSlideSaverDir%/}"

export EmptySlideSaverDir

/bin/mkdir -p "${HOME}/Library/Screen Savers"

if [[ -d "${NewSlideSaverDir}" ]]; then
echo "Directory already exists: ${NewSlideSaverDir}"
return 1
fi


# create a picture-free slide show screen saver directory structure based on Forest.slideSaver
if [[ ! -d "${EmptySlideSaverDir}" ]]; then
/usr/bin/sudo /bin/cp -R "/System/Library/Screen Savers/Forest.slideSaver" "${EmptySlideSaverDir}"

###/usr/bin/sudo /usr/sbin/chown -R "$(/usr/bin/logname)":"$(/usr/bin/logname)" "${EmptySlideSaverDir}"
###/usr/bin/sudo /usr/sbin/chown -R ${SUDO_UID}:${SUDO_GID} "${EmptySlideSaverDir}" # cf. sudo env
/usr/bin/sudo /bin/bash -c '/usr/sbin/chown -R ${SUDO_UID}:${SUDO_GID} "${EmptySlideSaverDir}"' # requires: export EmptySlideSaverDir

/usr/bin/find -x "${EmptySlideSaverDir}/Contents/Resources" -type f -delete
/usr/bin/find -x "${EmptySlideSaverDir}" -type d -print0 | /usr/bin/xargs -0 /bin/chmod 0755
/usr/bin/find -x "${EmptySlideSaverDir}" -type f -print0 | /usr/bin/xargs -0 /bin/chmod 0644
fi


# enable pathname expansion
if [[ "${SHELLOPTS}" == *noglob* ]]; then set +f; disable_pathname_expansion=1; fi

/bin/cp -Rp ${@} "${EmptySlideSaverDir}/Contents/Resources"

/bin/cp -Rp "${EmptySlideSaverDir}" "${NewSlideSaverDir}"

###/usr/sbin/chown -R "$(/usr/bin/logname)":"$(/usr/bin/logname)" "${NewSlideSaverDir}"
#/usr/sbin/chown -R "$(/usr/bin/logname)":"$(/usr/bin/id -gn)" "${NewSlideSaverDir}"
/usr/sbin/chown -R $(/usr/bin/id -u -r):$(/usr/bin/id -g -r) "${NewSlideSaverDir}"

/usr/bin/find -x "${NewSlideSaverDir}" -type d -print0 | /usr/bin/xargs -0 /bin/chmod 0755
/usr/bin/find -x "${NewSlideSaverDir}" -type f -print0 | /usr/bin/xargs -0 /bin/chmod 0644

/usr/bin/find -x "${EmptySlideSaverDir}/Contents/Resources" -type f -delete

if [[ $disable_pathname_expansion -eq 1 ]]; then set -f; fi

/usr/bin/open -a 'System Preferences' /System/Library/PreferencePanes/ScreenSaver.prefPane

return 0

}


cslidesaver mysaver1 ~/Pictures/pic-{1,2,3}.jpg
cslidesaver mysaver2 ~/Pictures/pic-*.jpg
cslidesaver mysaver3 ~/Pictures/picfolder
cslidesaver mysaver4 /Users/Shared/pic1.jpg ~/Pictures/pic2.jpg




Create stored procedure -


delimiter |

DROP PROCEDURE IF EXISTS CHECK_STOCKS |
CREATE PROCEDURE CHECK_STOCKS(p_order_id INT)
BEGIN
DECLARE v_done INT DEFAULT 0;
DECLARE v_o_p_id, v_quantity, v_stock INT;
DECLARE v_cur1 CURSOR FOR
SELECT opt.o_p_id , opt.o_p_quantity , p.product_stock
FROM order_products_tmp opt , products p
WHERE opt.order_id = p_order_id AND p.product_id = opt.product_id;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET v_done = 1;

OPEN v_cur1;

REPEAT
FETCH v_cur1 INTO v_o_p_id, v_quantity, v_stock;
IF NOT v_done THEN
IF v_stock <= 0 THEN
DELETE FROM order_products_tmp WHERE o_p_id = v_o_p_id LIMIT 1;
ELSEIF v_quantity >v_stock THEN
UPDATE order_products_tmp SET o_p_quantity = v_stock WHERE o_p_id = v_o_p_id LIMIT 1;
END IF;
END IF;
UNTIL v_done END REPEAT;

CLOSE v_cur1;
END
|



Source: Comment créer une procédure stockée ? ( MySQL, SQL )(chemise milano)
Canvas.java -
// description of your code here


open http://en.wikipedia.org/wiki/Inode


man find ls stat

help command help pwd type


type -t pwd
type -a pwd


find "$(pwd -P)" -ls
find "$(pwd -P)" -exec stat -f "%i -- %N" '{}' \;
find "$(pwd -P)" -exec stat -f "%i -- %N" '{}' +
find "$(pwd -P)" -exec sh -c 'exec stat -f "%i -- %N" "$@"' _ '{}' +



# cf. LSCOLORS Generator, http://geoff.greer.fm/lscolors/
# man ls
export CLICOLOR_FORCE=1
#export CLICOLOR=1
#export LSCOLORS=ExGxFxDxCxHxHxCbCeEbEb
#export LSCOLORS=GxFxCxDxBxegedabagacad
#export LSCOLORS=gxfxcxdxbxegedabagacad # cyan directories
export LSCOLORS="exfxcxdxbxegedabagacad" # blue directories


cd /dev
#cd /dev/fd
ls -i
ls -1i
ls -1i "$(pwd -P)"/*
command ls -1i "$(pwd -P)"/*

stat -f "%i -- %N" "$(pwd -P)"/*
stat -f "%i -- %N -- %Y" "$(pwd -P)"/*

stat -f "%i - %r - %v -- %d -- %N" /dev/*
stat -f "%i - %Sr - %v -- %Sd -- %N" /dev/*


# See also:
# - Why you shouldn't parse the output of ls(1), http://mywiki.wooledge.org/ParsingLs
# - Bash Pitfalls, http://mywiki.wooledge.org/BashPitfalls




Mounted volumes on Mac OS X -
// description of your code here


# See also:
# localvols in
# http://codesnippets.joyent.com/posts/show/1888


/bin/df -l | /usr/bin/sed -E -e 1d -e 's/^([^ ]+[ ]+)[^\/]+//' | /usr/bin/sort -u
/bin/df -l | /usr/bin/sed -E -e 1d -e 's/^([^ ]+[ ]+){5}//' | /usr/bin/sort -u

/bin/df -a | /usr/bin/sed -E -e 1d -e 's/^([^ ]+[ ]+)[^\/]+//' | /usr/bin/sort -u


declare IFS=$'\n'
#for volume in $(/bin/df -l | /usr/bin/sed -E -e 1d -e 's/^([^ ]+[ ]+)[^\/]+//' | /usr/bin/sort -u); do
for volume in $(/bin/df -a | /usr/bin/sed -E -e 1d -e 's/^([^ ]+[ ]+)[^\/]+//' | /usr/bin/sort -u); do
echo "vol: $volume"
done
declare IFS=$' \t\n'



# Cf. Get A List Of Mounted USB Drives
# http://www.adminselfhelp.com/?p=220

system_profiler SPUSBDataType | grep "BSD Name:" | awk '{gsub (" BSD Name: ","");print}'
diskutil info disk1
diskutil info disk1s3

system_profiler SPUSBDataType | sed -E -n 's/ *BSD Name: *([^ ]*)/\1/p'

declare IFS=$'\n'
for device in $(system_profiler SPUSBDataType | sed -E -n 's/ *BSD Name: *([^ ]*)/\1/p'); do
for usbdevice in $(diskutil info "$device" | sed -E -n 's/ *Mount Point: *(.*)/\1/p' | sed '/^ *$/d'); do
echo "USB device mounted at: ${usbdevice}"
done
done
declare IFS=$' \t\n'


Delete Files older than 14 days -
// Delete Files older than 14 days


@echo on

setlocal

set srcDir=.

REM the file mask, currently this will delete all *.mai files

set dirMask=*.mai

if not "%1"=="" set srcDir=%1

if not exist "%srcDir%" echo Directory %srcDir% does not exist.&goto :EOF

call :GETPARTS "%date%

REM set the amount of days to subtract from the current date

call :SUBTRACTDAYS 14

set cutoffDate=%yy%/%mm%/%dd%

pushd.

cd /D %srcDir%

for /f "delims=" %%a in ('dir /b /a-d %dirMask%') do call :PROCESS "%%a" %%~ta

popd

goto :EOF

:PROCESS

call :GETPARTS %2

REM task to perform, currently it deletes item %1
if /i "%cutoffDate%" GTR "%yy%/%mm%/%dd%" del %1

goto :EOF

:SUBTRACTDAYS

set dayCnt=%1

if "%dayCnt%"=="" set dayCnt=1

REM Substract your days here
set /A dd=1%dd% - 100 - %dayCnt%
set /A mm=1%mm% - 100

:CHKDAY

if /I %dd% GTR 0 goto DONESUBTRACT

set /A mm=%mm% - 1

if /I %mm% GTR 0 goto ADJUSTDAY

set /A mm=12
set /A yy=%yy% - 1

:ADJUSTDAY

if %mm%==1 goto SET31
if %mm%==2 goto LEAPCHK
if %mm%==3 goto SET31
if %mm%==4 goto SET30
if %mm%==5 goto SET31
if %mm%==6 goto SET30
if %mm%==7 goto SET31
if %mm%==8 goto SET31
if %mm%==9 goto SET30
if %mm%==10 goto SET31
if %mm%==11 goto SET30
REM ** Month 12 falls through

:SET31

set /A dd=31 + %dd%

goto CHKDAY

:SET30

set /A dd=30 + %dd%

goto CHKDAY

:LEAPCHK

set /A tt=%yy% %% 4

if not %tt%==0 goto SET28

set /A tt=%yy% %% 100

if not %tt%==0 goto SET29

set /A tt=%yy% %% 400

if %tt%==0 goto SET29

:SET28

set /A dd=28 + %dd%

goto CHKDAY

:SET29

set /A dd=29 + %dd%

goto CHKDAY

:DONESUBTRACT

if /I %mm% LSS 10 set mm=0%mm%
if /I %dd% LSS 10 set dd=0%dd%

goto :EOF

:GETPARTS

set dt=%~1
set tok=1-3

if "%dt:~0,1%" GTR "9" set tok=2-4

set yyyy=

for /f "tokens=%tok% delims=.:/-, " %%a in ('echo %~1') do (
for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do set %%x=%%a&set %%y=%%b&set %%z=%%c
)

if not "%yyyy%"=="" set yy=%yyyy%

if 1%yy% LSS 1000 (if %yy% LSS 70 (set yy=20%yy%) else (set yy=19%yy%))
if 1%mm% LSS 100 set mm=0%mm%
if 1%dd% LSS 100 set dd=0%dd%

goto :EOF



Script I wrote to stream a file and crypt it -
// Here is a php script I wrote to stream a file and crypt it with a xor operation on the bytes and with a key :

The encryption works very good but the speed is decrease by 2, it is now 520KiB/s. The user is now asked for a md5 password (instead of keeping it in the code directly). There is some part in French because it's my native language so modify it as you want.


// Stream files and encrypt the data on-the-fly

// Settings
// -- File to stream
$file = "FILE_out";
// -- Reading buffer
$bufferlength = 3840;
// -- Key in hex
//$keychar = "9cdfb439c7876e703e307864c9167a15";

// Function: Convertion hex key in a string into binary
function hex2bin($h) {
if (!is_string($h)) return null;
$r = array();
for ($a=0; ($a*2)$ta = hexdec($h[2*$a]);
$tb = hexdec($h[(2*$a+1)]);
$r[$a] = (int) (($ta <<4) + $tb);
}
return $r;
}

// Function to send the auth headers
function askPassword($text="Enter the password") {
header('WWW-Authenticate: Basic realm="'. utf8_decode($text) .'"');
header('HTTP/1.0 401 Unauthorized');
return 1;
}

// Key is asked at the first start
if (!isset($_SERVER['PHP_AUTH_PW'])) {
askPassword();
echo "Une cléest nécessaire !
";
exit;
}
// Get the key in hex
$keychar = $_SERVER['PHP_AUTH_PW'];

// Convert key and set the size of the key
$key = hex2bin($keychar);
$keylength = count($key);
// Teste si la cléest valide en hex
if ($key == "" || $keylength <= 4) {
askPassword("Cléincorrecte !");
//echo "Cléincorrecte !
";
exit();
}
// Teste si la cléest de longueur d'une puissance de 2
if ( ($keylength%2) != 0) {
askPassword("Cléde longueur incorrecte (multiple de 2 uniquement)");
//echo "Cléde longueur incorrecte (puissance de 2 uniquement)
";
exit();
}

// Headers
header("Content-Type: application/octet-stream; ");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($file) ."; ");
header("filename=\"".$file."\"; ");
flush(); // this doesn't really matter.

// Opening the file in read-only
$fp = fopen($file, "r");
while (!feof($fp))
{
// Read a buffer size of the file
$buffer = fread($fp, $bufferlength);
$j=0;
for ($i=0; $i <$bufferlength; $i++) {
// The key is read in loop to crypt the whole file
if ($i%$keylength == 0) {
$j=0;
}
// Apply a xor operation between the key and the file to crypt
// This operation eats a lots of CPU time (Stream at 1MiB/s on my server; Intel E2180)
$tmp = pack("C", $key[$j]);
$bufferE = ( $buffer[$i]^$tmp); // <==== Le fameux XOR

/*
echo "
key[".$j."]: ";
var_dump($tmp);
echo "
buffer[".$i."]: ";
var_dump($buffer[$i]);
echo "
bufferE: ";
var_dump($bufferE);
echo "
";
//*/

// Send the encrypted data
echo $bufferE;
// Clean the memory
$bufferE = "";
$j++;
}
$buffer = "";
flush(); // this is essential for large downloads
/*
fclose($fp);
exit();
//*/
}
// Close the file and it's finished
fclose($fp);

?>


Function which helps to avoid using empty/isset -
Hey..

here is a function which helps to avoid using empty/isset
checkings for arrays.

(it's acts simillar to 'default' modifier in Smarty)

Using this function you will avoid 'Undefined index' or
'Undefined offset' error.
//



$_POST['id']['other'] = 'val1';

/*
key exist (same as $_POST['id'][other])
*/
echo getRequestParam('id[other]', 'default value');

/*
key doesn't exist, we get default value (same as $_POST['var'])
*/

echo getRequestParam('var', 'default value');

function getRequestParam( $var, $default = '', $method = 'post' )
{
preg_match_all('!(\w+)!i',$var, $match );
array_shift($match);
$_vars = $match[0];
$ret = null;

if( strtoupper($method) == 'POST' ) {
$ret = _findRequestParam($_vars, $_POST);
}
elseif( strtoupper($method) == 'GET' ) {
$ret = _findRequestParam($_vars, $_GET);
}
elseif( strtoupper($method) == 'COOKIE' ) {
$ret = _findRequestParam($_vars, $_COOKIE);

}
elseif( strtoupper($method) == 'SESSION' ) {
$ret = _findRequestParam($_vars, $_SESSION);
}

if (! $ret )
return $default;
else
return $ret;

}

/**
@access private
*/

function _findRequestParam($vars, $find_in , $curr_key = 0)
{
static $ret;

if( array_key_exists($vars[$curr_key], $find_in) ) {
if( count( $vars)-1 == $curr_key ) {
$ret = $find_in[$vars[$curr_key]];
}
elseif( $curr_key _findRequestParam( $vars, $find_in[$vars[$curr_key]], $curr_key+1 );
}
}

return $ret;

}

?>








 Use OpenOffice.org        Spread Firefox Affiliate Button

For any questions or enquiries, i can be reached at my email
I look forward to hearing from you

Copyright © 2010 brentdodson.com