2,322 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for maddog39

This class will allow you to take an RSS feed (local or remote) and "export" it to an easily managed/viewed array. Below is an example of it usage: [code=php] <?php include("exportrss.php"); // Parse XML/RSS 2.0 feed $feed = new ExportRSS("test.xml", "2.0"); $channel = $feed->get_channel_data(); echo "<h3>Channel</h3> <p> <b>Title:</b> {$channel['title']}<br/> <b>Date:</b> …

0
333
Member Avatar for Ancient Dragon

This is a simple example of how to delete a line from a text file. In order to do that you have to completely rewrite the file, leaving out the line(s) you want to delete. First open the input file, then open an output file (doesn't matter what filename you …

Member Avatar for majestic0110
0
11K
Member Avatar for ankur.dhoot

This code changes color of prompt according to user, suppose if user is root then color would be red and normal user would have color black. This'll diffrentiate in users.

0
156
Member Avatar for cms271828

This program generates the 6 faces of a colour cube. The faces are displayed in a JPanel, and they are also saved to C:/Faces as PNG files. So non-windows users might have to alter code slightly.

Member Avatar for cms271828
0
173
Member Avatar for rohit83.ken
0
114
Member Avatar for maddog39

This snippet will allow you to separate or "explode" strings into vectors via a character separator or the visa versa. In which case you would take a vector and "implode" it into a string separated by a character. Also keep in mind that this requires the libboost libraries. This was …

0
571
Member Avatar for Shaffer

Hello, this code snippet is a function used to manage an unlimited amount of hit counters with a text file. [B]It is crucial that each page will only be displayed once.[/B] The text file syntax: [code] page_name.php:0 page_name.php:0 [/code] An example of a text file that was just set-up (not …

0
87
Member Avatar for vegaseat

A simple example of applying a font to a text displayed with wxPython's wx.StaticText widget.

0
602
Member Avatar for Shaffer

This function distributes mail to a mailing list, out of an array. Wether the array is plundered from a database, a file, or from the code, the function only takes a prepared one. Also, this function is only good for HTML messages. The array's syntax is to be: [code] array("recipent's …

Member Avatar for sonny.scroggin
0
143
Member Avatar for Shaffer

This function caps a specific letter of a string, and returns the updated string. THe first letter is 0, as it is default as well.

Member Avatar for Shaffer
0
149
Member Avatar for GreenDay2001

Generates all primes till n terms. Not a wonder scripts which will generate till billions, but works pretty fine till few millions.

Member Avatar for muthu_tek
0
148
Member Avatar for vegaseat

Just bouncing a red ball within the frame of a window, the twist here is that the image is stored within the code as a base64 encoded string of the gif image. This way you only have to distribute one file. The Python code is heavily commented, so you can …

Member Avatar for Arkapravo
2
375
Member Avatar for lookof2day

Well any Java programmer knows that a Java Interface only allows declaration of methods. You cannot define the methods inside interfaces. Yet if somebody like me wants you to define a method in interface and wants the program gets compiled and runs successfully, what would you do? Well the answer …

Member Avatar for Ezzaral
0
722
Member Avatar for Hamrick

A simple solution that prints the first n values in the fibonacci series up to the limit of an unsigned long. The program takes either command line arguments or interactive input for n and has code in place to make the program more flexible, like printing to a file.

0
157
Member Avatar for bumsfeld

The Python module datetime allows you to calculate the days between two given dates with relative ease. I am using the US date format month/day/year, but you can change that by giving attention to the order of the extracted tuple.

0
492
Member Avatar for vegaseat

Using count() from Python's itertools module and the Tkinter GUI toolkit's after() function, you can create a simple counter that counts up the seconds until the Stop button is pressed.

1
3K
Member Avatar for avgprogramerjoe

This code takes a string a cyphers it by shifting it's position in the alphabet. I've gotten it so it can pretty much take paragraphs. It's quite neat to play with. For example the above when shifted to 5, would be: Ymnx htij yfpjx f xywnsl f hDumjwx ny gD …

Member Avatar for ShawnCplus
0
143
Member Avatar for Tight_Coder_Ex

User can enter an ascii string of up to 48 characters consisting of 1's or 0's, with randomly interspersed whitespace. IE: [B]1011111001011110 [/B]will be evaulated equally to [B][1011][111....cc001cccx01 111hhhh0 [/B]Algorithm parses from right to left so will be truncated at 16 position Purpose is to give all those still programming …

0
438
Member Avatar for jasimp

This one works pretty fast, even for large numbers. Like it says, aproxomite end number, and that is because it will generally go one fibonacci number above what you specify.

Member Avatar for ilovepython1978
0
150
Member Avatar for TkTkorrovi

You likely want something graphical, where the things move. GTK version of the classic arcade game Asteroids.

Member Avatar for TkTkorrovi
0
140
Member Avatar for vegaseat

The wxPython wx.lib.fancytext widget allows you to display super and subscripts in texts, and allows you to change fonts and colours too. All this is done with XML coded strings. XML documentation code is tag based and not that difficult to understand. It looks rather similar to the older HTML …

0
416
Member Avatar for jasimp

All this snippet does is asks you for some information and then uses it and some math to guess your age. Pretty simple but I have to start somewhere.

Member Avatar for majestic0110
0
157
Member Avatar for vegaseat

The wxPython GUI toolkit has a number of calendar widgets, but the one that is most customizable is the wx.lib.calendar widget. Here we expanded it to colour the weekends and the holidays supplied by a dictionary of 'month: list of holiday dates in month' pairs. Since some holiday dates can …

0
2K
Member Avatar for bumsfeld

The wxPython GUI toolkit has a nice numeric LED widget (LEDNumberCtrl from the wx.gizmos module) that is used here for displaying the current time in very visible 7 segment LED color display. It also shows the application of the time module and wx.Timer(). The code is simple as far as …

0
2K
Member Avatar for TkTkorrovi

A small demo about how to use GTK label as a simple console. To compile GTK program, `pkg-config gtk+-2.0 --cflags --libs` should finally be somewhere in the compiler command line in the bash-like shell.

0
313
Member Avatar for darkscript
Member Avatar for ShawnCplus
0
594
Member Avatar for MitkOK

Here are two simple functions to validate name and e-mail . int [COLOR="#008000"]valName[/COLOR]( string $arg1 ) - this function returns 1 if name is correct, 0 if incorrect int [COLOR="Green"]valMail[/COLOR]( string $arg1 ) - this function returns 1 if name is correct, 0 if incorrect

0
187
Member Avatar for TkTkorrovi

Replaces every occasion of the pattern, or only the first occasion if there is a subexpression, between \( and \), anywhere in the regular expression, as repeated replace is not what one would expect in that case. The string size is restricted in POSIX regular expressions to the size of …

Member Avatar for xaviv
0
1K
Member Avatar for darkscript

This filters out the letters and numbers in the parameters you give it.

Member Avatar for hinduengg
0
127
Member Avatar for Sturm
Member Avatar for vijayan121

a string which can be used ala std::string, preserves case, but comparisons are not case sensitive.

Member Avatar for ~s.o.s~
0
463
Member Avatar for Arman Majumder

A JOptionPane version of the game of Penny Pitch. Uses numerical values spread on a board, and computer picks randomly chosen spot to place a penny and at the end of a run adds up the total score. *Two separate programs, PennyPitchGame and Square (Square Class)*

Member Avatar for NovaWarlock
0
2K
Member Avatar for Arman Majumder

A program that compounds interest [FONT=&quot]continuously [/FONT]to a specified premium, rate, and number of years. Displays the total work up in the GUI panel in a tree form.

0
178
Member Avatar for Arman Majumder

A simple program that displays the Muller-Lyer Illusion. Also tests the ability to draw simple figures using the Paint Component function.

0
1K
Member Avatar for Arman Majumder

A GUI form of the Game of Craps. Takes in total bank roll and bet for each round of the game. *Two seperate programs, Craps and CrapsData(Craps Class)*

0
1K
Member Avatar for Arman Majumder

A very simple program, which displays the coordinate points for the center point of the panel. Automatically updates the (X,Y) form coordinates with size modification.

0
731
Member Avatar for Arman Majumder

A red circle moves back and forth horizontally, when clicked (with a mouse) the circle halts motion and the background colour changes randomly, if clicked again the circle resumes it's motion and changes the background colour randomly. This loop continues until the user exits the program. *Two separate programs[FONT=&quot][/FONT], CirclePanel …

Member Avatar for cUtEAkew
0
1K
Member Avatar for Arman Majumder

A fixed Checkerboard board, which tests multiple panels each with alternating colors (Red and Black). Input the dimensions to output the board.

0
1K
Member Avatar for Arman Majumder

A simple GUI that tests the GridLayout function, multiple panels, and different coloured panels.

0
301
Member Avatar for msaqib

Demonstration of Linked list in java. Very simple and well commented java code for the beginners. Linked list of points are used to create a Polyline and display it More java codes at [URL="http://www.mycplus.com"]www.mycplus.com[/URL]

Member Avatar for jwenting
0
246
Member Avatar for sweetleaf

THE program highlights how to create a 2d array in freestore using pointers.. this is my first post so if i commit any fallacies regarding protocol or syntax please forgive me ....

0
110
Member Avatar for GreenDay2001

This would let you store different things of same type into one data structure, here its a list. A good and popular example would be file and folder hierarchical structure in your computer. Perhaps this is what this code demonstrates. The code has two classes [INLINECODE]File [/INLINECODE]and [INLINECODE]Directory[/INLINECODE](derived from File). …

0
298
Member Avatar for aj.wh.ca

Problem Description ----------------------- I tried to download my favourite site containing essays on history (leeching) with depth 4. For some reason say my download tool problem, I realized I could not download all the files. I had with me a list of files (list1) I downloaded and list of files …

Member Avatar for vegaseat
0
115
Member Avatar for Ene Uran

This simple Python code uses the Tkinter GUI toolkit and the Python Image Library (PIL) to create a program that allows you to grab an image of the display screen (or portion of it) and save it to an image file. Unfortunately, the ImageGrab.grab() method only works on a Windows …

Member Avatar for AndyGman
1
3K
Member Avatar for php4ever

While doing a redesign of two sites I had this need to take my clients TemplateMonster template and show flash on ONLY the front page and a static image on the internal pages but the problem was that it ran on a template engine which used a single load header …

0
88
Member Avatar for php4ever

Okay so I had this need to vary the template layout of an osCommerce theme using its BTS (basic template system) and noticed that unlike standard osCommerce where you can edit each and every individual page to have a unique layout, BTS uses a template system to generate its look. …

0
126
Member Avatar for vegaseat

Just a little mathematical exercise in geography, namely the use of longitude and latitiude coordinates to calculate the distance between two given cities. You can obtain the coordinates for just about any earthly city from [URL="http://www.ASTRO.COM"]WWW.ASTRO.COM[/URL]. The coordinates are in a format like 35n13 (35 degrees, 13 minutes north). The …

3
2K
Member Avatar for Stylish

I needed a way to spawn multiple threads, have them monitored, and restarted if an error occured. I came up with the following. This snippet is from a larger program, so if there is a problem please let me know. This is for command line and tested on Linux (well, …

0
125
Member Avatar for Stylish

Here is a little spinner thing for the command line, used when your current bash script is waiting on a background/system process. The weird character is ^H or a backspace.

Member Avatar for cfajohnson
0
254
Member Avatar for thekashyap

------------------------------------------------------------ [COLOR=Blue][B]Intro:[/B][/COLOR] This is a small program that measures the performance of given java classes. In snippet there are 2 classes: 1. TestClass.java contains all java classes that are being measured for performance, I've picked up Narue's Sorting Algorithms as AUT (application under test) 2. AJPerf.java: contains the aspect that …

Member Avatar for thekashyap
0
150

The End.