Useful Perl script – convert text to ascii

[problem]

You want to convert text to ascii values.

[/problem]

[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/perl  while(sysread(STDIN,$a,1)) {  $c=ord($a);if($c==10) { print "n"; } else { print "&#$c;"; }  }  exit(0);  __END__ 

[/solution]

[example]

Here is a screen shot:

convert characters to ascii values in perl

[/example]

[reference]

[/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.

[/problem]

[solution]

Below is the typical ‘hello world’ script

[/solution]

[example]

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

[/example]

[reference]

Microsoft technet tips on beginning vb scripting

[/reference]

Switch to a different user in MS Windows / DOS

[problem]

You want to switch user from the MS DOS prompt.

[/problem]

[solution]

Use runas

runas /?

[/solution]

[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" ...

[/example]

Setting file permissions from command line in windows

[problem]

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

[/problem]

[solution]

Use cacls

cacls /?

[/solution]

[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:F PCxxxxxxxxxxxxAdmin:F
  • Modify permissions. Here we are granting full access to the user, replace user with desired user name.
> cacls filename /E /G user:F processed file: C:...filename
  • Here we see the permissions have been reset:
> cacls filename ...filename           PCxxxxxxxxxuser:F NT AUTHORITYSYSTEM:F PCxxxxxxxxxxxxxAdmin:F

[/example]

Useful PHP tool to create an image with superimposed text

[problem]

You want to create an image text label.

[/problem]

[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.

  

[/solution]

[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.

[/example]

[reference]

[/reference]

[tags]Image, PHP[/tags]

MySQL backup db script

[problem]

You want to back up your mysql database.

[/problem]

[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.

[/solution]

[example]

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

[/example]

[tags]MySQL, Backups[/tags]