Archive for the ‘SQL’ Category

10 more pointless (but awesome) Linux terminal tricks

One year ago, I put together a list of my favorite “pointless but awesome” Linux terminal tricks—filled with such classics as making a cow talk with “cowsay” and rainbow-coloring your terminal with “lolcat.”  As was correctly pointed out to me at the time, there are a lot of ridiculous (but cool) things you can do in the terminal that didn’t make that list. So, here’s round two. You’re welcome. (Note: Some of these you will need to install using apt-get, zypper or whatever package manager your Linux distribution uses.)

I’m 99 percent sure that every one of you has seen this. A full version of Star Wars Episode 4: A New Hope. Entirely in the terminal. And entirely via telnet. Simply pop open your terminal, type “telnet towel.blinkenlights.nl”, then sit back and enjoy this cinematic masterpiece in all its ASCII glory.

This one dates all the way back to 1983—33 years ago—with the release of https://en.wikipedia.org/wiki/UNIX_System_V. The “cal” program, short for “calendar,” does exactly what you think it does. It displays a calendar. It has a handful of options (like what day a week starts on and what month to display) but only a handful.  Recommendation: pipe “cal” through “lolcat” (“cal | lolcat”) to spice things up a little bit.

Clear your mind of what you think is possible. If you could imagine the most useful terminal command, what would it be? If you said “a command that repeated the same bit of text over and over again until the end of time,” you and the developer of “yes” have something in common! Type, simply ‘yes “repeat this text forever”’ and you’re in business! Again. “lolcat” makes everything better.

Take text, and make it bigger using a bunch of smaller characters. That’s toilet.  Typing ‘toilet “Yo, Dawg.”’ will get you the results you desire.

In 1999, “rig” was born with a singular purpose—to generate fake identities.  From the man page (“man rig”): “It is suitable for such applications as feeding the NY times registration page to fend off junk (snail) mail and telemarketers, or for registering on BBS’s to which you don’t wish to reveal your real information.”

I love “espeak”. Take some text and speak it—with loads of options. Create a .wav file, customizable speaking speed, change the pitch—it’s just wonderful. Extra fun: You can feed content from a text file to read to you or pipe the output of another program into espeak. For example, “rig | espeak” will cause your computer to speak a random, fake person’s name and address. Why would you do that? Who knows. But it’s cool that you can.

What if you want to see the exact number of times that you’ve run every single terminal program? Type “hash”. Note: This doesn’t count the number of times you pipe output through “lolcat.” This bums me out. Because if it did, my main machine might be breaking a world lolcat record right now.

We’re going to get into some very debatable territory here in terms of “pointless-ness.” This program displays an ASCII-fied version of any image—with lots of options. I recommend using “asciiview picture.png -driver curses”. That’s what I do. And be sure to fire up “man asciiview” to see all of the options available.

Admit it—“top” sucks. It’s OK—we’re all thinking it. Written in 1984, “top” is fine for getting some quick stats and finding a process ID. But it’s ugly and not exactly interactive. That’s where “htop” swoops in and saves the day. First released in 2004, “htop” is like “top” only you can move through the running tasks with your arrow keys and issue signals directly to them. It’s handy as all get out. And using this instead of a graphical system monitor will prove you’re one of the cool kids.

The final, and possibly most useful, terminal program on this list is the one that helps you to find other programs. Type “apropos” into your shell, and it will simply ask you: “apropos what?” Type “apropos picture”, and it will display the programs with man pages that have the word “picture” in their name or description. Handy as all get out if you’re trying to find the right tool to use—or goof off with.

Click here to view complete Q&A of 70-417 exam
Certkingdom Review

MCTS Training, MCITP Trainnig

Best Microsoft MCTS Certification, Microsoft 70-398 Training at certkingdom.com

How to calculate Median in SQL Server

Nothing earth-shattering here, I was just helping out a colleague with this so I thought I’d post up the example I gave him. 70-640 Training .

 

Best Microsoft MCTS Certification, Microsoft MCITP Training at certkingdom.com

— sample table:
create table People
(
Person varchar(1) primary key,
City varchar(10),
Age int
)

go

— with some sample data:

insert into People
select ‘A’,’Boston’,23 union all  — odd #
select ‘B’,’Boston’,43 union all
select ‘C’,’Boston’,29 union all

select ‘D’,’Chicago’,15 union all — single #

select ‘E’,’NY’,12 union all  — even #
select ‘F’,’NY’,55 union all
select ‘G’,’NY’,57 union all
select ‘H’,’NY’,61

go

— here’s our query, showing median age per city:

select city,
AVG(age) as MedianAge
from
(
select City, Person, Age,
ROW_NUMBER() over (partition by City order by Age ASC) as AgeRank,
COUNT(*) over (partition by City) as CityCount
from
People
) x
where
x.AgeRank in (x.CityCount/2+1, (x.CityCount+1)/2)
group by
x.City

go

— clean it all up
drop table People

And here’s the result:

city       MedianAge
———- ———–
Boston     29
Chicago    15
NY         56

(3 row(s) affected)

Simply remove “City” from the SELECT clause and the GROUP BY clause to get the median age for all.

There may be more efficient tricks out there, but this is certainly the shortest and simplest technique I am aware of.

 

Microsoft Free MCTS Training and MCTS Online Training.

A Hotels in Malta Theme. Designed by Malta Hotel and Malta Hotels