Wednesday, March 05, 2008

Researchers turn Sun Solaris utility into fuzzing tool

Security researchers have developed a way to turn a utility for Sun Microsystems' Solaris operating system into a rootkit-like, reverse engineering tool that can be deployed to quickly locate application vulnerabilities and create exploits.

The utility, DTrace, is a dynamic tracing, or event logging, function within the Solaris OS that allows systems administrators to monitor a combination of functions, including system performance, statistic debugging information and execution analysis.

Sun designed DTrace to provide operational insights that allow systems administrators to tune and troubleshoot applications and the operating system itself.

Sun released DTrace in 2003 in conjunction with Solaris 10. In 2005, Sun made it available under the Common Development and Distribution License (CDDL) open source license. Apple has since integrated it into its Mac OS X Leopard platform.

The security researchers, Tiller Beauchamp and David Weston, who work at engineering firm Science Applications International Corp. (SAIC), unveiled their findings at the recent Black Hat conference in Washington D.C.

They explained that DTrace provides a framework for performance observability and debugging in real time. With DTrace, system administrators can set probes within their operating environment, then define a metric they want to measure or record.

The tool's ability to take an in-depth look at the operating system and its applications make it ideal not only for reverse engineering, but also for building exploits, the researchers said at Black Hat. Watson called DTrace a friendly programming rootkit that lets you see everything within the operating environment.

One of the key functions of DTrace is its ability to allow automating tasks that would otherwise be manually intensive, Beauchamp said. “If you're sending input to an application to trigger a vulnerability, you can have DTrace alert you when input has reached a vulnerable function. It basically takes a large amount of time off inspecting a vulnerability because it can be programmatically controlled.”

DTrace is a great platform as is, Weston added. “But we were interested primarily in a reverse-engineering tool, and DTrace is missing the ability to set conditions that would allow reverse-engineering an application to discover vulnerabilities."

While DTrace is not destructive by itself, combined with other utilities it can cause damage. For instance, it can be manipulated to perform "snooping" operations, such as stealing a user's keystrokes without their knowledge, exactly like a keystroke logger, the researchers said at Black Hat.

Beauchamp and Weston said they have developed a DTrace-based toolkit called RE:Trace. Working with Sun's Chris Andrews, they created a library of routines in a language called Ruby, they told SCMagazineUS.com. With Ruby, they were able to give DTrace a number of capabilities it lacked, including object-oriented programming and expressionals.

Beauchamp and Weston called RE:Trace a “high-level” application programming interface (API) that includes sample scripts. These help not only debug vulnerabilities within applications, but write exploits for them as well, Beauchamp and Weston said.

[Source: SC Magazine - Actual article link]

Friday, February 29, 2008

Solaris Threading Model

I was looking for a detailed account of Solaris Kernel's architecture, specifically the threading model, and I found this book Solaris Internals. The one I have talks about Solaris 7's architecture. Now I believe that minute architectural details change frequently in Solaris because of the aggressive involvement of the OpenSolaris community. So, I might not be up to date with whatsoever I will discuss about here.

The basic execution unit in Solaris is a Process. Each process has its own Virtual Memory/Machine Environment. Now this environment is nothing more than a name given collectively to objects associated with a process, e.g. the address space, global variables, open files, accounting information etc. Such an environment isolates the process from other processes in the system which are apparently running concurrently.

By default, each process has atleast one thread of execution which is the default main thread. And, each Solaris process can have multiple threads, where all the threads share the same Virtual Memory environment of that process. The kernel uses time-slicing to allocate the CPU to these process threads, and once a process is taken off a CPU, its complete execution environment consisting of per thread items(program counter, stack, registers etc) are saved so that the thread can be resumed at some later time.

Now, in Solaris, Kernel threads execute on the CPU. Kernel threads are different from the User or Process threads in the sense that there creation and management is a responsibility of the kernel itself, and not some threading api. So now, we have discussed Kernel Threads and the thread contained by a process. Before discussing the threading model, it's better to talk about one more dimension of threads in Solaris. The Solaris kernel is multithreaded - "it is implemented with multiple threads of execution to allow concurrency across multiple processors". Such a kernel allows concurrent access to itself to improve performance on a multiprocessor system.

