Where does DisplayRecorder save the videos in your iPhone?

January 11, 2012 Leave a comment

SFTP: /private/var/mobile/Library/Keyboard/DisplayRecorder

Categories: Uncategorized

SQL – Check If A Table Exists

March 11, 2011 Leave a comment

Check if a table exists in a database:

IF OBJECT_ID(‘database.dbo.table’) > 0
BEGIN
   //Code to run if table exists. e.g. delete table.
   //drop table database.dbo.table
END

 

 

Categories: SQL Tags: , , , ,

SQL – How to get the status of an SQL job (sp_help_job)

March 8, 2011 3 comments

 

Here is a simple script using sp_help_job to display information about jobs that are used by SQL Server Agent:

USE msdb
EXEC dbo.sp_help_job @JOB_NAME = ‘JOB_NAME’, @job_aspect=‘JOB’

Look for ‘current_execution_status’ to get the status of the job.

1 = Executing.
2 = Waiting for thread.
3 = Between retries.
4 = Idle.
5 = Suspended.
7 = Performing completion actions.

 

Here is a more detailed script to store the results of sp_help_job into a table and query the results:

DECLARE @JOBNAME VARCHAR(100)
SET @JOBNAME = ‘JOB_NAME’

CREATE TABLE #JOBSTATUS(
       job_id uniqueidentifier 
      ,originating_server nvarchar(30)
      ,name sysname
      ,enabled tinyint
      ,description nvarchar(512)
     
,start_step_id int
     
,category sysname
     
,owner sysname
      ,notify_level_eventlog int
     
,notify_level_email int
     
,notify_level_netsend int
     
,notify_level_page int
     
,notify_email_operator sysname
     
,notify_netsend_operator sysname
     
,notify_page_operator sysname
     
,delete_level int
     
,date_created datetime
     
,date_modified datetime
     
,version_number int
     
,last_run_date int
     
,last_run_time int
     
,last_run_outcome int
     
,next_run_date int
     
,next_run_time int
     
,next_run_schedule_id int
     
,current_execution_status int
     
,current_execution_step sysname 
     
,current_retry_attempt int
     
,has_step int
     
,has_schedule int
     
,has_target int
     
,type int     
); 

INSERT INTO #JOBSTATUS
EXEC dbo.sp_help_job
 @JOB_NAME = @JOBNAME
,@job_aspect=‘JOB’

SELECT CASE current_execution_status
WHEN ’0′ THEN ‘Returns only those jobs that are not idle or suspended. ‘        
WHEN ’1′ THEN ‘Executing.’
        
WHEN ’2′ THEN ‘Waiting for thread.’
       
WHEN ’3′ THEN ‘Between retries.’
        
WHEN ’4′ THEN ‘Idle.’

WHEN ’5′ THEN ‘Suspended.’

WHEN ’6′ THEN

WHEN ’7′ THEN ‘Performing completion actions.’

ELSE ‘UNKNOWN’
END as ‘current_execution_status’
FROM #JOBSTATUS

DROP TABLE #JOBSTATUS

 

OUTPUT:


current_execution_status
——————————————————–
Idle.

SQL – How to get the day of the week

Using the DATEPART function to calculate the integer value of the day of the week.

select datepart(dw,getdate()) as DayOfWeekINT


Output:
DayOfWeekINT
————
2  

1 = Sunday
2 = Monday
3 = Tuesday
4 = Wednesday
5 = Thursday
6 = Friday
7 = Saturday

Using the DATENAME function to calculate the  day of the week.

select datename(dw,getdate()) as DayOfWeekCHAR


Output:
DayOfWeekCHAR
——————————
Monday
 
 

 

You can get the day of the week for a given date (MM/DD/YYYY) using:

select datepart(dw,’03/07/2011′) as DayOfWeekINT
select datename(dw,’03/07/2011′) as DayOfWeekCHAR

 

How To Export Contacts / Address Book From BlackBerry To PC

August 12, 2010 3 comments

This step-by-step guide details how to export a BackBerry address book to a CSV / TXT file on a PC using BlackBerry Desktop Manager V5.

To configure the export

1) Open BlackBerry Desktop Manager.
2) Click Synchronize towards the right-hand side of the main screen.
3) Click Synchronize under the Configure heading from the menu on the left-hand side.
4) Click the Synchronization button on the right-hand side next to Configure synchronization settings for my desktop program.
5) A new window opens titles Intellisync. Make sure that Address Book is ticked, and untick all the other options.
6) Double-click on Address Book.
7) A new window will open title Address Nook Setup. Select ASCII Importer/Exporter and hit the Next button.
8) On the next screen select One way sync from device and hit the Next button.
9) Hit the Browse button and navigate to a folder to store your contacts. Enter a file name e.g. Contacts.csv and click Open.
10) Hit the Next button then hit the Finish button.
11) Back on the Intellisync window hit the OK button to save the changes.

To Run The Export

1) On BlackBerry Desktop Manager in the Synchronize screen, select Synchronize from the menu on the left-hand side.
2) Make sure that Synchronize organizer data check box is ticked.
3) Click the Synchronize button.

When the synchronization has completed, your address book will have been exported from you BlackBerry device to the file specified earlier.

JAVA – Hot To Rename a File or Directory.

A quick script to re-name a file or folder:

Import required:

import java.io.File;

Code:

