Find duplicate rows in MS SQL

by Syska 17. March 2010 17:51

So, the other day I was reading T-SQL: Why “It Depends” and in the comments section a guys suggested using the “PARTITION BY” in the OVER clause.

I thought was the heck does that do … so i searched the web for an answer … and wow … what a great way to find duplicate post … and possible also a lot of other things it can be used for that I haven’t thought about.

To the code …

WITH Data AS
(
	SELECT 
	ROW_NUMBER() OVER ( PARTITION BY CID ORDER BY Added DESC) AS DupeNumber
	,CID, Added
FROM Servers
)
SELECT * FROM Data Where DupeNumber >= 2

This will check for dupes on the CID column … and then select all the rows where DupeNumber is over or equal to 2. You could then instead of select it … you could delete it.

Fancy way … I like it.

Tags: , , ,

windows 7

Tcpdump – The ultimate tool for traffic analysis

by Syska 9. March 2010 14:50

Hello, so the other day I say that out external IP address was black listed on some black list … I used:
http://www.dnsbl.info/dnsbl-database-check.php
http://rbls.org/
http://whatismyipaddress.com/staticpages/index.php/is-my-ip-address-blacklisted

They are all similar, but maybe they show different result, if there database are outdated or the site could be down. Always a good idea to control the IP address against more sites.

So … we were black listed … but why. Back to the console on the firewall.

eth0 is my internal interface on the 172.17.4.0 network.

tcpdump -i eth1 net 172.17.4
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth1, link-type EN10MB (Ethernet), capture size 96 bytes
08:23:01.219395 IP x.x.x.x.dynamic.altibox.net.63486 > 172.17.4.251.distinct32: . ack 142967821 win 256
08:23:01.335626 IP 172.17.4.113.53814 > 93.152.158.87.47834: . 272803351:272804803(1452) ack 3427659943 win 16139 08:23:01.871096 IP pool-x-x-x-x.chi01.dsl-w.verizon.net.50129 > 172.17.4.251.distinct32: . ack 3979841491 win 62356 <nop,nop,timestamp 14764517 2569468>

This showed way to much information … back to reading the “man” pages for tcpdump. Then I saw that I could use logical operators and bit masking … now its getting fun. Also possible to look in the ip, tcp or udp package.

The DHCP server here only serves address from 100 and up … and as there are SMTP servers below that, we need to filter them out … looking at Figure 1, the source address is the 12byte and the next 4. We got the net address already …not we need to filter on the 4 octet.

tcpdump -i eth1 net 172.17.4 and \(ip[15] \>= 100\)

We can filter the port in 3 ways … either look at the tcp package or use “port 25” or “port smtp” in the name are located in the /etc/services file.

Doing the first … and looking at figure 2, we can see that we need read 2 bytes and have an offset of 2. Like “tpc[offset:bytes] = 25” and append it to the command we end up with the following.

tcpdump -i eth1 net 172.17.4 and \(ip[15] \>= 100\) and tcp[2:2] = 25
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth1, link-type EN10MB (Ethernet), capture size 96 bytes

This gives endless options … you can detect anything. Look in the data package … I’m amazed, this was not the first time using it, but probably the first time I understand all the options and possibilities it gives you.

Happy tcpdump’ing … :-)

Figure 1. IPv4 header

MJB-IP-Header-800x576

Figure 2. TCP header

MJB-TCP-Header-800x564

Tags: , , ,

Unix/Linux

Windows 7 Tips – Shortcuts

by Syska 5. December 2009 18:12

In windows 7 there are several great shortcuts that can make you day in front of the computer better, and here are some of them than I use often … and some of them I just know of.

Windows + Arrow

You can move the active window around on the screen.

capper-16 capper-18
Windows + Left Arrow
Will dock the window to the left
Windows + Right Arrow
Will dock the window to the right
capper-19 capper-17
Windows + Arrow up
Will maximize the window to the current screen.
Windows + Arrow Down
(do it again and it will minimize)

Windows + Shift + Arrow up

Like the shortcuts above, hitting these keys will stretch the active window vertically. Pressing Windows + Down will restore it to the previously size.

Alt + P

Alt_P

When you are in a explorer and want to preview things. Pressing Alt + P will bring up a preview window in the left part of the Explorer window. It can be used on all types of documents … but there is a startup time for them and depending on the time of document the first preview can take some time show.

Windows + + ( plus key ) and Windows + – ( minus key )

capper-21

Brings up the magnifier, so if you are showing something on a projector on a daily basis this is great. Consider you are showing how a program works, instead of lowering the resolution to something like 800x600 … you can just quickly zoom in on it.

You can of cause zoom out again using the other shortcut – Windows + – ( minus key )

capper-20 

Windows + P

capper-8

Will manage multiple monitor setup more easily or if you just connected a projector. Pressing the key P again while holding down the Windows key will loop over the available options.

Windows + [number]

capper-23

Here in my Taskbar i have:

  1. visionapp Remote Desktop 2010
  2. Visual Studio 2008
  3. Firefox ( of cause )
  4. Messenger
  5. Total Commander
  6. Windows Explorer
  7. Photo Viewer

Pressing Windows + 7 and this will bring up the Photo Viewer if there were only one instance. Here i got 2 so it lets to toggle between them. If there are no instance running of the program it will start one for you.

Ctrl + Click

capper-15

Holding down Ctrl while clicking a program icon in the taskbar will toggle between the instances. For example like in the above, that would toggle between the 2 instances of the Photo viewer. Here used with two instances of the Windows Explorer started.

Ctrl + Shift + Click

This will start the program clicked on with full administrative rights on the system. While not very useful I, it can be used as pinned programs to the Taskbar, would require more clicks, so it saves a little time :-)

Conclusion

These are some of the best shortcuts I have found to date, but there are still more I guess … so in the future I will update this blog post if I find any.

You you got any that you think is missing, please to post them as comments or contact me, and I will add them.

Tags: , , ,

About the brain

Mikael SyskaMikael Syska

Student at the Engineering College of Aarhus.

Microsoft Student Partner ( MSP )

On this blog I will primarily write about .NET, MSSQL & projects I'm working on ... and of course there will some off topic posts :-)