Wednesday, February 20, 2008

Troubleshooting SXDE installation and initial setup

Where SXDE is Solaris Express Developer Edition. In the following discussion, I am talking about Solaris Express Developer Edition 02/08, while using the word Solaris or OS.

During the last week's few nights, I struggled to pump up my Solaris as a competitve alternative to my existing Windows XP. However, I failed. Unexpectedly, I faced certain problems which I never had with most of the linux distros I ever installed.

First Problem: Solaris can't be installed on Extended Logical Partition.

I am not sure about the current status but, while googling it I found this to be declared as a bug, which was being taken care of back in 2006. I expected it to be resolved by 2008 however, I wasn't able to even look at the free space available within the extended logical partition in the Parition Manager, while installing Solaris.

Solution: Now since Windows XP don't allow you to have more than 3 primary partitions, I had to delete one from my machine. Once I did that, I had 5 gb free, but I required 20GB which is recommended for a smooth Solaris installation. Anyways, I wsa able to MOVE/RESIZE my extended logical parition to the point that the 15GB free space poped out of this extended partition, and I finally had 15+5 GB able to be used as a Primary Partition. That was it, I was done by using those 20GB to create a 'Solaris' Partition.

Second Problem: Wireless Internet connection not working.

I have a Dell Inspiron e1505, with a Dell 1390 Wireless Minicard. I assumed Solaris capable enough to do some sort of driver detection to get that thing running automatically, but it wasn't as simple. For certain reasons, I had to use Solaris NDIS(Network Driver Interface Specification) Wrapper Toolkit. This toolkit somehow makes use of the native binary Windows drivers of wifi cards to be used in Solaris. Also, one sort of limitation was that a 32 bit windows

driver can only be used in 32bit Solaris and not in 64Bit Solaris. Here, I was stucked again. By default, the installed Solaris was 64-bit Edition. And, there were no 64bit drivers for my Wifi card.

So, there was a grub-based workaround that I found in carlton's guide to boot up the 32 bit Solaris. All you have to do is to goto /boot/grub and edit the file menu.lst as follows:

Since I had a previous Windows XP Installation, I was able to find the string "title Windows" in the menu.lst file. Right above it, append (add) the following:

title Solaris Express Developer Edition 02/08 (32 Bits)
kernel$ /platform/i86pc/kernel/unix
module$ /platform/i86pc/boot_archive

Once done, restart the pc, and select this GRUB option from the boot menu to boot the 32 bit version of Solaris. Now you are ready to lookout over the internet for the 32 bit driver for you wifi card. So, find one. I got mine at dell.com. In that driver package, only 2 files were required by NDIS toolkit, which were:

bcm32.inf file (ASCII text file) - It contains information that tells the Windows installer what devices this driver supports and what registry keys should be created to control driver's configuration.

bcm32.sys file (binary file) - This file contains the actual driver executable code in Windows Portable Executable (PE) format.

You also need the NDIS Wrapper Toolkit which can be downloaded from here. Now, I won't rewrite the steps I did as I followed nothing more than what Carlton's little guide talks about. It's comprehensible and straight forward.

But finally, after doing it all, I was again troubled with 3 more problems:

1- I was ONLY able to access the www using IPs and not the domain names, for e.g. I could access Google if I type http://64.233.167.147 at the browser. But,

I couldn't access the same if I type http://www.google.com. I resolved this by making a little change in /etc/nsswitch.conf file. I changed the 'hosts: files' to 'hosts: files dns'(more on this). And that was it.

2- I couldn't sort out to activate the wifi connection automatically on startup. Although I have checked the same option in Networks Panel but, it helping me out.
3- Sometimes, the connection is lost when I play around with and apparently the only solution then turns out to be a system restart.

