TinyMCE — stripping junk when pasting from word

This will strip all annoying extra nonsense when copy/pasting from Word:

tinyMCE.init({
selector: “textarea”,
menubar: false,
plugins: “paste”,
paste_as_text : true,
paste_data_images: false,
paste_word_valid_elements: “”,
paste_webkit_styles: “”,
paste_retain_style_properties : “”,
toolbar: “insertfile | bold italic | bullist numlist”,
height : “500”
});

Posted in Uncategorized | Leave a comment

Handling Errors in MYSQL Procedures with Rollback

f you have mysql stored procedure that changes database tables — you probably want to enclose the whole procedure in a single transaction and add error handling to roll back the work if anything fails.

Here is how to do it:
Key points:
Use START TRANSACTION at top after BEGIN
Use COMMIT at end

Turn on Transactions with START TRANSACTION after the BEGIN

And end the transaction with COMMIT at the end of your procedure

Add an error handling block that calls ROLLBACK work if there is any SQL EXCEPTION.

This is example SENDs a custom crafted ERROR message ( similar to RAISE_APPLICATION_ERROR in ORACLE ) which our PHP code recognizes and displays / logs.

Here is the magic:
CREATE
DEFINER = CURRENT_USER
PROCEDURE bocs_create_budget(psource_bud_id INT(11), ptitle VARCHAR(200), pfy INT(4), pout_years INT(11))
BEGIN

DECLARE new_bud_id INT(11);

DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,
@errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
SET @full_error = CONCAT(“ERROR “, @errno, ” (“, @sqlstate, “): “, @text);
ROLLBACK;
SIGNAL SQLSTATE ‘45000’
SET MESSAGE_TEXT = @full_error, MYSQL_ERRNO = 1001;
END;

START TRANSACTION;

SET @TRIGGER_CHECKS = FALSE;

— Procedure work that may raise errors is done here

COMMIT;

SET @TRIGGER_CHECKS = TRUE;
END $$
DELIMITER ;

Posted in Uncategorized | Leave a comment

Resetting the MFC brother toner end of life message

My brother MFC 9440CN printer said something like Yellow toner end of life.

I knew these high capacity toners should not be out of life. It is just like the car maintenance indicator.

But my printer wouldn’t print!

So I found this to reset it — worked like a charm.

With power on, open the toner access main door. You will get a “Cover is Open” message on the LCD.
Press the “Clear/Back” button and you will be taken to the toner “Reset Menu”
You can then scroll through the reset options for the printer’s toner cartridges:
B.TNR-S – Black toner small cartridge (TN-110)
B.TNR-H – Black toner high-capacity cartridge (TN-115)
C.TNR-S – Cyan toner small cartridge (TN-110)
C.TNR-H – Cyan toner high-capacity cartridge (TN-115)
M.TNR-S – Magenta toner small cartridge (TN-110)
M.TNR-H – Magenta toner high-capacity cartridge (TN-115)
Y.TNR-S – Yellow toner small cartridge (TN-110)
Y.TNR-H – Yellow toner high-capacity cartridge (TN-115)
Select the cartridge size you have and the colour you want to reset, and press OK. Since I had small cartridges, I used the S options for all three colours.
Each cartridge must be reset individually. Press “1″ to reset.
Press “Clear/Back” to get out of the menu, then close the door.

 

It’s possible to reset the values for other consumables on the printer as well. Hold down both 3 and 9 at the same time, and you’ll get a menu to reset:
Drum
Belt Unit
PF Kit MP
PF Kit 1
PF Kit 2
Fuser
Laser

 

Posted in Uncategorized | Leave a comment

Oracle – spool sql to file with on the fly gzip compression

To run SQL dumps through gzip compression on the fly

1) Create a named pipe to destination for the sql spool using this command:

mknod output.pipe p

2) run a process in the background to compress any data sent to the named pipe

nohup gzip -c < output.pipe > output.gz &

3) Set up your SQL to spool to the named pipe

set feedback off
set heading off
set pagesize 0
set linesize 2000
set space 0
set newpage 0
set verify off
set termout off
set echo off
set wrap off
set flush off
set trimspool on
spool ‘output.pipe’;
select XXXX from XXXX
spool off;
exit;

4) Run the SQL and the output will be zipped up as it is created and put in the output.gz file…

Posted in Uncategorized | Leave a comment

Using rsync to backup windows files to linux server

I set up my fathers windows PC to backup his pictures to my linux server using the following steps:

Download grsync for windows from here: http://sourceforge.net/projects/grsync-win/

From Command Prompt set up “public/private key pair”

cd C:\Program Files\Grsync\bin

ssh-keygen

Just take defaults and it saves the id_rsa.pub and id_rsa.key to a .ssh directory under you windows User directory.

