1,916 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for ~s.o.s~

The program parses the digits in the number supplied to it and converts it to aplhabetical equivalent. Fore eg. input: 1234 output: one two three four This is a simple exercise for newbies, must try out. Tested and works under ideal input conditions.

Software Development c
Member Avatar for ~s.o.s~
0
185
Member Avatar for KevinADC

Given the date in mm-dd-yyyy (or M-D-YYYY) format (or any combination of that format) you can find out what day of the week that was on or is on or will be on, within the limitations of the system the script resides on. This snippet uses only core functions and …

Software Development perl
1
1K
Member Avatar for Ene Uran

Just a short little C program to send beeps to the PC internal speaker. Beep(frequency_hrz, duration_ms) is a WinAPI function as is Sleep(ms).

Software Development c
Member Avatar for Ene Uran
1
329
Member Avatar for Ene Uran

A list of tuples is easy to sort for items in the tuples. This snippet shows you how to sort a (character, frequency) tuple either by character or by frequency. One useful example would be the sorting and display of a list of (player, score) tuples, you might find in …

Software Development python
0
254
Member Avatar for Mushy-pea

This is my first working perl script that does anything useful; that being to count the hits made on a web page and display the count graphically. To make the counter work on your web page (should you wish to), you will need to create images for the number tiles …

Software Development perl
Member Avatar for Mushy-pea
0
197
Member Avatar for vegaseat

This is a short code example using the function os.stat() to get some of the basic file information. Things like file size, times the file was created (Windows), last modified, and last accessed. The program uses a dictionary in an interesting way to store and display the information. The times …

Software Development file-system python
0
2K
Member Avatar for vegaseat

There are situations in Python code when a function is used as an object rather then a function call. Handling arguments becomes a mild problem, that can easily be handled by wrapping the function object and its arguments. One common way is the use of a curry function or class. …

Software Development gui python tkinter
1
209
Member Avatar for vegaseat

This Python code shows a way to retrieve a picture from a web page and save it to a file.

Software Development python
Member Avatar for RonaldDuncan
0
2K
Member Avatar for amatallah
Member Avatar for manutd
0
142
Member Avatar for andor

This algorithm proved to be effective when two images are combined. The picture beneath (background) is seen if alpha component of fronth picture is less then 0xFF. If alpha of front picture (src in snippet) is zero then all we see is background picture. The format of colour is ARGB …

Software Development algorithm c
Member Avatar for Jason Zhang
0
1K
Member Avatar for kylethedarkn

Java Code that creates a random number between 1 and 100 and then asks the user to guess the number and tells if the guess was too high, too low or, the right number. Loops until right number is guessed.

Software Development java
Member Avatar for StonedNpwnd
0
342
Member Avatar for vegaseat

Some computer languages have a goto statement to break out of deeply nested loops. Python has chosen not to implement the much abused goto. There are other, really more elegant, ways to accomplish the same outcome. Here are three examples.

Software Development python
Member Avatar for jrcagle
1
3K
Member Avatar for roverphoenix

A simple program to calculate combinations of a string using recursion, I have used a malloc string of size 100 , you can change it to whatever value you want. The author is currently working at Microsoft. for eg if input string is abcd and you want all 3 letter …

Software Development c
Member Avatar for roverphoenix
0
378
Member Avatar for KevinADC

Convert 1000000 into 1,000,000 using a perl regexp.

Software Development perl
Member Avatar for KevinADC
0
259
Member Avatar for Dani

[LEFT]This is a program I wrote for my x86 assembly class which revolves a "roulette wheel" around. Wait about a minute and it will eventually slow down to a stop. It uses Irvine32.inc which came with the textbook.[/LEFT]

Software Development assembly
Member Avatar for holmes008
0
357
Member Avatar for Dani

This is a program I wrote for my x86 assembly class which bounces an ASCII ball across the screen. It uses Irvine32.inc which came with the textbook.

Software Development assembly
0
2K
Member Avatar for KevinADC