Wednesday, February 13, 2008

LLVM 2.2

Where LLVM stands for Low Level Virtual Machine.
I found about it while skimming through slashdot.

As of Wikipedia,
"The Low Level Virtual Machine, generally known as LLVM, is a compiler infrastructure, written in C++, which is designed for compile-time, link-time, run-time, and "idle-time" optimization of programs written in arbitrary imperative programming languages. The LLVM project started in 2000 at the University of Illinois at Urbana-Champaign."

As of Slashdot,
".. This is the thirteenth public release of the open-source compiler that started as a GCC fork. LLVM supports several aggressive optimizations, in compile-, link- and run-time, and often produces faster (1.5-3x) code than GCC. It is also much faster than GCC at compiling (despite the slow link-time optimizations). Gentoo users are already trying to build the whole system with the LLVM toolchain to get the extra performance bit."

Few features of LLVM as listed on its homepage are,

  • Front-ends for C and C++ based on the GCC 3.4 and 4.0.1 parsers. They support the ANSI-standard C and C++ languages to the same degree that GCC supports them. Additionally, many GCC extensions are supported. LLVM also includes a front-end for "Stacker", a Forth-like language.
  • A stable implementation of the LLVM instruction set, which serves as both the online and offline code representation, together with assembly (ASCII) and bytecode (binary) readers and writers, and a verifier.
  • A powerful pass-management system that automatically sequences passes (including analysis, transformation, and code-generation passes) based on their dependences, and pipelines them for efficiency.
  • A wide range of global scalar optimizations.
  • A link-time interprocedural optimization framework with a rich set of analyses and transformations, including sophisticated whole-program pointer analysis, call graph construction, and support for profile-guided optimizations.
  • An easily retargettable code generator, which currently supports X86, X86-64, PowerPC, PowerPC-64, ARM, Thumb, SPARC, Alpha, and IA-64.
    A Just-In-Time (JIT) code generation system, which currently supports X86, X86-64, PowerPC and PowerPC-64.
  • Support for generating DWARF debugging information.
  • A C back-end useful for testing and for generating native code on targets other than the ones listed above.
  • A profiling system similar to gprof.
  • A test framework with a number of benchmark codes and applications.
  • APIs and debugging tools to simplify rapid development of LLVM components

Where strengths being,

  • LLVM uses a simple low-level language with strictly defined semantics.
  • It includes front-ends for C, C++, and Stacker (a forth-like language). Front-ends for Java, Scheme, and other languages are in development.
  • It includes an aggressive optimizer, including scalar, interprocedural, profile-driven, and some simple loop optimizations.
  • It supports a life-long compilation model, including link-time, install-time, run-time, and offline optimization.
  • LLVM has full support for accurate garbage collection.
  • The LLVM code generator is relatively easy to retarget, and makes use of a powerful target description language.
  • LLVM has extensive documentation and has hosted many projects of various sorts.
    Many third-party users have claimed that LLVM is easy to work with and develop for. For example, the Stacker front-end was written in
    4 days by someone who started knowing nothing about LLVM. Additionally, LLVM has tools to make development easier.
  • LLVM is under active development and is constantly being extended, enhanced and improved. See the status updates on the left bar to see the rate of development.
  • LLVM is freely available under an OSI-approved "three-clause BSD" license.
  • LLVM is currently used by several commercial entities, who contribute many extensions and new features.

And the intended users include,

  • A compiler researcher interested in compile-time, link-time (interprocedural), and runtime transformations for C and C++ programs.
  • A virtual machine researcher/developer interested in a portable, language-independent instruction set and compilation framework.
  • An architecture researcher interested in compiler/hardware techniques.
  • A security researcher interested in static analysis or instrumentation.
  • An instructor or developer interested in a system for quick prototyping of compiler transformations.
  • An end-user who wants to get better performance out of your code.

