How to create / consume a .Net web service

[WebService(Namespace = "http://server")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class myservice : WebService {
[WebMethod]
public string someq(string var1, string var2)
{
return var1+var2;
}

<?php
$wsdl = "http://server/service.asmx?wsdl";
$client = new SoapClient($wsdl);
var_dump($client->someq(array('var1'=>"val1", 'var2'=>"val2")));
?>

How to fix a database in one simple step

DECLARE @db nvarchar(50)
set @db='my.datab.name'
--close all connections
DECLARE @SPId int
DECLARE @CMD varchar(100)
DECLARE my_cursor CURSOR FAST_FORWARD FOR
SELECT SPId FROM MASTER..SysProcesses
WHERE DBId = DB_ID(@db) AND SPId <> @@SPId
OPEN my_cursor
FETCH NEXT FROM my_cursor INTO @SPId
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @CMD = 'KILL ' + CAST(@SPId AS varchar(10))
EXEC (@CMD)
FETCH NEXT FROM my_cursor INTO @SPId
END
CLOSE my_cursor
DEALLOCATE my_cursor
exec('ALTER DATABASE ['+ @db +'] SET SINGLE_USER WITH NO_WAIT')
dbcc checkdb(@db, REPAIR_ALLOW_DATA_LOSS)
exec('ALTER DATABASE ['+ @db +'] SET MULTI_USER WITH NO_WAIT')

try another dbcc checkdb afterwards to be sure it’s fixed

How to read a .ini file in .Net

There is no ready-made class, so you’ll have to call the Windows API

[DllImport("KERNEL32.DLL", EntryPoint = "GetPrivateProfileStringW",
SetLastError = true,
CharSet = CharSet.Unicode, ExactSpelling = true,
CallingConvention = CallingConvention.StdCall)]
private static extern int GetPrivateProfileString(
string lpAppName,
string lpKeyName,
string lpDefault,
string lpReturnString,
int nSize,
string lpFilename);
[DllImport("KERNEL32.DLL", EntryPoint = "WritePrivateProfileStringW",
SetLastError = true,
CharSet = CharSet.Unicode, ExactSpelling = true,
CallingConvention = CallingConvention.StdCall)]
private static extern int WritePrivateProfileString(
string lpAppName,
string lpKeyName,
string lpString,
string lpFilename);


Continue reading "How to read a .ini file in .Net"

Useful Perl date tricks

perl -MDate::Manip -e 'Date_Init("Language=Romanian","DateFormat=non-US"); print UnixDate(DateCalc("azi","+ 18 zile lucratoare"),"%A, %e %B %Y%n")'

Output: marti, 8 decembrie 2009

perl -MDate::Manip -e 'Date_Init("Language=Romanian","DateFormat=non-US"); @date=ParseRecur("fiecare simbata din decembrie"); foreach (@date) {$d=UnixDate($_, "%A, %e %B %Y%n"); $d=~s/(\w+)/\u\L$1/g; print $d}'

Simbata, 5 Decembrie 2009
Simbata, 12 Decembrie 2009
Simbata, 19 Decembrie 2009
Simbata, 26 Decembrie 2009

How to change the soundtrack for a bunch of video files

@echo off
for /f %%f in ('ls -1 *avi') do c:\mplayer\mencoder.exe -ovc copy -nosound %%f -o %%~nf.dump
for /f %%f in ('ls -1 *wav') do c:\mplayer\ffmpeg.exe -i %%f -acodec libmp3lame -ar 44100 -ab 64k -ac 1 %%~nf.mp3

avi
for /f %%f in ('ls -1 *dump') do c:\mplayer\mencoder.exe -ovc copy -oac copy -audiofile %%~nf.mp3 %%f -o %%~nf.2.flv
flv (couldn’t find a way to remux without reencoding)
for /f %%f in ('ls -1 *dump') do c:\mplayer\mencoder.exe -vf scale=720x576 -af volume=+16db -ovc lavc -lavcopts dia=2:precmp=2:cmp=2:subcmp=2:vcodec=flv:vbitrate=1024 -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -of lavf -ffourcc FLV1 -oac copy -audiofile %%~nf.mp3 %%f -o %%~nf.2.flv

ls is a dir replacement from here

Bad Behavior has blocked 85 access attempts in the last 7 days.