1,916 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for chriswelborn

I started using Python a few weeks ago, something finally clicked and I started writing tools for my personal use. I started writing something with a GUI using GTK and the code lines started multiplying rapidly, so I thought to myself "Am I commenting my source to death? How many …

Software Development gui python
Member Avatar for chriswelborn
2
368
Member Avatar for TrustyTony

As in C++ was some question about speed of simple hard disk based lookup, here is a version of unscramble program completely HD based lookup, which gives all possible candidate words for multiword anagram. Program is not sensitive for case of words but does not ignore special characters like ' …

Software Development python
Member Avatar for svfox2000
0
1K
Member Avatar for chriswelborn

This is a script that was supposed to be very basic, just running a command with my scripts arguments attached. I didn't realize that if user 'cj' opens firefox, when user 'root' does '**firefox -new-tab**' it doesn't work. Firefox will just open a new window, and thats exactly what I …

Software Development python seo web-browser
Member Avatar for chriswelborn
0
314
Member Avatar for mike_2000_17

Hi all! This is a simple piece of code that I wrote about a year ago, in response to a question on Daniweb. I decided to infuse it with some C++11 magic, which led to a pretty sweet code snippet, full of neat little techniques you might want to use, …

Software Development c++
Member Avatar for mike_2000_17
3
1K
Member Avatar for everettnewell

With both subs you must enter the values as you would write them into a sql string i.e. 'mustsurroundstrings' I'm rather new at VB.Net and SQL but these work for me and are seem pretty efficient. If anyone has a way to improve on them or finds a flaw in …

Software Development sql vb.net
Member Avatar for Maulikpra
0
539
Member Avatar for Dave Sinkula

While not terribly difficult, first timers may not know the functions to look up and use. Here is some basic code for reading a file one line at a time. The contents of the file are printed to the stdout.

Software Development c
Member Avatar for 'CoffeeLike
2
61K
Member Avatar for ashine80
Member Avatar for ScottieF
0
167
Member Avatar for Lucaci Andrew

Here's some simulation of the basic push_back and pop_back functions from stl vectors, "inspired" by this thread: http://www.daniweb.com/software-development/cpp/threads/427912/question-about-a-simple-vector-class-template

Software Development c++
Member Avatar for Rashakil Fol
0
501
Member Avatar for avgprogramerjoe

This is a simple game of pong with made using pygame. You will need to make a picture of the pong for it to run properly. Simply make a cirlce in paint, 25x25. Joe

Software Development python
Member Avatar for astronautlevel
0
3K
Member Avatar for Labdabeta

I wrote this program because I often am asked by people that know that I like to make games to make just a quick simple game for some reason or another. I always make a simple text based adventure game (like Zork, but simpler) and they are usually happy with …

Software Development c++ gaming
0
486
Member Avatar for TrustyTony