try{       
        // File name (or directory) of the file to be renamed
        File file = new File(“c:/file1.txt”);
        // New File name (or directory)
        File file2 = new File(“c:/file2.txt”);
        // Rename file (or directory)
        file.renameTo(file2);
    }catch(Exception e){
        e.printStackTrace();
    }

Categories: Java Tags: , , , , ,

SQL – How To Shrink Un-shrinkable Database Log / Database Log Won’t Shrink SQL Server 2008

June 24, 2010 1 comment

To shrink the transactional logs in SQL Server 2005 follow this link:
http://robbamforth.wordpress.com/2009/11/16/sql-how-to-shrink-un-shrinkable-database-log-database-log-wont-shrink/

In SQL Server 2008 it’s a matter of changing the recovery model to SIMPLE and re-running the DBCC SHRINKFILE  command – assuming the current recovery model is FULL.

Firstly, here is a quick script to backup the database and also the transactional log (if required to back up separately) to disk:

– QUICK SCRIPT TO BACKUP THE DATABASE TO DISK
BACKUP DATABASE [DATABASE]
TO DISK = ‘c:\backup\DATABASE.BAK’
WITH NOFORMAT, NOINIT, NAME = ‘DATABASE-Full Database Backup’,
SKIP,NOREWIND,NOUNLOAD,STATS = 10– QUICK SCRIPT TO BACKUP THE LOG FILE TO DISK
BACKUP LOG [DATABASE]
TO DISK = ‘c:\backup\DATABASE_LOG.BAK’
WITH NOFORMAT, NOINIT,  NAME = ‘DATABASE-Transaction Log  Backup’,
SKIP, NOREWIND, NOUNLOAD, STATS = 10

 

 

Step 1: View the current recovery model configuration.

– SHOW AVAILABLE DATABASES AND THEIR CURRENT RECOVERY MODEL CONFIGURATION
select name,recovery_model_desc from sys.databases

 

Step 2: Change the recovery model to SIMPLE.

–CHANGE THE RECOVERY MODEL CONFIGURATION TO SIMPLE
Alter database [DATABASE] set Recovery simple

 

Step 3: Use DBCC SHRINKFILE to truncate the transactional logs of the database.

– USE BDCC CHRINK FILE TO TRUNCATE THE TRANSACTIONAL LOGS
USE [DATABASE]
GO
DBCC SHRINKFILE ([DATABASE_LOG], 0, TRUNCATEONLY)
GO

 

Step 4: Return the recovery model back to FULL if required.

– CHANGE TEH RECPVERY MODEL BACK TO FULL IF REQUIRED
Alter database [DATABASE] set Recovery full

 

  

JAVA – How To Convert Integer (INT) To Hexidecimal (HEX)

Integer to Hexidecimal string:

int intVal = 123;
String hexVal = Integer.toHexString(intVal);
System.out.println(“Hexidecimal: ” + hexVal);

Output:

Hexidecimal: 7b

Hexidecimal string to Integer:

String hexVal = “7b”;
int intVal = Integer.parseInt(hexVal,16);
System.out.println(“Integer: ” + intVal);Output:

Output:

Integer: 123

Categories: Java Tags: , , , , ,

JAVA – How To Get The Current Directory

The following script gets the current directory at runtime:

import java.io.File;

public class CurrentDir {
   public static void main (String args[]) {
     File dir = new File (“.”);
     try {
       System.out.println (“Current Directory : ” + dir.getCanonicalPath());       }
     catch(Exception e) {
       e.printStackTrace();
       }
     }
}

The same logic can be used to get the parent to the current directory:

import java.io.File;

public class ParentDir {
   public static void main (String args[]) {
     File dir = new File (“..”);
     try {
       System.out.println (“Parent  Directory : ” + dir.getCanonicalPath());
       }
     catch(Exception e) {
       e.printStackTrace();
       }
     }
}

SQL – How To Restore A Suspect Database SQL Server 2005

Occasionally an SQL database can lock-down in suspect mode. There are many causes, but the main is an expected shot-down or power loss. I had a slightly loose fitting CPU fan (and I mean ightly, one of the pins was a little less secure than the rest) in a server running SQL server 2005. It took a morning of stripping back the chassis to find it. Since re-seating the fan pins all is well.

To cut a long story short, the following script allowed me to restore the suspect database in its entirety. SQL server 2005 comes with the DB status of Emergency. This can be used to alter the status from Suspect mode (in which the database is inaccessible), to Emergency mode where you can gain access to the database and retrieve data from the tables along with those all important stored procedures and other scripts.

Once in Emergency mode you can re-run DBCC checkDB to check the integrity of all the pages and structures that make up the tables.
This script uses the REPAIR_ALLOW_DATA_LOSS argument which tries to repair all reported errors. These repairs can cause some data loss. Hopefully you have a recent back up, if not take backups from the database while you can access it in emergency mode!
REPAIR_ALLOW_DATA_LOSS is used to ensure the database is returned to a structurally and transitionally consistent state

This cannot be undone.

Here is the script:

EXEC sp_resetstatus DATABASENAME;
ALTER DATABASE DATABASENAME SET EMERGENCY
DBCC checkdb(DATABASENAME)
ALTER DATABASE DATABASENAME SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DBCC CheckDB (DATABASENAME, REPAIR_ALLOW_DATA_LOSS)
ALTER DATABASE DATABASENAME SET MULTI_USER

Follow

Get every new post delivered to your Inbox.