2,322 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for Echo89
Member Avatar for vegaseat

This Python Tkinter GUI toolkit code draws a shape, and shows you when and where the mouse has been clicked within the shape.

2
4K
Member Avatar for vegaseat

There is always room for optimizing primelist functions. Here is an assortment timed with Python module timeit ...

Member Avatar for rubik-pypol
3
396
Member Avatar for Jx_Man

This code to save, Edit and delete data in VB.Net using SQLServer as backend. this code is continuance from my previous post "Show Data in DataGrid with VB.Net 2003 and SQLServer 2000". so i didn't write code how to connect SQLServer 2000 with VB.Net 2003 cause this already in there. …

Member Avatar for anuj6928
1
21K
Member Avatar for Michael27
Member Avatar for chandrabhanu

This program in C finds 2 Longest common subsequence of 2 given strings(say X and Y),entered without any space on the screen individually,altering X and Y strings.I compiled and executed this above program successfully in Dev Cpp compiler as a C file(not a c++ file).

Member Avatar for hahahahohoho
-1
271
Member Avatar for glenwill101

While at work i had nothing to do so i wrote this simple python script that uses the dbm module to store user information its not perfect but im sure someone will find it helpful.

1
237
Member Avatar for Gribouillis

This snippet defines a `dir()` function which extends python's builtin `dir()` function by adding options to filter the returned sequence of strings by the means of regular expressions. The main use case is live inspection of python objects and modules during an interactive session with the python interpreter. The idea …

Member Avatar for TrustyTony
2
502
Member Avatar for TrustyTony
0
519
Member Avatar for vegaseat

I am exploring some of the PySide (PyQT public) widgets like the combo box, and how colors are applied ...

2
2K
Member Avatar for vegaseat

This Python code shows you how to get a current list of currency values (Canadian Dollar = 1.00) via the internet.

Member Avatar for TrustyTony
0
495
Member Avatar for Airshow

Tablesorter (currently v2.0.5) includes an "update" method. This method keeps a Tablesorter object up to date with dynamic changes made to its table(s). Like other Tablesorter methods "update" is implemented in the form of a custom event. A typical method call would be $table.trigger("update"); , where $table is a jQuery …

Member Avatar for punknroll
0
822
Member Avatar for pritaeas