Next Copy this file up to the server using the scp command (comes with grsync)

scp -p22 c:\Users\USERNAME\.ssh\id_rsa.pub username@linux_hostname_or_ip:/tmp

Then from the linux server put the id_rsa.pub file contents in /home/username/.ssh/authorized_keys file

mkdir /home/username/.ssh
cat /tmp/id_rsa.pub > /home/username/.ssh/authorized_keys
chmod 600 /home/username/.ssh/authorized_keys file

Then test to see if you can get in without password prompt using ssh command

ssh.exe -p22 username@linux_hostname_or_ip

If it lets you in without a password you’ve got it configured properly and are ready to use rsync to back it up

Now make a batch file called mybackup.bat file with this command (ALL ON ONE LINE)

C:\Program Files\Grsync\bin\rsync -az –progress –rsh=”./ssh.exe -p22″ /cygdrive/c/PATH_ON_C_TO_SYNC username@linux_hostname_or_ip:/PATH_TO_SERVER_LOCATION

When you run the bat file the first time it will copy everything.

If you run later it will copy only the changed files.

You can add this bat file to a scheduled job to have an automated backup process.

NOTE: The -p22 reference is specifying the default port 22 for ssh — change it if you have configured SSH to listen on a different port.

Also — Make sure your firewalls are open to allow incoming SSH traffic on the specified port on the server location.

 

Posted in Uncategorized | Tagged | Leave a comment

Preventing caching in php

Sometimes when you have php programs that render data from databases, after updating the data from a webpage the server will cache the results from before the update effectively showing wrong data.

We found this to be especially problematic with MSIE. Internet Explorer seems to try to re-use the data when we navigate between jquery tabs in IE.

To fix this we made the programs that render the tab content send these HTTP headers to prevent cacheing:

//Set no caching
header(“Expires: Mon, 28 Jul 1997 05:00:00 GMT”);
header(“Last-Modified: ” . gmdate(“D, d M Y H:i:s”) . ” GMT”);
header(“Cache-Control: no-store, no-cache, must-revalidate”);
header(“Cache-Control: post-check=0, pre-check=0”, FALSE);
header(“Pragma: no-cache”);

This seems to solve the problem.

Posted in Uncategorized | Leave a comment

MYSQL DEFINER

There are issues when you use mysqldump to dump a database and it contains DEFINER=root@x.x.x.x type references. THese are typically in the create procedures or trigger statements. The dump files contain the actual machine name even though the source .sql used to create the procedures or trigger uses CURRENT_USER syntax..

Problems arise when you reload this mysqldump on another machine and the DEFINER does not exist there. You may not have problems until you try and DUMP that database and you’ll get errors like this:.

The user specified as a definer (‘XXX’@’XXX’) does not exist

To fix this use sed to edit the DEFINER statements in the mysqldump before reloading it on another machine like this:

sed -re ‘s/DEFINER=`[^`]+`@`[^`]+`/DEFINER=CURRENT_USER/g’ mydb.dmp.sql | mysql -uroot -hdbhost -p schemaname

This uses sed with -r for extended regular expression support to convert the DEFINER = statements in the dump to CURRENT_USER which will always exist on the destination machine.

 

Posted in Uncategorized | Leave a comment

Stop IE from prompting for passwords on download of excel

We finally came up with a solution for the IE prompts for PIN multiple times and passwrods.

 

The solution turned out to be adding a Content Header  to treat the xls files as “Attachements”  — this way IE doesn’t try to open see if it can open for “editing”  instead it just gives the user the dialog to open or save choice – If they choose open it just pops open without any delay or extra pin prompts J

 

Here is the Microsoftt page that gave us this IDEA:
http://support.microsoft.com/kb/899927

 

Which we found from here:

http://support.microsoft.com/kb/2019105/en-us

 

The Apache /etc/httpd/conf/httpd.conf change we made to fix this is here:

 

First – make sure the mod_headers module is loaded and then add the yellow below.

 

LoadModule headers_module modules/mod_headers.so

 

 

Order allow,deny

Allow from all

Deny from all

Header set Content-Disposition attachment

Posted in Uncategorized | Leave a comment

esxi clone disk

Command to clone a disk from an esxi VM from command line.

Make sure the VM is shut down.
Then you can just:

cd /vmfs/volumes/Datastore

mkdir NEW_VM

cd SOURCE_VM

vmkfstools -i source.vmdk ../NEW_VM/new_vm.vmdk

 

Posted in Uncategorized | Leave a comment

Using split to break up large file into smaller pieces

You can pipe output of tar to split command to make smaller chunks that are easier to transfer.

tar czv /pathtofiles | split -b 1000M -d – “test.tar.gz.”

Then to untarr you can use this command:

cat test.tar.gz.* | tar tzvf –

Posted in Uncategorized | Leave a comment