1,916 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for vegaseat

The module pyglet leans on OpenGL for graphics and is used in the scientific community together with Python. This short code snippet shows you how to use it to display an animated GIF file. The download is free, so give it a try. You don't have to download OpenGL to …

Software Development opengl python
Member Avatar for kwekey
4
17K
Member Avatar for Dave Sinkula

Many times [inlinecode]strtok[/inlinecode] is recommended for parsing a string; I don't care for [inlinecode]strtok[/inlinecode]. Why? [list][*]It modifies the incoming string, so it cannot be used with string literals or other constant strings. [*]The identity of the delimiting character is lost. [*]It uses a static buffer while parsing, so it's not …

Software Development c
Member Avatar for anti_neoliberal
0
10K
Member Avatar for Geekitygeek

It is a common design in data handling applications to move from form to form to show the user different information. I have seen any number of different attempts at this on the boards so i thought I'd throw together a short snippet to show a cleaner OO way to …

Software Development web-design
Member Avatar for jacss1x
1
3K
Member Avatar for vegaseat

Just a simple exploration of the goslate module (uses the Google Translate API) to translate some common languages. However, some IDE's create character problems. Note: Your computer has to be connected to the Internet to access Google.

Software Development api python seo
Member Avatar for Ekta_1
3
2K
Member Avatar for james6754

Hi everyone this is my first code snippet so be gentle.. I have written a basic client/server chat program that uses multithreading for listening and sending. I welcome any improvements or discussion... Thanks James

Software Development client-server java multithreading
Member Avatar for Arpit_1
2
12K
Member Avatar for djjeavons

