Useful Perl script – convert text to ascii

Problem

You want to convert text to ascii values.



Solution

Perl script to convert standard input to ascii values, useful with web code.

You can take the output and insert directly into HTML pages.

#!/usr/bin/perlwhile(sysread(STDIN,$a,1)) {$c=ord($a);if($c==10) { print "n"; } else { print "&#$c;"; }}exit(0);__END__


Example


Here is a screen shot:

convert characters to ascii values in perl



Reference



First steps in vb scripting for windows / DOS

Problem

Starting out with a new series of tips, getting started with vb scripting. Microsoft have an excellent guide on the site, which I’ve link at the bottom of this post.



Solution

Below is the typical ‘hello world’ script



Example


C:\Documents and Settings\Admin > copy con test.vbsWscript.echo "Hello World."^Z1 file(s) copied.C:\Documents and Settings\Admin > cscript test.vbsMicrosoft (R) Windows Script Host Version 5.6Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.Hello World.




Switch to a different user in MS Windows / DOS

Problem

You want to switch user from the MS DOS prompt.



Solution

Use runas

runas /?


Example


Switch user to other id (Then just run explorer and browse to directory)

runas /user:USERID@xxx c:\winnt\system32\cmd.exe

Where user-id is the USER you wish to change to. For example Admin. xxx represents the hostname of the box or domain.

You can also just use local, if changing to user on the same box, like this:

C\:Documents and Settings\Admin runas /user:localmarcus "c:\WINDOWS\system32\cmd.exe"Enter the password for localmarcus:Attempting to start c\:WINDOWS\system32\cmd.exe as user "localmarcus" ...


Reference



Setting file permissions from command line in windows

Problem

You want to modify permissions in Windows from the DOS prompt command line.



Solution

Use cacls

cacls /?


Example


Here are the commands to modify MS Windows/DOS files and directories.

  • Display file permissions. Replace filename with your file name.
> cacls filename...filename            NT AUTHORITYSYSTEM:FPCxxxxxxxxxxxxAdmin:F
  • Modify permissions. Here we are granting full access to the user, replace user with desired user name.
> cacls filename /E /G user:Fprocessed file: C:...filename
  • Here we see the permissions have been reset:
> cacls filename...filename           PCxxxxxxxxxuser:FNT AUTHORITYSYSTEM:FPCxxxxxxxxxxxxxAdmin:F


Reference



Useful PHP tool to create an image with superimposed text

Problem

You want to create an image text label.



Solution

Use GD library that can be built-in to PHP. Or just use my free on-line tool to create it, as shown in example below.

Once GD is built in – use this PHP code to generate the label.



Example


This shows the label .

You can use this to generate black blank images, with white superimposed text over the top:

generate black blank images, with white superimposed text .. click this link, change text "label" – then save to your machine.



Reference



MySQL backup db script

Problem

You want to back up your mysql database.



Solution

This script is good for backups, as it will generate a dump – zipped and as the day of the week is used (in the backup file name), automatically rolls every 7 days.

Run it daily or every other day. If you want a months worth, guess can just change the date command, etc.



Example


#!/bin/zsh[ $# -ne 1 ] && {    echo "Usage: $0 db"    exit 1}db=$1dbd="/PATH_TO_YOUR_BUS/$db.$(/bin/date +%a)"    # set the pathalias mysqldump="/usr/bin/mysqldump"            # you may need to modify thisalias gzip="/bin/gzip"                          # may need to change this too# set your password and usermysqldump --user=root --password=your_password $db > $dbd gzip --best --force $dbdexit 0


Reference