2,322 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for ddanbe

While strolling around in the methods of the Graphics class, I bounced on the CopyFromScreen method. He, so why not make a screen capture utility! I know there is lots of this stuff out there. But it just seems like fun to try to make one myself. I made a …

Member Avatar for ddanbe
0
3K
Member Avatar for ddanbe

Blink and you will see them appear in a Console window. This is a translation to C# of a Modula-2 implementation by N.Wirth, the inventor of Pascal. The tested integers are obtained by incrementing alternatively by 2 and 4, thereby avoiding multiples of 2 and 3 in the first place. …

Member Avatar for ddanbe
0
97
Member Avatar for VernonDozier

I received some feedback on my [URL="http://www.daniweb.com/code/snippet1019.html"]earlier code snippet[/URL] regarding how to generate unique random numbers and someone suggested I make a shorter, easier example, so here it is. This example simply generates the integers from 0 to 9 in random order without any repeats. It is basically the function …

0
749
Member Avatar for Gribouillis

Many threads in daniweb's python forum deal with menu based programs which run in a terminal. This snippet defines a handy class, MenuCrawler, to help writing such programs. Subclassing from this base classes and adding methods corresponding to a given set of menus allows one to build the menu-based application. …

0
3K
Member Avatar for vckicks

A slightly modified version of Bucket Sort that uses LinkedLists and initializes buckets only when required. Results in massive speed improvements.

0
265
Member Avatar for ddanbe

Although there is little need for any sort algorithm in C#. Every collection class has a sort method, so why would you wanna write one for yourself? My guess to learn and see how it is done. Well her are implementations of two popular sorts. The arrays are integer but …

Member Avatar for subtercosm
0
837
Member Avatar for MosaicFuneral

After flipping through some organic chemistry books I had, I found a interesting little table of basic hydrocarbons. I decided it would be nice to play around with it, by putting together something that could to some accuracy generate them. I am by no means a chemist. You don't even …

0
142
Member Avatar for MosaicFuneral

I decided to find a use for the STL map, and this is what I decided would be cool to practice with. Just have three placed in the code. Could use a function to load the requested elements from a file.

Member Avatar for ddanbe
0
253
Member Avatar for serkan sendur

to demonstrate some usage of bitwise shift and xor operators, i created a conversion function using these two.

0
148
Member Avatar for ddanbe

You can make any color you like by setting the r, g and b values of a Color structure. But .NET has a set of predefined colors that you can use by name, so that you can simply set the backgroundcolor of a form with Color.LawnGreen for instance. Ever wondered …

0
776
Member Avatar for serkan sendur

This pure javascript code simulates how multiplication is done by mips processors.

0
158
Member Avatar for VernonDozier

Very often you find that you need to generate an array of integers where each integer is unique. The program below contains two functions that do that in different ways. One uses a boolean array to keep track of the numbers that have been generated. If a number has already …

Member Avatar for VernonDozier
0
508
Member Avatar for vckicks
Member Avatar for subtercosm
0
2K
Member Avatar for vckicks
Member Avatar for MosaicFuneral
0
2K
Member Avatar for ddanbe

Visual Studio is a great tool to use. But for beginners like me a few years back, it was a bit overwhelming and confusing. You got the feeling you lost all the control. VS has it’s special ways of doing things with partial classes and so on. So lets get …

0
150
Member Avatar for MosaicFuneral

From part of a cryptanalysis tool I was writing, the other day. A way of obtaining possible XOR'ed string values. If you ever get to the point in the analysis that you can simply XOR the string to get closer towards your goal, of finding a weakness, this might be …

Member Avatar for MosaicFuneral
0
379
Member Avatar for ddanbe

Way back years ago I tried to understand [B]delegates[/B]. See the snippet how I did it.

Member Avatar for ddanbe
0
393
Member Avatar for gbertoli3

Set the Image's Gamma, Brightness, Contrast, Color; Enhance an Image's Edge; Turn it to a Grayscale Image; and Invert the Image.

0
173
Member Avatar for ddanbe

Encryption has many issues. It can be very simple or very complex. I personally don’t have that many secrets, but when the company I worked for wanted to encrypt something I used the following : XOR ! What is nice about xor is that you can use the same method …

Member Avatar for Ramy Mahrous
0
596
Member Avatar for MosaicFuneral

Occasionally there's times when you want to shift a bit over, but you would like to preserve the end of it, for one reason or another. Such as with say you have: [icode]10000001[/icode] but you would like: [icode]00000011[/icode] then latter on back to: [icode]10000001[/icode] Or in Dec 129-into-3, and 3-into-129. …

0
1K
Member Avatar for ddanbe

Class to convert between Celcius, Fahrenheit and Kelvin temperatures. Set one temperature and automatically get the other two. This class makes use of properties. See the code snippet for details. A short main program is added to exercise the Temperature class by printing a conversion table between celsius and fahrenheit.

Member Avatar for ddanbe
0
2K
Member Avatar for ddanbe

This is the last part. This is the code that sets it al together and lets the parser and scanner do some work. Happy calculating!

0
1K
Member Avatar for ddanbe

Here is the second piece of code. The parser tries to interpret the tokens it gets from the scanner.

0
1K
Member Avatar for serkan sendur
0
149
Member Avatar for reena12

''' <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 Return dt2 ElseIf dt1 …

Member Avatar for roby22
0
266
Member Avatar for ddanbe

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 …

1
480
Member Avatar for banders7

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.

0
222
Member Avatar for ajay.krish123

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..

Member Avatar for banders7
0
217
Member Avatar for banders7

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

0
494
Member Avatar for banders7

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.

Member Avatar for banders7
0
442
Member Avatar for Alex Edwards

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 …

Member Avatar for MosaicFuneral
0
898
Member Avatar for banders7

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 gathered, the caller's selection parameters are …

Member Avatar for banders7
0
183
Member Avatar for ddanbe

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.

0
220
Member Avatar for ddanbe

[TEX]Solve an equation of the form Ax^2 + Bx + C = 0.[/TEX] 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 : [CODE]QuadraticEquation z = new QuadraticEquation(1, 3, 3); z.Solve(); …

0
781
Member Avatar for ddanbe

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 …

Member Avatar for ddanbe
1
529
Member Avatar for ddanbe

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.

0
410
Member Avatar for ddanbe

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 …

0
344
Member Avatar for Gribouillis

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.

0
749
Member Avatar for ShawnCplus

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.

Member Avatar for ShawnCplus
0
228
Member Avatar for Alex Edwards

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 overhead could …

Member Avatar for Alex Edwards
0
197
Member Avatar for Gribouillis

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

Member Avatar for Gribouillis
1
813
Member Avatar for gbertoli3
0
996
Member Avatar for gbertoli3
Member Avatar for gbertoli3
Member Avatar for vckicks
Member Avatar for vckicks
0
327
Member Avatar for William Hemsworth

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 [B].bmp[/B] once its made. You can be creative like this and make images which would be …

Member Avatar for Prabakar
0
1K
Member Avatar for ShawnCplus

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

0
80
Member Avatar for toraj58

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

0
149
Member Avatar for Alex Edwards

Simple program that returns a vector of string elements based on the string argument and the token specified.

Member Avatar for Alex Edwards
0
183

The End.