This code snippet demonstrates how to use ADO.NET to read the contents of a Microsoft Excel Worksheet. This snippet also demonstrates the use of the [GetSchema](https://msdn.microsoft.com/en-us/library/ms135981%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396) method to determine what worksheets are available within an Excel workbook allowing the end user the ability to select a specific worksheet in order …

Software Development display microsoft-office open-source
Member Avatar for vivek_sharma
2
2K
Member Avatar for Luckychap

This is a program for Encryption and Decryption This program uses the Simple Data Encryption Standard (SDES) Algorithm. This Algo takes 8-bits of plaintext at a time and produces 8-bits of ciphertext. It uses 10-bits of key for Encryption and Decryption.

Software Development algorithm c++ encryption
Member Avatar for overwraith
1
13K
Member Avatar for major_lost

I know that this probably has been done by someone, but I want to learn how to do this using VB 2010 express. I cannot seem to get the numbers to stay in the text boxes that they are dropped in. The numbers always go to the last box (#81). …

Software Development puzzle vb.net
Member Avatar for Reverend Jim
0
504
Member Avatar for ddanbe

Some time ago, I needed to know the pathname of my running application, in order to create a temporary file. As it seems ther are alot more options than I thought. So I applied all I could find in this little snippet. I also used the full names to make …

Software Development file-system
Member Avatar for Teme64
1
2K
Member Avatar for ddanbe

This is easy! But I admit, it can be rather confusing at first if you also take the old style MenuItem stuff into account. I hope my code is as clear as possible. If not please let me know. To test it, just start a forms application and paste it …

Software Development c#
2
6K
Member Avatar for dileepkumar235

Login functionality in C-language : Here the user enters the user id and password. The entered user id and password will be compared with the stored ones and user will be authenticated. While user enters password, characters should not be displayed on the screen. user id comparison must be case …

Software Development c
Member Avatar for Tanmay_1
0
4K
Member Avatar for ShiftLeft

For those interested in operating system development, this snippet tests status of A20. It is the line that allows memory beyond 1 meg to be addressed, otherwise it will just wrap around which some applications and versions of DOS depend on. My bootloader **MBR1_44** has switched system to protected (*32 …

Software Development assembly operating-system
0
291
Member Avatar for ddanbe

This is a small one. Some time ago this table came in handy, testing out low level multiplication. And I just love multiplication tables. We all do, now don't we? :)

Software Development
0
440
Member Avatar for fonzali

since the forum has been quiet for a while I thought to post this program , it might start new discussions . the idea is not new but it should be interesting to starters . as usual any comments is appreciated

Software Development python tkinter
Member Avatar for fonzali
2
2K
Member Avatar for ddanbe

One of the most, if not THE most, beautiful formulas in math, is from Euler: ![Euler_e_pi_i.png](/attachments/large/1/b32f45540a27b3efc328d14c60ee286c.png "align-center") It combines in it a relation between the number **e**, the number **Pi** and the complex number **i**, plus the basic math symbols 1, +, = and zero. Is that not amazing? More …

Software Development c# mathematics
Member Avatar for JOSheaIV
1
616
Member Avatar for ddanbe

After reading this excellent [code snippet](https://www.daniweb.com/software-development/csharp/code/492766/display-excel-data-in-a-datagridview) by djjeavons, and just trying to learn WPF, I decided: "Well, let's translate that to WPF!". It was a bit harder than I thought, but a great learning experience! Her's how my screen in action looks: ![WPFscreen.png](/attachments/small/1/ac05d33ccd8a190d0576fa063e54749f.png "align-left") Things that changed compared to the …

Software Development asp.net microsoft microsoft-office
Member Avatar for ddanbe
1
552
Member Avatar for ddanbe

Inheritance with generic types can sometimes be tricky. If you would inherit from a Stack<double>, no problem, but what if you want to keep it as generic as possible? Maybe it's a bad idea, but I wrote something like `class Stacker<T> : Stack<T>` and in Stacker I implemented some arithmetic …

Software Development oop
Member Avatar for JOSheaIV
1
778
Member Avatar for iPoor

This is the code to align the content of a Panel in the Center, Hope this Helps :)

Software Development vb.net
Member Avatar for iPoor
0
4K
Member Avatar for BustACode

I found that one can use dictionaries to hold Tkinter widget config and display parameters. This then permits one to have these dictionaries elsewhere in the code for easy modification instead of buried within the code for each widget. I particularly like to place these dictionaries toward the top of …

Software Development display python tkinter
0
3K
Member Avatar for BustACode

I have been learning NumPy arrays/matrices in Python. As I worked, I found that I desired a more readable form of 3d matrices. So I figured that writing one would be a good goal and learning exercise. The goal was to create a function that would print 3d NumPy matrices …

Software Development matrix-multiplication python
0
3K
Member Avatar for DragonMastur

It could be simplifide more, I know. I was doing it as an exersise so its rough and skecthy. But it's workable, I tested it more then 50 times.

Software Development python
Member Avatar for Slass33
0
532
Member Avatar for vegaseat

This is the updated version of the Tiny Tkinter Calculator. It has more power, since you can type in functions contained in the Python math module then press the equals key. You can then move the result into memory for other calculations. The code is written in OOP class style …

Software Development oop python tkinter
Member Avatar for vegaseat
4
2K
Member Avatar for vegaseat

The example shows how to establish a dictionary of (row, column):value pairs to mimic a two dimensional array. This can be easily expanded to more dimensions. Python3 has dictionary comprehension, making the process of creating a dictionary of this type easier.

Software Development python
Member Avatar for vegaseat
1
7K
Member Avatar for vegaseat

Just a simple password creator using Python code. The length of the password can be set and the characterset could be changed if you so desire.

Software Development python
0
576
Member Avatar for DragonMastur

I needed a calculator and I didn't want to use google since my internet is slow. So I made one! Here it is. Working with it is simple. Use the number and operation keys("c" for clear, "p" for pi, and "s" for sqrt) as well as the return and enter …

Software Development gui python tkinter
0
699
Member Avatar for DragonMastur

karmstrong ask in the Python chat if any one was farmilar with converting a for loop in C to Python. Here is a program in python that will do it for you! Thank You!

Software Development python
Member Avatar for vegaseat
0
823
Member Avatar for vegaseat

This is a test to get the Python snippets going! For those of you who are scared of snakes, the language is named after the TV program, not the snake. Python is an interpreted language, but programs to compile/combine the code to an exe file are available (Py2Exe). The latest …

Software Development python
Member Avatar for vegaseat
2
3K
Member Avatar for DragonMastur

I made a little py editor because I didn't want to go to all the troble of installing an idle, but I didn't like notepad either. Here it is!

Software Development python
Member Avatar for DragonMastur
3
319
Member Avatar for ddanbe

Sometimes, when I have really, really nothing else to do, I start doodling with some code. Wanted to display the coordinates of the mouse pointer. Thought it was complicated, but it was rather easy. Look, starting at line 94. Then: why not explore a [Bezier curve](https://en.wikipedia.org/wiki/B%C3%A9zier_curve), and what if I …

Software Development pc-peripheral
0
262
Member Avatar for William Hemsworth

Quite a while ago, I made [URL="http://www.daniweb.com/code/snippet217147.html"][B]this[/B][/URL] snippet. This code is basically the same, except that it adds animation. This method of blitting is very fast assuming you don't use a surface that's too large. On a 500 x 500 surface, I managed 350fps using only 0-1% of the cpu. …

Software Development api c++ image microsoft
Member Avatar for thetukiet
1
7K
Member Avatar for vegaseat

The bubble sort is slow and I thought it would be interesting to visualize the progress as it sorts an array of integers.

Software Development c
Member Avatar for David_50
5
746
Member Avatar for vegaseat

Here lambda is used to create a one-line function for factorials.

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

Needed a func to convert base 2 into 10, and back. Found the referenced code in this func for moving between three bases, and generalized it to between bases 2 and 62, and all in between. Upconvert a number, then down convert, then upconvert again. Go wild, have fun.

Software Development python
0
633
Member Avatar for BustACode

In my quest to learn more regarding programming in Python, I "dissect" a lot of other people's code. While doing this, or writing my own code, I end up with 10's of debug print lines. Things like this: if v_Debug == 1: print("DEBUG - ".format()) # DEBUG If I decide …

Software Development python
Member Avatar for Mark_37
0
276
Member Avatar for BustACode

I, and many others, desired a "switch" keyword in Python. For me it was to a desire to make some of my code more compact and readable, as I often have many user selected options for the code to weed through. So I set off on a journey to figure …

Software Development assembly python visual-basic
Member Avatar for Mark_37
0
603
Member Avatar for TnTinMN

I have just seen a resurrected thread about issues with loading images to a PictureBox and the inability to delete the file while the program is running. There was no clear explaination of the problem, only suggested hacks and apparent frustration. So I thought I would offer this explanation from …

Member Avatar for J.C. SolvoTerra
0
7K
Member Avatar for jephthah

too many new and intermediate users of C attempt to use the command [icode]fflush(stdin)[/icode] to "flush the input buffer". this is patently wrong. the rule is (and click if you don't believe me) : [URL="http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1052863818&id=1043284351"]NEVER [/URL][URL="http://answers.yahoo.com/question/index?qid=20071013052534AAuxWmW"]USE [/URL][URL="http://www.gidnetwork.com/b-57.html"]"FFLUSH()"[/URL] [URL="http://www.linuxforums.org/forum/linux-programming-scripting/41287-problem-fflush-stdin-function.html"]ON [/URL][URL="http://www.it.usyd.edu.au/~dasymond/mirror/c-faq/stdio/gets_flush2.html"]INPUT [/URL][URL="http://www.cplusplus.com/forum/general/6554/"]STREAMS [/URL][URL="http://c-faq.com/stdio/stdinflush.html"]SUCH [/URL][URL="http://gcc.gnu.org/ml/gcc-help/2009-01/msg00287.html"]AS [/URL][URL="http://www.dreamincode.net/forums/showtopic45833.htm"]"STDIN" [/URL] here is one method of properly …

Software Development c perl
Member Avatar for David_50
0
6K
Member Avatar for vegaseat

I have joined the thousands who have done it before, and have compared a number of sorting routines. The sorting is done on the same random-integer arrays. No surprises, quicksort wins this simple comparison hands down. There are clever combinations of sorting routines that are faster, like the snippet by …

Software Development c
Member Avatar for vegaseat
2
253
Member Avatar for vegaseat

A few hundred years ago the glorious leader of a big country wanted to reward the creator of the chess game. The creator of the game simply wanted one grain of rice put on the first square of the chessboard, two grains on the second, then doubling it for every …

Software Development python
Member Avatar for vegaseat
2
8K
Member Avatar for BustACode

I needed a random color selector. I found one [here](http://peepspower.com/python-script-to-generate-random-css-colors). I rewrote it to make it more general purpose. "f_GenRandomColor" is the picker. The output is in list form, which should make it suitable for most general applications. "f_HTMLRandomColorChart" is just a way to create an HTML table to test …

Software Development html-css python
Member Avatar for snippsat
2
523
Member Avatar for ShiftLeft

This will take a value in EAX or AX, convert to ASCII hex with optional padding and upper or lower case This example would yield "---fc103a" push word 0x222d ; 32 bit conversion, padd output with '-' push word ASCPntr ; Pointer to end of conversion buffer push 0xfc103a call …

Software Development assembly
0
404
Member Avatar for TnTinMN

I am posting this in response to those who ask about replacing the webbrowser (WB) control’s default browser. You cannot ask the WB control to use a different browser, it is hardwired to use the current version of Microsoft’s Internet Explorer that is installed on the target computer. It may …

Software Development vb.net web-browser
Member Avatar for Jim_8
1
3K
Member Avatar for vegaseat

Just some interesting applications of the bitwise and (&), or (|) operators. You might find some other uses.

Software Development python
Member Avatar for vegaseat
0
282
Member Avatar for BustACode
Member Avatar for vegaseat
0
1K
Member Avatar for vegaseat

This shows the application of a Memoize decorator to speed up recursive functions in Python.

Software Development python
Member Avatar for vegaseat
4
689
Member Avatar for BustACode

Allows multiple entries using raw_input. I often have to enter multiple items in my Python programs. I desired an easier way than using a loop(s). Today I discovered a way, and with a few mods made it happen.

Software Development python
1
699
Member Avatar for vegaseat

Just an example of a persistent list class that could have interesting applications in data mining.

Software Development python
1
682
Member Avatar for ddanbe

This is just for fun. You know how old you are(I hope), but do you know how many days you are walking around on this planet? The two routines presented here could be used more practically in an ever present employee application.

Software Development
Member Avatar for ddanbe
0
730
Member Avatar for vegaseat

Sometimes it's easier to pick an image from the internet to display in your Python Tkinter GUI toolit program.

Software Development image python tkinter
Member Avatar for vegaseat
1
5K
Member Avatar for vegaseat

Shows how to convert a comma separated value (csv) string to a list of records, and then do some data processing. The csv strings usually come from csv files created by spreadsheets.

Software Development python
Member Avatar for vegaseat
1
3K

The End.