2,322 Reusable Code Snippet Topics
Remove Filter ![]() | |
Using the Python win32 extensions it is relatively simple to copy to and from the clipboard. Sorry. the Windows OS is a requirement. | |
Just a small mildly optimized function to check if an integer is a prime number. For very large numbers use the Miller-Rabin primality test. There have been questions why I used `not n & 1` to check for even integer n. The more tradional` n % 2 == 0` is … | |
You can accesss the clipboard simply by using the Tkinter GUI toolkit that comes with your Python installation. | |
By means of Mates8, graph coding becomes a bit easier. The web page has four textboxes so the figure gets bounded to the left, right, top and bottom; and a draw button. Additionally, a panel control will contain the image generated by the code after the button is pressed. | |
A dictionary in Python is an unordered set of key:value pairs. I show you how to initialize, create, load, display, search, copy and otherwise manipulate this interesting container. Like the name says, it is the closest thing to a dictionary. | |
Python's double ended queue module makes Caesar's cipher easy. | |
The .Net Framework uses by default radians in its trigonometry calculations. Find out how to convert degrees to radians to use with C# | |
Use the PySide (PyQT) GUI toolkit to play animated gif files. | |
If you draw a series of close spaced shapes your eyes get fooled to see Moire patterns. Here is one example of this. | |
Sometimes you want the value of a variable to be related to its name in the source code. For example, the variable x should have the value "var x". This is especially useful when you perform symbolic computations with python (with the sympy module for example). In standard python, the … | |
Just in time for the season, a star. (Playing with my grandson on the Raspberry Pi computer) | |
<?php $height = 100; for ($i=0; $i<$height; $i++){echo str_repeat(' ',($height-$i)).str_repeat('*',$i).'<br />';} ?> May you Daniweb people Grow Like this one. | |
To refresh my mind I did some exercises about complex numbers. I was constantly drawing axes and arrows. So I decided to print out some worksheets with a program to make my life a bit easier, and because it is always fun to design a little program to do that … | |
For a report I had to show a list of items (ID's). Instead of showing them all, they wanted to show consecutive items separated by a dash. Just like the way you would use print pages in Word for example. In the print dialog you can say 1-5, 8 to … | |
I have filled the datagridview on the buttonclick Now, The reuirement is, If the excel having null, or 0 or stringvalue datagridview should eleminate that row. Please suggest. Thanks & Regards Kaustubh | |
it is a simple program but the beuty lies in its shortness it is written in least line as possible By :- Anurag Pareek | |
This is a program I wrote for my x86 assembly class which is basically the Spade Invaders game in all its glory. It uses Irvine32.inc which came with the textbook. | |
This snippets shows how to have fun replacing multiple words in a text. The target words and the replacement words form key:value pairs in a dictionary. The search and replacement is done using Python's regular expression module re. The code also gives an example of a function within a function. | |
An example how to use Tkinter's OptionMenu() as a combobox to allow one year to be selected from an option list of let's say the past 15 years. | |
When using emails as usernames you want them to be unique over your table, but this can be a problem if you consider a GMail account, because of their [username](https://support.google.com/mail/answer/12096?hl=en) [policy](https://support.google.com/mail/answer/10313?hl=en). They allow: * dots * digits * letters * plus addressing text by using the `+` sign, i.e. `orange+juice@gmail.com` … | |
I'm a beginner to Python and I decided to make a permutation finder program. Have fun and don't question the name. :) | |
*Warning: This code is tested, but not as-is. I combined multiple files to simplify the snippet.* One of my specialties is document imaging, and custom tools to handle it. A common request for both scanner sources and file import is correction of when pages are not properly oriented. To avoid … | |
For those of you who are inquisitive, here is a little Python program to approximate the value of pi to 77 digits. You can easily go further, just change the value n in range(n+1). | |
This piece of code is far from perfect, but it works! It produces a list of substrings (consisting of digits and letters) and their delimiters. If it is practicaly a sin to manipulate the index of a for loop, then I'm a sinner. If two delimiters follow each other, an … | |
I am totaly new to C++, and i am trying to get sum of two digits, but i am getting some error, will somebody please correct my code. Regards ![]() | |
This snippet shows you how to animate a dice roll with the Tkinter GUI, useful for many games that require a dice to give a random number from 1 to 6. An interesting use of Tkinter's grid(), grid_forget() and after() functions. | |
It was tinstaafl who put me on the right track. [Click Here](http://www.daniweb.com/software-development/csharp/threads/450463/graph-plotter) I did not know that .NET as of VS 2010 had a charting control! OK, let’s get started! But the learning curve, is as always, a bit steep. MSDN does not seem to provide too much code, so … | |
Draw a group of shapes on the Tkinter GUI toolkit canvas and animate the group using the common tag names. | |
This conception I get from a post on CodeProject by [Heriberto Lugo](http://www.codeproject.com/Tips/837177/Recursion-for-Beginners-Sorting-Ten-Numbers-Withou). But that was for only 10 numbers. Then I had an idea to use it in vb. There are many shorting process like Bubble Short, Linear Short etc. But exceptionally it does not use loops as others do. … | |
The idea for this snippet came from vegaseat, who wrote a very nifty RPN calculator in Python, simulating a switch/case statement, something that Python is missing. See this code on page 19 in the projects for beginners thread on the Python software development forum. In my opinion, he did a … | |
| |
OK I know the DateTime structure is very good at doing this. But if you ever wanted to design your own calendar, or just wanted to know how things are possibly done, this could be a handy function. Enjoy. | |
Using .Net's SHA1 Crypto Service to compare hashes between a user's password and their stored hashed password. Simplez =0) | |
One of the more common functions in any language is conversion of an integer to a string. This implementation, which demonstrates not only the common function activation record format but also a simple recursive function, was written in response to a recent question in which the OP posted an incomplete … | |
Just the very basics on how to draw a rotated text using the Python GUI toolkit PySide (public PyQt). Please experiment and embellish. | |
I was just mucking around with a progress feature for some software, and thought I'd just put this wee demo up of a clocky type progress thing =0) Just Copy and paste the form code and watch it run. (p.s it's in degrees, note minutes and seconds)  | |
first create the table [CODE] create table images ( image_id serial, filename varchar(255) not null, mime_type varchar(255) not null, file_size int not null, file_data longblob not null, primary key (image_id), index (filename) ); [/CODE] the file to output the images to the browser [B]picsrc.php[/B] [CODE]<?PHP //detect if image is called … | |
After trying to manipulate PNG files and failing miserably discovering that the standard GDI doesn't provide support for any PNG parameters decided to provide some basic image manipulation functions built into .Net that I came across on my investigations. 1. Adjust Image Quality 2. Flip Image Horizontally 3. Flip Image … | |
I work with images...a *lot*. Often this involves image processing of various types such as resizing, resampling, and various cleanup operations. However, a common issue is that people like to conflate Adobe PDF with images. As such, any application that works with images should also work with PDF. However, since … | |
Here is a simple way to insert into a database that isn't much harder than using string concatenation - which we all know is very dangerous due to SQL injection attacks. Put the code snippet into `database.php`. Now, in a script handling a form post, such as `post_reply.php`: <?php require_once("database.php"); … ![]() | |
Did you know that you can data bind a bitmap to a PictureBox's image property, and the source image doesn't have to be in a binary format stored in a data table? Using a standard object setup for data binding (iNotify etc.) you can easily update your program's image propertie's … | |
This is just a little example of howto make a Gtk+ application go fullscreen. This is really useful in game programming. Please rate/comment/report errors :icon_mrgreen: | |
Well, start a new forms application from VS. In design mode, drop a DataGridView and a Button on the form and fill in the code. The button clickhandler will add an extra totals row to the datagrid. Here it will keep adding and totaling, which is of course meaningless, but … | |
With the advent of Python33 the module time has received a high resolution timer/counter. Here we use time.perf_counter() in a decorator to conveniently time two test functions. | |
NOTE: The games GUI is not fully implemented, so changing it's image and difficulty is done manually in the Button.Click Event NOTE: Whether you download the VS2013 source file or copy and paste the code, you need to download, and extract the two image files to the project's "Bin\Debug" directory. … | |
![]() | Hi All, Been a bit bored, so went at it to create a class from some long procedural stuff I found littered in various guises all over the web. The code I used as a base for the class came from [here](http://www.codediesel.com/php/downloading-gmail-attachments-using-php/). As this uses IMAP functions and many of … |
String input has changed from Python2's raw_input(prompt) to Python3's input(prompt). The old Python2 numeric input(prompt) has gone away with Python3, all input is now string input. The snippet shows a few lines you can add to your program such that you only need to use input(prompt). This makes your code … | |
>Take Heed There are lots of things to be aware of with the Windows Registry. In most cases the best thing to be aware of is that ideally you should avoid playing with it at all costs. Alas, we are what we are and we do what we do. My … | |
Run two calls to a function simultaneously with this threading @background decorator. | |
I'm currently working on a collection of sub-projects, one of which was a backup manager. I needed to be able to allow the user to specify a backup time and a repeat interval. After thinking about the solution, decided it would be best for the user to provide an Initial … |
The End.