Use the List::Util module. I believe List::Util is a core module starting with perl 5.8. For older versions of perl you may need to install the module. See the module documentation for more details: [URL="http://perldoc.perl.org/List/Util.html"]List::Util[/URL]

Software Development perl
0
167
Member Avatar for KevinADC

I've seen this question (or similar) asked many times on forums: I have a variable in a file (text) and want to expand it. For example, I have this line in a text file: Mary had a little $lamb and I want to be able to expand $lamb but text …

Software Development perl
0
278
Member Avatar for KevinADC

"How can I find all the permutations of a list (or a word)"? I have seen this question asked a number of times on forums. There is a module that makes this task very easy: List::Permutor. It is not a core module so you may need to install it. See …

Software Development perl
0
174
Member Avatar for KevinADC

You will need to install the Email::Valid module if it's not already installed. See the module documentation for further details. [URL="http://search.cpan.org/~rjbs/Email-Valid-0.176/lib/Email/Valid.pm"]Email::Valid[/URL]

Software Development email perl
0
294
Member Avatar for KevinADC

The [URL="http://perldoc.perl.org/File/Basename.html"]File::Basename[/URL] module is used to parse file paths into directory, filename and suffix (or file extension). My simple example shows how to get just the file extensions.

Software Development file-system perl
0
884
Member Avatar for Maggot

a simple program to test the JDBC drivers.

Software Development java
0
243
Member Avatar for Dave Sinkula

This snippet is an example of using XOR encryption to encrypt/decrypt a file. It uses command-line input parameters as follows:[indent]argv[1] - name of input file to encrypt/decrypt argv[2] - name of output file argv[3] - crypt key[/indent]For example, an input file called "main.c" is used to create an output file …

Software Development c encryption
Member Avatar for vonqi
0
338
Member Avatar for bumsfeld

Here we search a Python script file (or other text file) for one certain string, and copy any files containing this string to another folder.

Software Development python
0
213
Member Avatar for bumsfeld

Search for a file given its name and the starting search directory. The search is limited to a set depth of subdirectories. Python makes this easy to do.

Software Development python
0
224
Member Avatar for bumsfeld

This Python code will search for given filename starting with given directory. It will also search all the subdirectories in the given directory. The search will end at the first hit.

Software Development python
0
153
Member Avatar for bumsfeld

Code snippet to show you how to verify exit events from wxPython using dialog window. One event is from menu exit and the other from frame exit (x symbol in corner).

Software Development python
0
715
Member Avatar for bumsfeld

This short code shows how to indicate the mouse-over event on wxPython button, similar to the mouse-over in web pages. Button changes colour when mouse pointer is over its area.

Software Development python
0
2K
Member Avatar for Dave Sinkula

