Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Update to ClamAV 0.94

Compile ClamAV from source on Mac OS X, but apply the following changes to /private/var/clamavadmin/clamd.conf.
# cf. man 5 clamd.conf after update

# delete the following two lines in /private/var/clamavadmin/clamd.conf
ArchiveMaxFileSize 100M
ArchiveMaxCompressionRatio 0

# add the following two lines to /private/var/clamavadmin/clamd.conf
MaxFileSize 300M
MaxScanSize 150M

References:
- What's New: ClamAV 0.94
- What's New: ClamAV 0.94.1

Update your Bash shell via MacPorts

Just following the steps described in this neat summary.

For information on how to install MacPorts see here and here.

export PATH="/opt/local/bin:/opt/local/sbin:/opt/local/lib:/opt/local/include:/opt/local/man:/usr/bin:/bin:/usr/sbin:/sbin"
export IFS=$' \t\n'


1.
/opt/local/bin/port info bash
/usr/bin/sudo /opt/local/bin/port -c install bash

2.
# add '/opt/local/bin/bash' to /private/etc/shells
/usr/bin/sudo /usr/bin/nano /private/etc/shells

3. 
# enable UTF-8 support by adding to your ~/.bash_login (or alternatives):
# /usr/bin/locale -a
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

4.
man chsh
# run chsh and change the path of the shell to /opt/local/bin/bash
chsh

5.
# set encoding of Terminal.app to UTF-8
/usr/bin/defaults read com.apple.Terminal StringEncoding
/usr/bin/defaults write com.apple.Terminal StringEncoding -int 4

/usr/bin/defaults read com.apple.Terminal DoubleWideChars
/usr/bin/defaults write com.apple.Terminal DoubleWideChars -bool YES

kill -HUP $$
#killall -HUP Terminal


6.
# [cmd-,]
Terminal -> Preferences... -> select: Execute this command (specify complete path): /opt/local/bin/bash


#---------------------------------------------------------------------------


# Bash 3.0 Announcement
# http://groups.google.com/group/gnu.announce/msg/e05c4cbeecdb24c7
# http://en.opensuse.org/Bash

bash --version
which bash

dscl . read /Users/$(/usr/bin/logname) UserShell

man 7 re_format     # POSIX 1003.2 regular expressions
man /opt/local/share/man/man1/bash.1.gz 2>/dev/null | less -p '=~'
man /opt/local/share/man/man1/bash.1.gz 2>/dev/null | less -p regex

# new feature of Bash 3.0 ff.: in-process regular expression matching
str='abc def'
if [[ "${str}" =~ 'c d' ]]; then printf "%s\n" "${BASH_REMATCH[0]}"; fi

printf "%s\n" "${BASH_REMATCH[0]}"
printf "%s\n" "${#BASH_REMATCH[*]}"
printf "%s\n" "${#BASH_REMATCH[@]}"

SQL Update with Values from Second Table

// Update multiple fields in a table based on values in a second table. This prevents you from having to use multiple sub-queries.

UPDATE table
SET col1 = a.col1, col2=a.col2
FROM anotherTable a
WHERE a.anotherTableID = 1

Scripting schema updates in MSSQL #1

This SQL statement will alter a table only if a column in the table to be altered does NOT contain a column named 'FavoriteColorId'.

From: http://haacked.com/

IF NOT EXISTS
(
    SELECT * FROM [information_schema].[columns]
    WHERE    table_name   = 'Customer'
    AND      table_schema = 'dbo'
    AND      column_name  = 'FavoriteColorId'
)
BEGIN
    ALTER TABLE [dbo].[Customer]
    ADD FavoriteColorId int

How to update something using a patch (Wordpress, pmwiki etc.)

After unzipping, taring or whatever archive you used copy thepatch over the old files, replacing them.

Copy the files in your newly extracted directory (pmwik-new/wordpress-patch) over the files of your existing software installation. For example, if your existing PmWiki/Wordpress installation is in a directory called pmwiki/wordpress, then one way to copy the new files over the existing ones is to enter the command:
cp -a pmwiki-new/. pmwiki


Note that BSD systems will not have the -a option as a command-line argument for cp, but that's okay, since it's just shorthand for cp -dpR, so use that instead of -a.

On (some) FreeBSD servers and Mac OS X systems you need to use
cp -Rpv pmwiki-new/. pmwiki 

This works well on TxD shared hosting.

Update From sample

// sample "update from" sql statement

UPDATE 
	[Crm].[tbPartyLegalEntityData]
SET 
	[CompanyType] = ape.[CompanyType],
	[EmployeesCount] = ape.[EmployeesCount]
FROM 
	[Crm].[tbPartyLegalEntityData] p
INNER JOIN 
	App.[tbApplicationPersonEmployer] AS ape 
ON 
	ape.[Bulstat] = p.[Bulstat]
WHERE 
	ape.[Bulstat] <> '!' 
	AND [ape].[EmployeesCount] IS NOT NULL 
	AND [ape].[CompanyType] IS NOT NULL

count duplicate users and store in db - sql

// count duplicate users and store in db

// count users with filter
select Count(surname+firstname) as duplicates, surname, firstname
from c_contact
where show_record=1
group by surname, firstname
having Count(surname+firstname) > 1
order by duplicates, surname, firstname

// original code
SELECT column,COUNT(*) c 
FROM table
GROUP BY column 
HAVING COUNT(*) > 1

//update code
update c_contact
set duplicates = dbo.func_get_duplicates(surname, firstname)