2,322 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for iamthwee
Member Avatar for William Hemsworth
0
954
Member Avatar for Dave Sinkula
Member Avatar for bemboysms
0
249
Member Avatar for nanodano

This code snippet actually contains a few nifty things. There are two functions, hasVisited() and main(). hasVisited() makes use of a very handy function for CGI programmers: getenv. You can see I use it to retrieve REMOTE_ADDR which is the person's IP address. In main() it gets the count from …

Member Avatar for manutd
0
262
Member Avatar for vegaseat

This little snippet combines a Tkinter GUI application with sound from the pygame mixer. The snippet should do fairly well across platforms. I tested it on a Windows XP machine, but let me know your experience with other platforms.

0
453
Member Avatar for nihilks

The program uses doubly linked lists to store the numbers where each node contains a single digit . Hence numbers of any length can be used as operands . Program works only with +ve integers

0
142
Member Avatar for IP2Location

This is ASP script to enable lookup country, region, city, latitude, longitude, ZIPcode, Timezone and netspeedomain and netspeed from IP address by using IP2Location database. Free sample database available at [URL]http://www.ip2location.com[/URL]. The script supports several database types such as Microsoft Access, MS SQL and mySQL. Internet geolocation has been widely …

0
419
Member Avatar for MattEvans

You want your object to do a number of different things when it's clicked, and you've used up onmouseup, onmousedown and onclick. There are some properietry solutions to this, but it's quite a simple thing really. Copy and paste the MultiHandle object into an empty js file, include it in …

Member Avatar for MattEvans
0
160
Member Avatar for MattEvans

Ever wanted to evaluate a user-provided expression, maybe from a form input or otherwise, and return the result? eval($expr) is dangerous because eval(open $out, "> file.what"); will open the file, infact, eval(everything) will pretty much do everything. checking though everything is tedious, and manually parsing everything seems like a waste …

Member Avatar for KevinADC
0
392
Member Avatar for teddy13
Member Avatar for kalyanraj
Member Avatar for venomlash

This can be used for plotting radioactive decay of an unlimited* number of elements, decaying into each other. *Limited only by memory and user attention span.

0
179
Member Avatar for Mouche

This game takes a random word from a list, gives you five prompts to guess letters in the word, and then it shows you a "masked word," filling in the letters you've guessed. Say the word is "hockey" and the user guesses: 'h,' 'e,' 't,' 'r,' and 's.'The masked word …

0
280
Member Avatar for vegaseat

This shows you how to draw a colorful bar graph of a data set using the Tkinter canvas and rectangles. An attempt has been made to use most of the canvas area for the graph. The bars are spaced and labeled with the corresponding value. The x-axis is simply the …

2
4K
Member Avatar for roverphoenix

the code now contains snippet to create the linked list too! any questions can be directed to [U]raghu_tillu@hotmail.com[/U]

Member Avatar for virusfree
0
152
Member Avatar for Ene Uran

The snippet shows the use of a list of class instances to form a sortable and searchable database for solvents, or for that matter other chemicals. The list can be expanded and all the needed data added at the same time.

0
269
Member Avatar for diafol

A simple example of date (day and month) translation. The code is for Welsh, but can be easily modified for any language - especially those without "full" support. I have used the code in a footer to display the last updated date and time. //EDIT - a few years later …

Member Avatar for 42south
0
254
Member Avatar for vegaseat

You can use the Tkinter canvas and the canvas.create_line() function to draw a line plot of a mathematical function. The canvas.create_line() function accepts a list of x, y points that you can create within a for loop. The resulting plot is centered and can be stretched along the x and …

0
2K
Member Avatar for bumsfeld

The wxPython GUI tool makes it very simple to create nice looking analog clock. The analog clock component was put into simple dialog frame and can be moved about the screen.

0
729
Member Avatar for vegaseat

Another famous fractal called the Sierpinski Triangle named after Polish mathematician Waclaw Sierpinski. He seemed to have played around with it the most. To state it simple, you start with an equilateral triangle and then form smaller triangles by connecting the midpoints of each of the sides. Some folks shade …

1
1K
Member Avatar for venomlash

For those of you who live at home, run this on your parents' computer fullscreen, blue background, white font. Then put the mouse over the block in the upper lefthand corner, and enjoy the show.:twisted:

Member Avatar for lol_hacker101
0
134
Member Avatar for venomlash

This code will let you play Battleship against the computer (bad graphics, I know) for a while, upon which it quits without so much as an error message. Could an experienced coder look this over and tell me why? Thanks. Venomlash :?:

0
125
Member Avatar for ~s.o.s~

Hello to everyone out there. Recently many people on different forums have been asking how to make a recursive function which reverses the string passed to it. But unlike the normal recrusive funtion which only prints out the reversed string, this implementation returns a pointer to reversed string.

Member Avatar for roverphoenix
0
172
Member Avatar for Lord Soth

Based on [url]http://astronomy.swin.edu.au/~pbourke/geometry/insidepoly/[/url] Converted to Delphi by Lord Soth

Member Avatar for Zajoma
0
768
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.

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 …

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

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 …

0
253
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 …

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 …

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

1
209
Member Avatar for vegaseat
Member Avatar for RonaldDuncan
0
2K
Member Avatar for amatallah
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 …

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.

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.

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 …

Member Avatar for roverphoenix
0
378
Member Avatar for KevinADC
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]

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.

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]

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 …

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 …

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]

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.

0
884
Member Avatar for Maggot
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 …

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.

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.

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.

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

0
715

The End.