Below is a documented code example showing how to use the [PDO](http://php.net/pdo) classes/objects to connect and query your database (and check for errors). If there are any questions, or you want to see different features, let me know. UPDATE: I've encountered a problem with PDO and bit fields (MySQL). If …

Member Avatar for sammry
2
3K
Member Avatar for Gribouillis

This snippet allows one to implement an equivalent of a `__getattr__()` function in a python module. The module can then define its own way to lazily import abitrary symbols. For example the module can contain infinitely many names or load values from other modules on demand. There are many implementations …

Member Avatar for Gribouillis
1
531
Member Avatar for bflack

This snippet could be a problem solver for a tricky programing problem in entrance exams. Hoping that this has no buggs. haha. Didn't use compiler for this

Member Avatar for SoreComet
0
4K
Member Avatar for pritaeas

Below is a documented code example showing how to use the [MySQLi](http://php.net/manual/en/book.mysqli.php) (MySQL improved) classes/objects to connect and query your database (and check for errors). If there are any questions, or you want to see different features, let me know.

5
4K
Member Avatar for pritaeas

Below is a documented code example showing how to use the [MySQL functions](http://php.net/manual/en/book.mysql.php) to connect and query your database (and check for errors). Please note that using the MySQL extension is **NOT RECOMMENDED**. This extension is no longer maintained and will be deprecated soon. If you want your scripts to …

3
865
Member Avatar for Troy III

# This is a simple HTML String Sanitizing tool. # ## It allows a highly rich,- but safe - html content input to be published on your pages. ## **The script code is very light and to some degree customizable.** * This function takes care of blacklisted tags, which are …

Member Avatar for Troy III
2
274
Member Avatar for tux4life

A program which displays the prime factors of a given number, all the 'hard' work is done by the [B]factorize()[/B] function: [CODE=c] /* Find out the prime factors * of a given number and print * them on the screen */ void factorize(int n) { int d = 2; if(n …

Member Avatar for delta_frost
0
796
Member Avatar for vegaseat

The Tkinter library folder \lib-tk contains a module called turtle. You can import this module and experiment with turtle graphics. Tell the turtle to move and draw circles, lines, rectangles and more, and watch it, as it performs on a Tkinter canvas. In typical turtle fashion it moves at its …

Member Avatar for woooee
0
2K
Member Avatar for deceptikon

Encoding and decoding functions for RFC 4648 compliant base-64. The code is written in standard conforming C11 and backward compatible with C99 (pre-C99 is *not* supported without code changes).

Member Avatar for deceptikon
0
345
Member Avatar for felgall

JavaScript doesn't actually have a sleep() function corresponding to what is available in other languages. We can easily implement one though. The following code uses afunc as an example function where we want to be able to have the code sleep for a number of milliseconds between sections of code. …

Member Avatar for Troy III
0
367
Member Avatar for Troy III
Member Avatar for Troy III

With this *Spartan*, we can destructively disable all the links on the page. (Or whatever link collection we feed the Fn.arg.)

Member Avatar for Troy3
0
185
Member Avatar for D33wakar

This is a simple hangman game that I wrote using my beginner python skills. Though this game is playable, there must be lots of things I must've been doing wrong or the methods I'm using here may be not so pythonic. So I want some suggestions on how to improve …

Member Avatar for TrustyTony
1
713
Member Avatar for srm2010

Here I am Sending you my code ,wherein I want to have total of examfees(column),PromotionFees(column),Totalfees(column) and Balance(column).Examfees are paid in installment in my project The idea if single record is found then it doing calculation of balance=promotionfees-totlafees and if anywhere due to mistyping is value is higher then the respectively …

0
441
Member Avatar for TrustyTony

Here is slow brute force way to find the largest palindromic product of three digit integers. You could do loop and break out of it if you go under the smaller number (the second one) of best solution found so far to be more efficient etc.

Member Avatar for hughesadam_87
0
558
Member Avatar for Lucaci Andrew

Ok, so, this code snippet is a reply to this thread: http://www.daniweb.com/software-development/cpp/threads/425821/prime-number-c From what I understood form the OPs request, is that, he wanted an algorihm which would check for prime numbers in a given range, applying these conditions: a number is to be considered valid if: a. the number …

Member Avatar for RainbowMatrix
0
602
Member Avatar for vegaseat

Just a few more explorations using a Python class to mimic a C Structure or Pascal Record. Loading the record from a csv type data file, displaying the data and sorting and searching the data in various ways.

Member Avatar for hughesadam_87
3
366
Member Avatar for raj26061990

Eg.407 4*4*4=64 0*0*0=0 7*7*7=343 now 64+0+343=407. Any number which satisfies the above condition is called as Armstrong

Member Avatar for vinnitro
1
512
Member Avatar for np complete

What is it : A simple logic (text based) game, in which you are required to identify the counterfeit coin within 3 chances. How it works : You are given 'x' coins ( best is to play it with 12 coins ). You are asked how many coins you want …

Member Avatar for WaltP
0
361
Member Avatar for vegaseat

Just a simple text editor using the Tkinter expansion TIX. You are encouraged to improve this program with added functions. TIX is included with the latest Python distributions.

Member Avatar for Lardmeister
2
2K
Member Avatar for Bumpehh

This is a very simple Rock Paper scissors game i made. i showed it to my cousin and he played it for like 20 mins lol. Its against an AI and you pick by number, not words.

Member Avatar for m4ster_r0shi
0
1K
Member Avatar for Banderson
Member Avatar for vckicks

Use regular expressions, regex, to create an efficient textbox that only takes in digits as input.

Member Avatar for Chatthanz
1
847
Member Avatar for TrustyTony

There was discussion thread http://www.daniweb.com/software-development/python/threads/424953/polynomial-division for class based implementation for polynomials, and I developed a version utilizing the magic methods to enable operation with normal arithmetic operation. I only inherited sequence structure from list type. Interoperability with scalar types is not implemented to avoid too complicated type checks of the …

Member Avatar for TrustyTony
1
1K
Member Avatar for Reverend Jim

This is a short bit of code that shows how to implement sorting on columns in a details-mode ListView. Suggestions for improvement are always welcome. One possible improvement would be to modify the column headers to indicate which column is being sorted and in which direction.

0
2K
Member Avatar for Graphix

Hello everyone, I stumbled upon a video about the monty hall problem, which I found very well explained, and a lot of comments below the video that were against the conclusion that it **is better to switch**. To clarify, I wrote this small program that simulates the game and allows …

Member Avatar for WaltP
0
651
Member Avatar for hughesadam_87

This post is a followup to an older dicsussion [on recordmanaging](http://www.daniweb.com/software-development/python/code/429753/custom-named-tuples-for-record-storage). I am writing this to share with colleagues, so it may be a bit fluffy and not straight to the point. I apologize to all the experts. Good programs always start by managing data in a flexible and robust …

0
576
Member Avatar for lxXTaCoXxl

These are just some of the more useful #define statements I've used in C++. These are some of the statements you'll use the most (in the case of template<typename T> when you use it, you use it a lot!). So I figured I'd post it for others, even though a …

Member Avatar for sepp2k
-4
271
Member Avatar for pritaeas

In addition to [my post in this thread](http://www.daniweb.com/web-development/php/threads/429740/php-best-practice#post1841569) I've decided to post an extended example, which also implements functions for inserts and updates. I hope the code is straightforward enough. If not, reply and let me know. The table structure I've used for my test is the following: CREATE TABLE …

Member Avatar for extjac
4
453
Member Avatar for hughesadam_87

This code was inspired after several discussions on the forum, and I'm especially indebted to PyTony for all of his help with these aspects. The motivation behind this code is quite simple. I wanted a robust, light and general way of storing CSV data that could be used over and …

Member Avatar for TrustyTony
2
537
Member Avatar for Reverend Jim

Sometimes sorting data can be easy and sometimes it can be difficult. If you have data in a listview you can spend a great deal of time writing ICompare functions. This is appropriate for non-trivial applications but can be a little intimidating for inexperienced programmers. Also, it is a problem …

Member Avatar for Reverend Jim
1
892
Member Avatar for chriswelborn

This is a piece of code I wrote a long time ago when I saw someone make a "guess this scrambled word" game. The program didn't have to unscramble the word to know what the answer was, but I wanted to do it anyways. I wanted an algorithm that could …

Member Avatar for Reverend Jim
0
1K
Member Avatar for Graphix

Hey everybody, Lately I have written the game Hangman in many different languages (C, JavaScript, Java and PHP so far). Here is the code snippet for JavaScript! It uses a words file, on the bottom of this post you will see a small example of a few words. The source …

Member Avatar for rotten69
-1
2K
Member Avatar for vegaseat

You have to mildly trick Windows, but it is possible to put a bitmap image on your console. Uses a flock of WinApi calls. Works well with the free PellesC compiler and Dev-C++. This is a Windows Console Application. Drop me a comment, if you have luck with another compiler.

Member Avatar for I_m_rude
2
10K
Member Avatar for tux4life

This is how mine [B]strcmp[/B] function would look like if I'd to implement it from scratch :)

Member Avatar for ibykow
0
699
Member Avatar for ReDuX

This is a very simple statistics script that provides for services on/offline, memory info, server load averages and uptime and lastly drive info. Its easily customised and i have usef <font> alot where you could have set come css and have it all done easily and look a bit more …

Member Avatar for ReDuX
0
172
Member Avatar for vegaseat

The computer is a binary beast. We want to go from the one-fingered digital box to the ten-fingered human being and convert binary to denary(base 10) numbers. This is how it works, for instance, binary 10010 is calculated as 1*16+0*8+0*4+1*2+0*1 = decimal 18. Just because it's easy, let's throw in …

Member Avatar for soorajshaji
0
2K
Member Avatar for lil_bit

Hi. Here is a simple beginners program. It uses "if_else" and returns no information. After execution, it deletes files within the same directory as the exe. Enjoy.

Member Avatar for mrnutty
0
211

The End.