In [url=http://www.daniweb.com/code/snippet259.html]Part 1[/url], the code reversed the string in place. This version uses a source and a destination string.

Software Development c
0
138
Member Avatar for bumsfeld

The myth is around that while loop is faster than the corresponding for loop. I checked it out with Python module timeit, and came to surprising conclusion. This snippet can easily be modified to time any of your functions you write.

Software Development python
Member Avatar for Begjinner
0
2K
Member Avatar for vegaseat

Yet Another Calculator using wxPython, smaller, but more advanced than the previous one. Wrote this one to test the Curry class, but it didn't work well. So there is no curry there. I found out that one has to be careful with the eval() function. If you write 012 instead …

Software Development python
1
155
Member Avatar for hemanthjava

JAVA Date Utility ( This program Demonstrates the proper use of Date functionality in common java programming scenarios ) Date and Time

Software Development java
Member Avatar for msg2ajay
0
206
Member Avatar for Rajnesh

/*This program works just like MS-DOS. It takes in the input, uses the C Library, uses the system files and function, executing and displaying the code on the same command prompt. */

Software Development c
Member Avatar for Ancient Dragon
0
1K
Member Avatar for vegaseat

Let mathematics do your art work! It is amazing how a simple mathematical formula can draw very intricate shapes. Here we draw a fractal tree on a Python Image Library (PIL) blank image, and save the finished drawing as an image file in one of the popular formats. Look at …

Software Development mathematics python
0
694
Member Avatar for vegaseat

The wx.BitmapButton shows an image, great for those folks who think that a picture is worth a thousand words. The snippet gives an example how to load the image, size the button, and put the image on the the button.

Software Development python
Member Avatar for InfoClock
0
827
Member Avatar for bumsfeld

The program takes text and establishes dictionary of character:frequency. This dictionary is then presented sorted by character. Since it is important to show the most frequent characters, two methods are given to present dictionary sorted by frequency. Should all be very good for learning Python.

Software Development python
0
627
Member Avatar for nanodano

This snippet shows how to use command line arguments as variables in your program. A command line argument is extra information you give a program at runtime, by typing the information after the program name like so: Linux might look like this: user$: ./myprogram argument1 argument2 A windows command prompt …

Software Development c
0
186
Member Avatar for vegaseat

Just a small Python program to calculate monthly payments and other costs. I have compared it with some of the calculators available from many of the online mortgage companies, and results seem to match.

Software Development python
2
1K
Member Avatar for Jaks_maths

Used recursion to reverse the string. Another method for string reversal.

Software Development c
Member Avatar for ~s.o.s~
0
153
Member Avatar for vegaseat

In this snippet we are playing around with wxPython's buttons, showing you how to bind the mouse click event, enable and disable, show and hide the buttons. Each button also has a tool-tip (hint) associated with itself.

Software Development python
Member Avatar for Racoon200
0
4K
Member Avatar for vegaseat

If you want a variable in a C function to retain its last assigned value, you simply declare it as static. Python does not have static variables, but you can impersonate one in different ways. The default list argument is my preferred option. Here are some examples.

Software Development python
0
601
Member Avatar for Jaks_maths

Returns the duplicate value in array t[n], which contains numbers 1 to n-1. Given two approaches with O(n) and O(n-square) complexities.

Software Development c
Member Avatar for yogeshwar
0
129
Member Avatar for vegaseat

Py2Exe takes your Python code file and packages it into an executable file that you can distribute to a client that does not have Python installed. The executable file contains your byte code, all the required modules and the Python interpreter. It is not a small file. The snippet is …

Software Development python
Member Avatar for Aestter
1
375
Member Avatar for Jaks_maths

Return Nth the node from the end of the linked list. Time Complexity is O(n).

Software Development c linked-list
0
120
Member Avatar for Jaks_maths
0
218
Member Avatar for bumsfeld

Do you think that people act demented during full moon nights? This small python program will tell you moon phase of a date you give it, so you can take precautions!

Software Development python
0
4K
Member Avatar for dubeyprateek

[B][COLOR="Red"]Introduction[/COLOR][/B] There are many times when we try to create a binary search tree of many different data types. This article explains creation of a template library CTree. template <class T>class CTree can be used to create a binary search tree (BST) of any data type. [B][COLOR="red"]Features[/COLOR][/B] This class support …

Software Development c
0
164
Member Avatar for vegaseat

This small snippet shows how to load and display HTML (Hyper Text Markup Language) with wxPython's HtmlWindow(). This could be particularly useful with instruction and help text. HTML allows you to include pictures, fancy fonts and links.

Software Development display html-css python
0
1K
Member Avatar for vegaseat

When I first met folks in Las Vegas that used biorhythm values of the top players in a team to place their bet, I thought they were a little odd. Some of them were successful, but I am sure biorhythms were not the only thing they considered. You can read …

Software Development python
0
3K
Member Avatar for Narue

FASM can output an executable PE directly, but sometimes you want to output an object file for linking with modules in other languages. The following program can be used to link with the C library of the GCC compiler with the following commands: C:\>fasm hello.asm hello.obj C:\>gcc hello.obj -o hello.exe …

Software Development assembly
0
280

The End.