Code Snippet Index

Layout Sample #1

You are free to use and modify my layout in any purpose, and I hope you find this useful! Enjoy... (Read More)

Decimal to Binary Converter

As usual i searched google to convert Decimal numbers to their Binary equivalents but i couldnt find any short algorithm for that matter. So here is mine.. (Read More)

Calculate Sum of Two Time values

''' <summary> ''' FUNCTION TO CALCULATE SUM OF TWO TIME VALUES ''' PASS TWO DATE VALUES AS STRING ''' </summary> Function GetTimeSum(ByVal dt1 As String, ByVal dt2 As String) As String Dim ReturnStr As String = "" If dt1 = "" And dt2 <> "" Then ... (Read More)
C++

Simple Equation Solver ( in C++ )

This is a remake of the Simple Equation Solver snippet that is written in Java. This is an equivalent version written in C++. (Read More)

Rational Number Class

Provides a means of performing operations on Rational numbers that can be treated as fractions to make non-whole numbers easier to calculate and read than typical floating point storage types. This was a project for a class. This is by no means an attempt to "reinvent the wheel" (The reason I... (Read More)

Extract logical drives in system and select desired subset from them

Programming Environment: Windows XP Compilers: Borland C++ Builder 6 (Personal)/Borland C++ 5.5 (freebie) This is a routine that queries the logical drives in the system, along with their device types, local/network status and whether or not the devices are removable. Once the data are... (Read More)

The Ideal GasPump!

Hmm this implementation is a bit bulky and unnecessary, but it was required as a project for one of my classes. Programming perspective: You'll notice in the code that I'm still fairly new to manipulating streams directly in C++, but I am trying my best =P. The StandardIncremental... (Read More)

Programming Images

Heres a snippet that allows you to make your own images by using a mathematical formula. It gives you fast access to each pixel in the bitmap, and then saves the image as a .bmp once its made. You can be creative like this and make images which would be impossible to make using applications such as... (Read More)

String Tokenizer

Simple program that returns a vector of string elements based on the string argument and the token specified. (Read More)
C#

Descriptive statistics

A bunch of basic statistical functions. I could have made a class here and I could have used more features of C#. But just to keep it simple I left it as a console application. So the modifications you have to make if you're into C, C++, Java etc. should be minor. (Read More)

Get info from files in a directory in C#

If you ever want to get information about files stored in a particular map or directory, you can find out how it is done here. With a little modification you could turn this snippet into a DOS DIR-command or a UNIX(LINUX?) ls-command. (Read More)

Find IP address

A little console application in C# to show you the IP address of your computer or the IP address of any website you like. (Read More)

A C# class to solve a quadratic equation

Solve an equation of the form Ax^2 + Bx + C = 0. The class is commented, but if you have any questions don't be affraid to ask. You may exercise this class in a console application with the following snippet : QuadraticEquation z = new QuadraticEquation(1, 3, 3); z.Solve(); ... (Read More)
1

Sorting with a stopwatch.

OK Quicksort IS fast. But what if you just wanna sort 30 items? Then Quicksort becomes a bit of overkill. So what most people then use is the one and only popular "bubblesort", also called "standard exchange sort". Let me present you here with my implementation of another sort(among many others)... (Read More)

Two ways to implement the GCD

Most of the time there are many ways to implement an algorithm. Here are two ways to implement the greatest common divisor algoritm, one of the oldest algorithms ever. (Read More)

Get environmental!

You can get your hands on to usefull information from within your C# program. Use the static System.Environment class! Take a look at this snippet, which can be used as is in a Console application. I have not exhausted all the possibilities, if you want you can look them up in the documentation. (Read More)

Angle conversions

If you have to convert an angle from degrees to radians and way back, here are some utility functions in C#, along with a program to test them. I made use of the "out" keyword here, which allows a function to return more than one value. An alternative would be to return a struct containing all the... (Read More)

Determine your zodiac sign

Fill in your birthday in the DateTime structure and get your sign as a string. Get an extra (an element associated whith the sign) via the out parameter thanks to C#! This switch statement uses returns all over the place, so a break staement is not needed. (Read More)

Determine easter for a given year

Ever wondered how to calculate the date of easter? Well here is how to do it in C# (Read More)

Get a List of Installed Drivers

Get the Driver's Name, Path, Description, Status, and Start Mode (Read More)

Convert an Image to Grayscale

Change a Color Image into a Grayscale(Black & White) Image. (Read More)

Stop a Group of Processes

Stop a Group of Processes (Read More)

Start a Group of Processes

Start a Group of Processes (Read More)

Play Any Sound File

Play any Sound File. Just add a reference to Microsoft.DirectX.AudioVideoPlayback(COM) (Read More)

Slope Formula

Calculate the slope between two points. (Read More)

Distance Formula

Calculate the distance between two points. (Read More)

Reflect on Life; Reflect on C#

Sometimes it is good to sit back and reflect on life. More specifically, you can sit back and reflect on yourself. Often you will discover information that you didn’t realize about yourself. it is possible to have a C# program reflect upon itself. You can use such reflection to learn about an... (Read More)
1

Simple Equation Solver

Solves simple string-based expressions. Currently only supports integers, but can easily be expanded to support float-types. (Read More)

Capture and save an image of the screen

The code below captures the screen and saves it. Depending on your need, you can modify it to do just what you want import java.awt.AWTException; import java.awt.Robot; import java.awt.Rectangle; import java.awt.Toolkit; import java.awt.image.BufferedImage; import java.io.*; import... (Read More)
C

Spawn a program/console command and retrieve its stdout/stderr output

This a routine that executes a _popen() pipe on your behalf and retrieves the spawned program's/comand's console output for you. Useful if your program needs data from another program and can't communicate directly with it. (Read More)

A calculator in C

Program is of the calculator which the usual thing for the operation. It has been totally implemented in the C language with the graphics and mouse functions included in it. Its not scientific but just a usual one.. (Read More)

Determining if stdin data exists for your program BEFORE issuing fgetc() or similar command

A program that handles either piped input (command/prog | your_prog) or file redirected (your_prog < file_name) input. Determine whether such input exists before issuing a stdin read so that the program does not go into a "waiting for input" state. Written in/for the XP environment. (Read More)

Reading data from the Windows registry

A program that demonstrates opening Windows registry keys, reading data fields and closing the keys. (Read More)

Transfer data to/from the Windows clipboard

Two very short routines. CLIPPUT transfers data to the clipboard and CLIPGET retrieves data from the clipboard. Developed and tested in Windows XP using a Borland C++ compiler. (Read More)

The Greatest Common divisor

The greatest common divisor of integers x and y is the largest integer that evenly divides both x and y. Write a recursive method Gcd that returns the greatest common divisor of x and y. The Gcd of x and y is defined recursively as follows: If y is equal to 0, then Gcd( x, y ) is x; otherwise, Gcd(... (Read More)
1

Piecewise linear continuous functions.

Joining together ordered sample points (xi, yi) when ths xi's are different yields a piecewise linear continuous (P1) function. This snippet defines a handy class to manipulate these functions. It allows computing the value and the slope of the function at each point, arithmetic operations,... (Read More)

Grouping strings by prefixes

This snippet defines a class which can group a collection of strings according to a given set of prefixes. Each string goes in the group of the longest prefix it contains. (Read More)

Mendeleiev's periodic table in python

This snippet allows your code to use the Mendeleiev's periodic table of elements. It defines a single function mendeleiev_table() which returns the table as a python list of lists. (Read More)

Show/Compare Line Number Ranges

I ran across the need to view a specific line of a file so I wrote this up. You can view a line or a range of lines for a file or compare two files. Check the command for the syntax. Drop it in /usr/bin/sln and enjoy. (Read More)
PHP

Backtracing Function Calls

So you've got this big long function chain and PHP's oh-so-helpful Fatal Error messages aren't helping at all. Here's a quick example of how to do a function backtrace without throwing exceptions. Output: => => Array ( => someFile.php => 4 ) => Hello World (Read More)


About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC