2,322 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for vegaseat

Using the Python win32 extensions it is relatively simple to copy to and from the clipboard. Sorry. the Windows OS is a requirement.

0
2K
Member Avatar for vegaseat

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 …

Member Avatar for vegaseat
2
3K
Member Avatar for sneekula

You can accesss the clipboard simply by using the Tkinter GUI toolkit that comes with your Python installation.

Member Avatar for TrustyTony
1
14K
Member Avatar for xrjf

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.

Member Avatar for xrjf
0
569
Member Avatar for vegaseat

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.

Member Avatar for Babe1
3
1K
Member Avatar for vegaseat
Member Avatar for vckicks

The .Net Framework uses by default radians in its trigonometry calculations. Find out how to convert degrees to radians to use with C#

Member Avatar for ddanbe
1
722
Member Avatar for vegaseat
Member Avatar for vegaseat

If you draw a series of close spaced shapes your eyes get fooled to see Moire patterns. Here is one example of this.

2
2K
Member Avatar for Gribouillis

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 …

Member Avatar for Gribouillis
0
446
Member Avatar for vegaseat
Member Avatar for sneekula
1
5K
Member Avatar for imti321

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

Member Avatar for imti321
0
273
Member Avatar for ddanbe

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 …

2
256
Member Avatar for pritaeas

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 …

Member Avatar for pritaeas
0
1K
Member Avatar for kau14

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

Member Avatar for SteveDotNet
0
225
Member Avatar for anurag_pareek

it is a simple program but the beuty lies in its shortness it is written in least line as possible By :- Anurag Pareek

Member Avatar for Indra_1
0
236
Member Avatar for Dani

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.

Member Avatar for Dani
2
2K
Member Avatar for vegaseat

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.

Member Avatar for Gribouillis
0
20K
Member Avatar for vegaseat

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.

2
1K
Member Avatar for cereal

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

Member Avatar for cereal
2
663
Member Avatar for matrixdevuk

I'm a beginner to Python and I decided to make a permutation finder program. Have fun and don't question the name. :)

Member Avatar for matrixdevuk
0
187
Member Avatar for deceptikon

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

0
2K
Member Avatar for vegaseat

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

Member Avatar for sneekula
0
3K
Member Avatar for ddanbe

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 …

Member Avatar for xrjf
0
1K
Member Avatar for justzamir

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

Member Avatar for jencas
1
338
Member Avatar for vegaseat

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.

Member Avatar for Jake_6
0
4K
Member Avatar for ddanbe

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 …

Member Avatar for ddanbe
0
3K
Member Avatar for sneekula

Draw a group of shapes on the Tkinter GUI toolkit canvas and animate the group using the common tag names.

1
5K
Member Avatar for Santanu.Das

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

Member Avatar for David_50
0
525
Member Avatar for ddanbe

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 …

Member Avatar for xrjf
1
539
Member Avatar for harshchandra
Member Avatar for ddanbe

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.

Member Avatar for xrjf
0
2K
Member Avatar for J.C. SolvoTerra

Using .Net's SHA1 Crypto Service to compare hashes between a user's password and their stored hashed password. Simplez =0)

0
868
Member Avatar for Schol-R-LEA

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 …

Member Avatar for Kiệt
0
7K
Member Avatar for vegaseat

Just the very basics on how to draw a rotated text using the Python GUI toolkit PySide (public PyQt). Please experiment and embellish.

Member Avatar for vegaseat
2
2K
Member Avatar for J.C. SolvoTerra

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) ![55f1addda67a729e91ae90c980c39deb](/attachments/small/4/55f1addda67a729e91ae90c980c39deb.png)

Member Avatar for J.C. SolvoTerra
0
255
Member Avatar for metalix

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 …

Member Avatar for guruparthi
0
1K
Member Avatar for J.C. SolvoTerra

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 …

Member Avatar for Santanu.Das
1
2K
Member Avatar for deceptikon

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 …

Member Avatar for deceptikon
2
1K
Member Avatar for Isaac_4

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"); …

Member Avatar for diafol
4
508
Member Avatar for J.C. SolvoTerra

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 …

0
1K
Member Avatar for athlon32

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:

Member Avatar for Stefan_4
0
3K
Member Avatar for ddanbe

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 …

Member Avatar for ddanbe
0
2K
Member Avatar for vegaseat

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.

3
2K
Member Avatar for J.C. SolvoTerra

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

Member Avatar for J.C. SolvoTerra
1
324
Member Avatar for diafol

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 …

4
3K
Member Avatar for Lardmeister

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 …

Member Avatar for vegaseat
2
222
Member Avatar for J.C. SolvoTerra

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

0
1K
Member Avatar for vegaseat
Member Avatar for J.C. SolvoTerra

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 …

Member Avatar for J.C. SolvoTerra
1
693

The End.