[sources: http://developers.slashdot.org/article.pl?no_d2=1&sid=08/02/12/1431222, http://llvm.org/Features.html, Wikipedia]

Tuesday, February 12, 2008

Bill Clinton at George Mason




Bill Clinton at our campus (George Mason University, Fairfax), supporting Hillary's presidential campaign..

Thursday, February 07, 2008

Mac hack contest

One year after Mac hack contest, Linux & Vista may be tested
IDG News Service 2/6/08Robert McMillan, IDG News Service, San Francisco Bureau

One year after launching a controversial Macintosh hacking contest, the promoters of the CanSecWest security research conference are thinking about giving hackers another shot at cracking the Mac. Only this time, they're looking to broaden the field.

Last year, show organizers invited attendees to hack into a Macintosh laptop, with the successful hacker winning the computer and a cash prize. But this year they're talking about giving attendees three targets to choose from. "We're thinking of having a contest where we have Vista and OS X and Linux ... and see which one goes first," said Dragos Ruiu, the principal organizer of CanSecWest.

Last year, security researcher Dino Dai Zovi spent a sleepless night hacking his Mac in order to take the prize at the show's first PWN to OWN contest. Dai Zovi found a QuickTime bug that allowed him to run unauthorized software on the Mac once the computer's browser was directed to a specially crafted Web page.

Dai Zovi split the contest prize with a friend at the show, Shane Macaulay, who helped him pull off his attack. Macaulay got to keep the Macbook Pro while Dai Zovi pocketed the US$10,000 put up by 3Com's Tipping Point division in exchange for technical details on the bug.

It turned out that the QuickTime bug affected the Windows operating system too, but Ruiu said that Dai Zovi's hack helped change the way the industry thinks about the Mac OS, which has a reputation for being far more secure than Windows. "We were trying to point out that there was a security issue with Mac stuff here, and everybody was trying to play ostrich."

Ruiu and Dai Zovi say that last year's contest helped kick off a flurry of Mac-related security research, but according to TippingPoint Manager of Security Response Terri Forslof, it also illustrated a security industry truism: "Given enough time and motivation, everything can be broken," she said. "When TippingPoint agreed to purchase whatever vulnerability was used to win the contest for $10,000, it added an appropriate level of motivation. That's how it works."

Shortly after last year's contest, Gartner published a research paper warning that such challenges are "risky endeavors" that could put sensitive vulnerability information out in the public domain.

That hasn't stopped CanSecWest from pressing forward with this year's event.

Ruiu isn't certain that he'll run the three-way hacking contest this year. That's because he also has a grander, top-secret hacking contest idea that may or may not pan out, he said.

Either way, he promised "an interesting spectacle."

Bob McMillan is Senior writer for the IDG News Service.
[source: http://security.itworld.com/4341/mac-hack-contest-080206/page_1.html]

Saturday, February 02, 2008

OpenSolaris Concern: Virtualization

If we can identify 3 facets of virtualization of an underlying hardware as
- virtualization to Isolate a 'process' from other processes,
- something that can monitor status of and activities within a virtual machine, and
- being a guest or being a host operating system,

then,
- OpenSolaris has Zones and Branded Zones which provide "protected and virtualized OS environment within an instance of Solaris, allowing one or more processes to run in isolation from other activity on the system', and they "enable kernel and user mode development of Solaris and Linux applications without impacting developers in seperate zones".

- OperSolaris also supports Xen, which is "an open-source virtual machine monitor", and

- OpenSolaris is available as a guest operating system for VMWare. (Get Started)

[source: OpenSolaris - Student Guide]

SXDE Installation Guide: Laptop Installations

Where SXDE is Solaris Express Developer Edition.
The Student Guide titled as "Introduction to Operating Systems: A hands-on approach using the OpenSolaris Project" referred to the following link for installation of SXDE on Laptops:
Solaris Express Developer Edition Installation Guide: Laptop Installations

Since I couldn’t love it by just running it within a virtual machine, I am following these guidelines to install it as another operating system on my machine.

Friday, February 01, 2008

Thinking of a switch? think OS.

Where OS is OpenSolaris.
I am taking Advance Operating Systems course in spring08 semester with Dr. Harry Foxwell at George Mason University. Two things convinced me to get into this class: the professor's profile, and an opportunity to get out of closed Windows..

He is kind of an AIO individual, being an ex-soccer referee, a Vietnam veteran, Senior System Engineer at Sun Microsystems, and an adjunct professor here at GMU, which seemed interesting at a glance.

Then, I remember the references made to Solaris' implementation during my Operating Systems class as being competitive with the contemporary systems, if not any better. I also knew Solaris is based on Unix. And literally, this was the only information I had before taking the first class of this course.

I want to track my progress in learning it, and this text serves the purpose of being the appetizer post. As I will try to gradually fill up my stomach with more *nix-based stuff, I'll try to keep this blog in shape perfected with my knowledgebase.

As of now, I have successfully installed Solaris 10 (commercial version) on VMware Server version 1.0.4, which was a piece of cake while partly following HOW TO INSTALL SUN SOLARIS INSIDE VMWARE WORKSTATION 5.5

But, I feel like I am lacking hardware resources on my inspiron e1505 notebook to enjoy its full capacity. Following up, I downloaded 3 DVDS of Solaris Express Developer Edition 09/07 from opensolaris.org, and burned them.

And yes, I was thinking of a switch, and I'll love one such to OS, if it's supporting my coursework!

Saturday, January 26, 2008

Friday, January 25, 2008

Deliver a Presentation like Steve Jobs

The following article is written by Carmine Gallo. He is a business communications coach and Emmy-Award winning former TV journalist, is the author of Fire Them Up! and 10 Simple Secrets of the World's Greatest Business Communicators. He writes his communications column every week.

When Apple (AAPL) CEO Steve Jobs kicked off this year's Macworld Conference & Expo, he once again raised the bar on presentation skills. While most presenters simply convey information, Jobs also inspires. He sells the steak and the sizzle at the same time, as one reader commented a few years ago.

I analyzed his latest presentation and extracted the 10 elements that you can combine to dazzle your own audience. Bear in mind that Jobs has been refining his skills for years. I broke down his 2007 Macworld keynote in a previous column (BusinessWeek.com, 7/6/07) and in a chapter in my latest book. Still, how he actually arrives at what appear to be effortless presentations bears expanding on and explaining again.

1. Set the theme. "There is something in the air today." With those words, Jobs opened Macworld. By doing so, he set the theme for his presentation (BusinessWeek.com, 1/15/08) and hinted at the key product announcement—the ultrathin MacBook Air laptop. Every presentation needs a theme, but you don't have to deliver it at the start. Last year, Jobs delivered the theme about 20 minutes into his presentation: "Today Apple reinvents the phone." Once you identify your theme, make sure you deliver it several times throughout your presentation.

2. Demonstrate enthusiasm. Jobs shows his passion for computer design. During his presentation he used words like "extraordinary," "amazing," and "cool." When demonstrating a new location feature for the iPhone, Jobs said, "It works pretty doggone well." Most speakers have room to add some flair to their presentations. Remember, your audience wants to be wowed, not put to sleep. Next time you're crafting or delivering a presentation, think about injecting your own personality into it. If you think a particular feature of your product is "awesome," say it. Most speakers get into presentation mode and feel as though they have to strip the talk of any fun. If you are not enthusiastic about your own products or services, how do you expect your audience to be?

3. Provide an outline. Jobs outlined the presentation by saying, "There are four things I want to talk about today. So let's get started…" Jobs followed his outline by verbally opening and closing each of the four sections and making clear transitions in between. For example, after revealing several new iPhone features, he said, "The iPhone is not standing still. We keep making it better and better and better. That was the second thing I wanted to talk about today. No. 3 is about iTunes." Make lists and provide your audience with guideposts along the way.

4. Make numbers meaningful. When Jobs announced that Apple had sold 4 million iPhones to date, he didn't simply leave the number out of context. Instead, he put it in perspective by adding, "That's 20,000 iPhones every day, on average." Jobs went on to say, "What does that mean to the overall market?" Jobs detailed the breakdown of the U.S smartphone market and Apple's share of it to demonstrate just how impressive the number actually is. Jobs also pointed out that Apple's market share equals the share of its top three competitors combined. Numbers don't mean much unless they are placed in context. Connect the dots for your listeners.

5. Try for an unforgettable moment. This is the moment in your presentation that everyone will be talking about. Every Steve Jobs presentation builds up to one big scene. In this year's Macworld keynote, it was the announcement of MacBook Air. To demonstrate just how thin it is, Jobs said it would fit in an envelope. Jobs drew cheers by opening a manila interoffice envelope and holding the laptop for everyone to see. What is the one memorable moment of your presentation? Identify it ahead of time and build up to it.

6. Create visual slides. While most speakers fill their slides with data, text, and charts, Jobs does the opposite. There is very little text on a Steve Jobs slide. Most of the slides simply show one image. For example, his phrase "The first thing I want to talk to you about today…" was accompanied by a slide with the numeral 1. That's it. Just the number. When Jobs discussed a specific product like the iPhone, the audience saw a slide with an image of the product. When text was introduced, it was often revealed as short sentences (three or four words) to the right of the image. Sometimes, there were no images at all on the slide but a sentence that Jobs had delivered such as "There is something in the air." There is a trend in public speaking to paint a picture for audiences by creating more visual graphics. Inspiring presenters are short on bullet points and big on graphics.

7. Give 'em a show. A Jobs presentation has ebbs and flows, themes and transitions. Since he's giving his audience a show instead of simply delivering information, Jobs includes video clips, demonstrations, and guests he shares the stage with. In his latest keynote, the audience heard from Jim Gianopulos, CEO and chairman of Fox Filmed Entertainment, and Paul Otellini, CEO of Intel ((INTC). Enhance your presentations by incorporating multimedia, product demonstrations, or giving others the chance to say a few words.

8. Don't sweat the small stuff. Despite your best preparation, something might go wrong as it did during the keynote. Jobs was about to show some photographs from a live Web site, and the screen went black while Jobs waited for the image to appear. It never did. Jobs smiled and said, "Well, I guess Flickr isn't serving up the photos today." He then recapped the new features he had just introduced. That's it. It was no big deal. I have seen presenters get flustered over minor glitches. Don't sweat minor mishaps. Have fun. Few will remember a glitch unless you call attention to it.

9. Sell the benefit. While most presenters promote product features, Jobs sells benefits. When introducing iTunes movie rentals, Jobs said, "We think there is a better way to deliver movie content to our customers." Jobs explained the benefit by saying, "We've never offered a rental model in music because people want to own their music. You listen to your favorite song thousands of times in your life. But most of us watch movies once, maybe a few times. And renting is a great way to do it. It's less expensive, doesn't take up space on our hard drive…" Your listeners are always asking themselves, "What's in it for me?" Answer the question. Don't make them guess. Clearly state the benefit of every service, feature, or product.

10. Rehearse, rehearse, rehearse. Steve Jobs cannot pull off an intricate presentation with video clips, demonstrations, and outside speakers without hours of rehearsal. I have spoken to people within Apple who tell me that Jobs rehearses the entire presentation aloud for many hours. Nothing is taken for granted. You can see he rehearsed the Macworld presentation because his words were often perfectly synchronized with the images and text on the slides. When Jobs was showing examples of the films that are available on the new iTunes movie rental service, one poster of a particular film appeared at the exact moment he began to talk about it. The entire presentation was coordinated. A Steve Jobs presentation looks effortless because it is well-rehearsed.

[source: http://www.businessweek.com/smallbiz/content/jan2008/sb20080125_269732.htm]

Thursday, January 24, 2008

What's missing in C++?

  • No automatic garbage collection (It is possible to use an external GC though, such as the Boehm_garbage_collector)
  • No requirement for bounds checking of arrays (The std::vector class can be used to avoid this problem)
  • No operations on whole arrays (This can be achieved with Template classes).
  • No syntax for ranges, such as the A..B notation used in several languages
  • No nested function definitions
  • No formal closures or functions as parameters (only function and variable pointers). (C++0x will probably feature closures).
  • No native support for multithreading and networking (C++0x will provide thread-local storage and threading classes in the standard library)
  • No standard libraries for several other application programming needs

[source: http://en.wikipedia.org/wiki/Criticism_of_C%2B%2B]

C++0x

C++0x is the planned new standard for the C++ programming language. It is intended to replace the existing C++ standard, ISO/IEC 14882, which was published in 1998 and updated in 2003. These predecessors are informally known as C++98 and C++03. The new standard will include several additions to the core language and will extend the C++ standard library, incorporating most of the C++ Technical Report 1 libraries — most likely with the exception of the library of mathematical special functions.

Programming languages such as C++ use an evolutionary process to develop their definition. This process inevitably raises compatibility issues with existing code, which has happened occasionally during the C++ development process. However, according to the announcement made by Bjarne Stroustrup (inventor of the C++ language and member of the committee), the new standard will be almost 100% compatible with the current standard.

[source: http://en.wikipedia.org/wiki/C%2B%2B0x]

Wednesday, January 23, 2008

Defining C++

I was trying to get to the roots of information pertaining to the evolution of C++ and found an interview link on youtube. It's with Bjarne Stroustrup, founder/inventor of C++, and Herb Sutter, secretary of the ISO/ANSI C++ standards committee.

In it, Stroustrup defined C++ as a language,

  • Which is close to the hardware,
  • Which can deal very effectively with resources, and
  • Which has the abstraction mechanism that can serve the demands of really large applications,

He also somewhat criticized that if there is something good happening about C++, one won't hear a lot about it. This is partly because a number of people working on other languages are paid to disseminate improvement bullets about their languages; on the other hand, there is no substantial marketing budget to popularize or create hype around C++.

The invention of C++

1983: C++

Tired of the lack of expressiveness of mainstream programming languages of the day and of the slowness of experimental languages, AT&T researcher Bjarne Stroustrup built the first version of C++ in 1983. C++ combines the expressive power of OOP (object-oriented programming) with the speed, compactness, and flexibility of C, its systems programming language predecessor, which was invented at AT&T ten years earlier. C++ matches C in efficiency and adds facilities for building larger, more easily maintained, and more reliable systems.

Stroustrup's creation, originally intended to improve the working lives of his colleagues, rapidly became one of the most influential programming languages in industry and academia worldwide. Today, upwards of a million programmers use C++ to write software for machines ranging from PCs to supercomputers. If you have used a computer, you have almost certainly used a program written in C++. Most PC and Internet users do so daily. C++ is even used for software in gadgets such as cameras and elevators, which are not usually associated with computers and programming.

At AT&T, C++ has become embedded in transmission, switching, and operations systems. C++ is also used in scientific programming, data analysis, simulation, and other mainstays of telecommunications research. Constant research and refinement have kept C++ in the front line of systems development to this day.

[source: http://www.corp.att.com/attlabs/reputation/timeline/83cplus.html]

In The Design and Evolution of C++ (1994), Bjarne Stroustrup describes some rules that he uses for the design of C++:
  • C++ is designed to be a statically typed, general-purpose language that is as efficient and portable as C
  • C++ is designed to directly and comprehensively support multiple programming styles (procedural programming, data abstraction, object-oriented programming, and generic programming)
  • C++ is designed to give the programmer choice, even if this makes it possible for the programmer to choose incorrectly
  • C++ is designed to be as compatible with C as possible, therefore providing a smooth transition from C
  • C++ avoids features that are platform specific or not general purpose
  • C++ does not incur overhead for features that are not used (the "zero-overhead principle")
  • C++ is designed to function without a sophisticated programming environment

[source: http://en.wikipedia.org/wiki/C%2B%2B]

Java: Rounding off to 2 decimal places

Seeking the simplest way to round off a float value to 2 decimal places, i found these:

Method 1:
x = (double)int((x+0.005)*100.0)/100.0;

Method 2:
x = Math.round(x*100.0) / 100.0;

Method 3:
DecimalFormat df2 = new DecimalFormat( "#,###,###,##0.00" );
double dd = 100.2397;
double dd2dec = new Double(df2.format(dd)).doubleValue();

Method 4:
f = (float) (Math.round(n*100.0f)/100.0f);

Method 5:
double r = 5.1234;
System.out.println(r); // r is 5.1234
int decimalPlaces = 2;
BigDecimal bd = new BigDecimal(r);
bd = bd.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP); // setScale is immutable
r = bd.doubleValue();
System.out.println(r); // r is 5.12

[source: www.thescripts.com, accuracy unchecked]

How I did it:
float percentage = score.floatValue()/(qapairs.length*10)*100; //my float value
percentage = Float.valueOf((new DecimalFormat("###.00").format(percentage)));

Saturday, January 19, 2008

SPARQL Query Language for RDF

DBpedia is a community effort to extract structured information from Wikipedia and to make this information available on the Web. DBpedia allows you to ask sophisticated queries against Wikipedia and to link other datasets on the Web to Wikipedia data.
[source: www.DBPedia.org]
---------------- ---------------- ----------------
The W3C just gave SPARQL the stamp of approval. SPARQL is a query language for the Semantic Web, and differs from othe query languages in that is usable across different data sources. There are allready 14 implementations of the spec, which is a lot. Most of them are free software. There are also billions of relations out there that are queryable, thanks to the Linking Open Data project. The structured data of Wikipedia are now queryable at DBpedia. Also, have a look at Ivan Herman's presentations.

Lets have an example: You could do this on dbpedia.org (with the standard prefixes you find there) and it will return computer scientists born before 1945: SELECT ?name ?birth ?death ?person WHERE { ?person skos:subject . ?person dbpedia2:birth ?birth . ?person foaf:name ?name . OPTIONAL { ?person dbpedia2:death ?death } FILTER (?birth < "1945-01-01"^^xsd:date) . } ORDER BY ?name
[source: Slashdot]
---------------- ---------------- ----------------
SPARQL Query Language for RDF
ABSTRACT
RDF is a directed, labeled graph data format for representing information in the Web. This specification defines the syntax and semantics of the SPARQL query language for RDF. SPARQL can be used to express queries across diverse data sources, whether the data is stored natively as RDF or viewed as RDF via middleware. SPARQL contains capabilities for querying required and optional graph patterns along with their conjunctions and disjunctions. SPARQL also supports extensible value testing and constraining queries by source RDF graph. The results of SPARQL queries can be results sets or RDF graphs.

Wednesday, January 09, 2008

Different Swap techniques

Using a TEMPORARY variable:

int a = 10, b = 20;
int temp = 0;

temp = a;
a = b;
b = temp;

Without using a temporary variable:

int a = 10, b = 20;

a = a + b; // ( a = 30 )
b = a - b; // ( b = 10 )
a = a - b; // ( a = 20 )

In one line:

int a = 10, b = 20;

a = a + b - ( b = a );

Sunday, January 06, 2008

Sum of square of each digit of an integer

My first try that worked:


int S(int x){
   int sum=0, y=0;
   while (x!=0){
      if (x < 10) {
       y = x;
      } else {
       y = x % 10;
      }
      x = (x - y) / 10;
      sum += y * y;
   }
   return sum;
}


Returns:
DigitsSum(55)=50 [5*5 + 5*5]
DigitsSum(230)=13 [2*2 + 3*3 + 0*0]
DigitsSum(37)=58 [3*3 + 7*7]


U P D A T E

A better solution:
int ur_num;
int sum_of_sq=0;
while(ur_num!=0){
remainder=ur_num%10;
sum_of_sq += remainder*remainder;
ur_num = ur_num/10;}