Because of [C++ code snippets not dealing with multiple +-](http://www.daniweb.com/posts/jump/1829367) in sequence (or even negative number) in expressions, I post this, as it is so much easier for me than C/C++. EDIT: Fixed signs together with '(' issues and '+' at beginning removing without lstrip, removed separate now unused '(' …

Software Development python
0
413
Member Avatar for TrustyTony

This is bit funny code as you can first read from this excellent response: http://www.daniweb.com/software-development/python/threads/427341/custom-types-in-a-simple-way#post1828718 why should you not use it, even it maybe feels useful. Anyway I got curious to see how type signature could be implemented, even using it would generally just be stupid way of slowing down …

Software Development python
0
279
Member Avatar for Lucaci Andrew

This is a program which I made back in the beginnings when I was trying to figure out how to work with strings, and how to work with files. This is suppose to format a C++ code, for example if the syntax of an if statement is if (condition) { …

Software Development c++
Member Avatar for Lucaci Andrew
0
368
Member Avatar for HTMLperson5

This is a goofy sentence generator I have made in python; it took about 5 minutes to get the code to work - but its working now so if your curious try it out!

Software Development python
Member Avatar for HTMLperson5
-1
573
Member Avatar for pritaeas

The `ReplaceStrings` function replaces all strings in `APatterns` found in `ASubject` with the value in `AReplacement`. As an example, I added the `RemoveStrings` function which replaces everthing with an empty string, thus deleting all strings found. Usage examples are in the XMLDoc comments. A good test will be to rewrite …

Software Development delphi pascal
Member Avatar for pritaeas
0
283
Member Avatar for ashine80
Member Avatar for HTMLperson5

This is a program using the `urllib` module to find the (html/any client-side script) source code of any website which exists. Have fun!

Software Development python
Member Avatar for M.S.
0
172
Member Avatar for ashine80
Member Avatar for Ancient Dragon
0
316
Member Avatar for ashine80
Member Avatar for ashine80
Member Avatar for TrustyTony
0
161
Member Avatar for ashine80
0
194
Member Avatar for ashine80

To Check Whether the Given Point P is inside a Triangle or Not..

Software Development c
0
138
Member Avatar for TrustyTony

Here you see how one could use recursion together with generators for (inefficient) permutations generator. It is kind of interesting to know how one can do it recursively (of course there exist many ways). Anyway this snippet demonstrates how you can use recursive generator call to feed a for statement. …

Software Development python
0
435
Member Avatar for TrustyTony

I googled little around for correct way to not reinventing of the wheel for expression evaluation (even I had done some simple evaluation check for my [Tkinter calculator snippet](http://www.daniweb.com/software-development/python/code/282548/simple-calculator) earlier). After getting totally upset with [this example](http://www.bestcode.com/html/evaluate_math_expressions_pyth.html), I made this with some struggles with `__builtins__` globals parameter of eval. First …

Software Development python tkinter
0
642
Member Avatar for Lucaci Andrew

Inspired by some C and C++ threads regarding finding a specific pattern in a file.

Software Development python
Member Avatar for TrustyTony
0
319
Member Avatar for Gribouillis

When working whith large data files, it may be desirable to output a sequence of bytes by large chunks. This snippet defines a file adapter class to handle this transparently. Writing bytes to an ChunkedOutputFile will automatically write the underlying file object by fixed length chunks.

Software Development python
Member Avatar for Gribouillis
3
4K
Member Avatar for Aviras

Hello everyone, this is something I wrote a couple months back. It is used as a universal class/object loader from an XML file. For the handling of XML I use the JDOM library. The story basically goes like this: I have a load of classes in a game I'm working …

Software Development java xml
Member Avatar for Troy III
1
396
Member Avatar for TrustyTony

Sometimes we want to tackle some problem specifying properties of sequence of numbers consisting the integer. Then it is usefull to have function to join many integers to make a long integer. Most efficient way for tight loops is to stay in integers domain and not go through the string …

Software Development python
Member Avatar for TrustyTony
0
298
Member Avatar for TrustyTony

Finding efficiently primes, whose begining numbers are also primes. See the thread http://www.daniweb.com/software-development/cpp/threads/425821/prime-number-c in C++ forum for discussion on topic.

Software Development python
1
275
Member Avatar for jnawrocki
Member Avatar for jnawrocki
0
280
Member Avatar for Lucaci Andrew
Member Avatar for Lucaci Andrew
0
498
Member Avatar for jhai_salvador

Hi! This is my submission for code snippet contest. I also posted this code to help other members on how they can use compact & repair their MS Access Database within Visual Basic 6.0. You also need to add Microsoft Jet and Replication 2.6 in your project reference. To use, …

Software Development microsoft microsoft-access visual-basic
Member Avatar for jhai_salvador
3
2K
Member Avatar for vegaseat

This code snippet allows you to list the files in a folder sorted by "last modified date". The tuple returned by the os.stat() function contains amongst other things the last modified date, which is then converted by the time.localtime() function to a tuple that is ideal for sorting. You can …

Software Development file-system python
Member Avatar for leong87
2
8K
Member Avatar for TrustyTony

We can run Python2 script in most simple cases if we just use the 2to3.py script found in recent Python versions: F:\Python27\Tools\Scripts>copy \test\output_window_tk.py \test\output_window_tk2.py 1 tiedosto(a) on kopioitu. F:\Python27\Tools\Scripts>2to3.py -w \test\output_window_tk.py RefactoringTool: Skipping implicit fixer: buffer RefactoringTool: Skipping implicit fixer: idioms RefactoringTool: Skipping implicit fixer: set_literal RefactoringTool: Skipping implicit fixer: …

Software Development python tkinter
0
786
Member Avatar for BestJewSinceJC

Since I keep seeing people asking how to read the Integers from a File, I figured this simple snippet might be useful. What it does is it creates a new Scanner Object based on the File Object "test.txt" then it reads all of the Integers from that file, skipping over …

Software Development file-system java
Member Avatar for Ezzaral
0
5K
Member Avatar for lxXTaCoXxl

Just a couple basic static mathematical helper methods that I've found useful for game development. Feel free to add some in replies for future visitors. I will do another post later this week with advanced helper methods from trig and calc. I will also do a geometry helper class as …

Software Development
Member Avatar for skatamatic
0
159
Member Avatar for Gribouillis

This python 2 code snippet uses unicode chess symbols and box drawings symbols to display a chessboard in a terminal. With a terminal profile having a monospace font of size 20 or more, it looks quite usable to play chess.

Software Development python
Member Avatar for Kyril
3
7K
Member Avatar for rhoit

i don't know how it happen but the exe formed after compilation was 1.23 MB which has never happen before.

Software Development c++
Member Avatar for rhoit
0
369
Member Avatar for peter_budo

Simple code to see if array of primitives has duplicates. The aim is to only check if there are any duplicates, but not to check what element is repeated, or its position etc. PS: Do you know some handy snippet? Don't way, post it!

Software Development java
Member Avatar for odoepner
4
973
Member Avatar for Reverend Jim

This code demonstrates how to add controls to a form at run time. The number of rows and columns, the spacing between the controls and the size of the controls are all determined by Consts, but this could easily be changed so that the parameters are user entered. My example …

Software Development vb.net
3
670
Member Avatar for vinayphadke

Hello Guys, I was performing text file reading and writting operations and the job looked very simple as usual, yet it has not been solved successfully. We have got a simple text file **final.txt** which contains data like this:- **05/18/2012 02:12:66 8HRY hjhruehr737243 YES NO u34gewryge 698** i.e each value …

Software Development c c# c++ file-system
Member Avatar for gnath
0
265
Member Avatar for lxXTaCoXxl

Figured I've been working on material for a while and would throw these up for everyone that needs them in the future to use. It's very simple implementation; if I get enough people asking me to, I will write the methods for each of the instructions so you don't have …

Software Development assembly seo
Member Avatar for skatamatic
0
280
Member Avatar for lxXTaCoXxl

I had a small problem with collision detection starting out with XNA 4.0 so I figured I'd release a simple snippet that helps with two different types of collision detection; Per-Pixel and Rectangular. To use simply copy and paste the snippet into your current source, or you could put it …

Software Development
Member Avatar for tpb_rocpile
0
250
Member Avatar for Clinton Portis

have fun with this game o' keno! post here with your highest winnings

Software Development c++ gaming
Member Avatar for Nick Evan
0
166
Member Avatar for vegaseat

I borrowed this from C#, where you can easily send output, that normally goes to the ugly black console window, to a nice looking Windows MessageBox with an OK button to close after you read your results. You can accumulate your output in a string to send to one message …

Software Development c display gui microsoft
Member Avatar for nagendra_rao
0
874
Member Avatar for zachattack05

![UnderlinedLabel](/attachments/small/2/UnderlinedLabel.JPG "align-left") I was tired of always looking for a way to underline labels like in Windows property dialogs. I created this little control that allows you to set a two-tone line above, below behind or in front of a label (even through it!) to solve that problem. The image …

Software Development open-source
0
196
Member Avatar for TrustyTony

Gribouillis has allready posted code similar to this in his snippets, but here version for input suitable for for expressions, generators and list comprehensions. Need to add robustness by some try...except blocks for real world use.

Software Development python
Member Avatar for vegaseat
0
553
Member Avatar for Gribouillis

This code snippet provides methods to convert between various ieee754 floating point numbers format. For example double precision to single precision. The format is given by a pair (w, p) giving the size in bits of the exponent part and the significand part in the ieee754 representation of a number …

Software Development python
Member Avatar for TrustyTony
1
5K
Member Avatar for lxXTaCoXxl

I get tired of having to google this simple line of code all the time. My problem with memorizing it is that I switch back and forth between C# and C++ all the time, and the way you overload operators in each is different. So once I learn one again, …

Software Development
0
174
Member Avatar for TrustyTony

This came up, maybe it is usefull to somebody. Later I plan to do a managing context interface to `with`statement for this.

Software Development microsoft python
Member Avatar for TrustyTony
0
2K

The End.