1,916 Reusable Code Snippet Topics
Remove Filter ![]() | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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. … | |
This Python code shows a way to retrieve a picture from a web page and save it to a file. Software Development python | |
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 … | |
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 | |
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 | |
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 | |
Convert 1000000 into 1,000,000 using a perl regexp. Software Development perl | |
[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 | |
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 | |
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 | |
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 | |
"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 | |
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] | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
JAVA Date Utility ( This program Demonstrates the proper use of Date functionality in common java programming scenarios ) Date and Time Software Development java | |
/*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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
Used recursion to reverse the string. Another method for string reversal. Software Development c | |
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 | |
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 | |
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 | |
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 | |
Return Nth the node from the end of the linked list. Time Complexity is O(n). Software Development c linked-list | |
One line stament which acts as a conditional operator ?: If x=true, returns y else returns z. Software Development c | |
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 | |
[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 | |
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. | |
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 | |
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 |
The End.