1,916 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for TrustyTony

Roman numbers is a standard programming exercise, to give it a small twist, we input roman numeral, turn it to value and prepare minimal version of it using the substraction rule. Correctness of the input is not checked so Garbage in - Garbage out.

Software Development mathematics python
0
338
Member Avatar for TrustyTony

While looking stuff about idlelib, I came to [URL="http://stackoverflow.com/questions/3431498/what-code-can-i-use-to-check-if-python-is-running-in-idle"]this thread in stackoverflow[/URL], so I posted own solution. I post it also here, as maybe somebody needs it (as for example \b looks ugly in IDLE)

Software Development python
0
259
Member Avatar for peter_budo

Sometimes one line of tool tip is not enough. You may want to try and play around with JToolTip, but if you in hurry this "little hack" can be handy. With little of HTML plus CSS code you can work out various formats (font, colour, alignment, size etc.).

Software Development html-css java
Member Avatar for peter_budo
2
508
Member Avatar for masterofpuppets

This is my first GUI program in Java. If finds the day of the week for any given date which is after 1 January 1900.

Software Development gui java
Member Avatar for glen dc1
1
822
Member Avatar for TrustyTony

Picked up from old thread but currently applicable (the IBAN number became more widely required actually this year in Finland). The style was quite alien for modern Python coders, so I massaged the code to my own liking. I removed many temporary variables, as for my opinion they did not …

Software Development python
Member Avatar for TrustyTony
2
416
Member Avatar for TrustyTony

By coding algorithm and using some liberal prints with small set of data, you can learn to understand the basic algorithms better than just reading about them. Here simple selection sort.

Software Development python
Member Avatar for TrustyTony
0
218
Member Avatar for Reverend Jim

I wrote this 3D Breakout game as a sample project to learn both Python and the visual module, vPython. It is based on a similar game I had on my Amiga back in the 80s. I don't expect that my Python is either standard or as elegant as it could …

Software Development gaming image python
Member Avatar for Reverend Jim
0
499
Member Avatar for TrustyTony

Very trivial program which could be thought as conclusion from the Quiz posts (thanks Gribouillis for inspiration for format)

Software Development python
Member Avatar for TrustyTony
0
195
Member Avatar for hondros

Alright , so I spent _forever_ trying to figure this out. So, if any newbies here need to know how to write and read ANY object (with the exclusion of pointers, but I'll get to that), this is something that can help. First and foremost, you have to take endianness …

Software Development c++
Member Avatar for mike_2000_17
0
369
Member Avatar for TrustyTony

There was question about encryption in Delphi/Pascal forum and a guy was suggested reversing the bits as additional step (I do not know if he in reality meant XOR 255, that is making 0's 1's and vice versa). As it keeps still same distribution of letters I suggested as better …

Software Development delphi encryption pascal python
0
634
Member Avatar for TrustyTony

Dig up this for discussion thread request and some Googling. By little experiment found the different forms for sending message commands. Could no send in Python3 the code of program itself so only simple test "Hello". Sorry that subject is left incorrectly refering program name.

Software Development email python
Member Avatar for JoshuaBurleson
3
2K
Member Avatar for Diamonddrake

This simple static class contains a static method called sOnline that accepts a username as a string param. it make a call to an old yahoo api that will determine if a Y! user is online. This only returns true if the user is not using stealth, this will return …

Software Development api
Member Avatar for miladar91
0
381
Member Avatar for TrustyTony

Here is example how data can be summed to dictionary or you can use numpy.histogram to sum the data as weights of the categorized data.

Software Development python
Member Avatar for Stackheuw
2
2K
Member Avatar for TrustyTony

I finally modernized this code. It is very primitive, but it is nice to have basic version, even it does a lot of mistakes. You could add features, like repetition elimination, or you can check the compete chatbot: [url]http://www.jezuk.co.uk/cgi-bin/view/software/whereskal[/url].

Software Development artificial-intelligence-llm python
Member Avatar for TrustyTony
0
942
Member Avatar for TrustyTony

I was not happy of solution [url]http://chaos.weblogs.us/archives/331[/url] for one line Ceasar cipher, so I wrote my own version without import by using raw_input (change to input for Python3). Chance to play little with memoryview object also. Crypt: give displacement amount for shift Decrypt: give -displacement amount shift

Software Development encryption python
Member Avatar for TrustyTony
0
420
Member Avatar for Bench

This code snippet outlines a simple, no-frills linked list. Tested under MSVC++ 2003 and Comeau, but not guaranteed bug free. Snippet includes example main() . This snippet is intended as an example of a possible implementation of a linked list class (Of which there are many variations) For a better …

Software Development c++ linked-list
Member Avatar for Narue
0
3K
Member Avatar for TrustyTony

Again "pseudo-code" for [URL="http://www.daniweb.com/software-development/cpp/threads/379255/1632559#post1632559"]C++ program[/URL]. Quite primitive and simple, but I post it anyway. Generalized to take even even number as parameter.

Software Development python
0
132
Member Avatar for ddanbe

What polar coordinates are is explained [url=http://en.wikipedia.org/wiki/Polar_coordinate_system]here[/url]. I wanted to draw some polar functions myself, so I changed my [url=http://www.daniweb.com/software-development/csharp/code/217204]plotting class [/url] a bit and added a polar struct to a new project.. Just posted code for the Plot class and the polar point structure here. You can find an …

Software Development c# mathematics
2
1K
Member Avatar for TrustyTony

Here is simple math program to list number whose all factors are in given set of factors. I have included my timing decorator, which uses my timestring function, so I included that and imports for decorator in the decorator function, bit against the rules. Of course I could have used …

Software Development algorithm python
0
274
Member Avatar for ddanbe

Although [url=http://en.wikipedia.org/wiki/Roman_numerals]roman numerals[/url] sneak in our lives from time to time, we(luckily) don't use them very often. Probably the reason why the Romans where not that good at calculating things. That changed, more than 1000 years later, with [url=http://en.wikipedia.org/wiki/Fibonacci]this person[/url] who introduced to the Western world the number system we …

Software Development
Member Avatar for gracefull
0
1K
Member Avatar for sandeepparekh9

hi.. i just made two function related to excel . 1. Merging all sheet of excel as tables in single Dataset 2. Exporting a dataset to Excel File .(all the tables of dataset as sheets) i just wanted to share.. i hope it becomes helpful to you. ps: Dont forget …

Software Development dataset microsoft-office vb.net
Member Avatar for sandeepparekh9
0
542
Member Avatar for caut_baia

Hi.Someone asked a day or two ago for a way to extract the square root of a number without using the std::sqrt function so i thought about writing my own.Here it is and please feel free to criticize.

Software Development c++
Member Avatar for maninaction
0
417
Member Avatar for Ene Uran

Just a simple console blackjack game. The bread and butter code was written with lots of comments, so you can improve on it. Really, the most important part is figuring out when an ace is 11 in value and when it is a 1 in value, so you don't bust.

Software Development python
Member Avatar for s4bb4t
1
8K
Member Avatar for TrustyTony

As [URL="http://www.daniweb.com/software-development/c/threads/377568/1625821#post1625821"]Goddess Narues' C code in C forum[/URL] was over my head and her critique of simplistic solution maybe overflowing the integer range was valid in C, I worked out a recursive solution more suitable to my brain in my preferable language. Maybe one day I put in C, now …

Software Development mathematics python
0
271
Member Avatar for ptaylor965
Member Avatar for aniketcool
1
8K
Member Avatar for Gribouillis

How to create a png image containing a fragment of source code ? Well, don't do it yourself, the [url=http://pygments.org]pygments module[/url] contains all the necessary tools. The example below shows how to produce a png image from python code, but pygments supports lexers for many other languages and its formatter …

Software Development image python
1
517
Member Avatar for ddanbe

I saw a thread lately on this site to rotate an integer. Seemed like a fun project to do. There are probably more efficient solutions out there but this is mine, and indeed it was fun! It is mostly a demo on how you could use the less known shift …

Software Development c#
Member Avatar for kel634
0
2K
Member Avatar for Purkinje

[url=http://www.daniweb.com/software-development/python/threads/375271/1621485#post1621485]Sample code credited to Enalicho[/url] In this example, we count the number of appearances of the number 1 through a range of pages using while loops. First off, notice how easy it is to tell what the variables in this method are doing. I did not write this method, but …

Software Development python
0
191
Member Avatar for Gribouillis

A functor, or function object is sometimes a convenient way to encapsulate helper functions and data needed to achieve a small task, and also to share data between calls to the same function. This snippet defines a base class [b]functor[/b] which permits an easy functor creation for python 2.

Software Development python
Member Avatar for TrustyTony
2
724
Member Avatar for TrustyTony

Inspired by Computer Science forum post, I did this code. I prepared it Shedskin compatible, and it runs quite nicely indeed. Even interpreted the algorithm is faster than full sort. Here interpreted test for the module, shedskinning this test would show better time for sort solution. Python version has benefit …

Software Development algorithm python
Member Avatar for TrustyTony
0
372
Member Avatar for gbertoli3

Play any Sound File. Just add a reference to Microsoft.DirectX.AudioVideoPlayback(COM)

Software Development
Member Avatar for Fifth Horseman
0
796
Member Avatar for alex_extreme

Gets the names of all the partitions in a system. Note that media must be in every removable drive for this to work (can be fixed easily)

Software Development visual-basic
Member Avatar for Mark A
0
182
Member Avatar for Gribouillis

This snippet defines a context [icode]autofilename()[/icode] to create an existing temporary file with a new name in python. Unlike the methods in the [icode]tempfile[/icode] module, it only gives a filename which exists within a 'with' block, instead of an open file. This is useful for example when a program needs …

Software Development python
Member Avatar for Gribouillis
1
302
Member Avatar for TrustyTony

Here is Mandelbrot set viewer in Tkinter and modules for shedskining (included compiled modules for windows in the zip file): [CODE]# mandelsh.py def mandel(real, imag, max_iterations=20): '''determines if a point is in the Mandelbrot set based on deciding if, after a maximum allowed number of iterations, the absolute value of …

Software Development python tkinter
Member Avatar for TrustyTony
0
2K
Member Avatar for Momerath

As a companion article to my [URL="http://www.daniweb.com/code/snippet349081.html"]Permutation Generation[/URL], I now present Combination generation. This snippet will do a lazy generation of the combinations of a set of objects. Each combination has a grouping size (number of items in each combination). If you need a different grouping size, you'll have to …

Software Development
Member Avatar for codeholic
2
1K
Member Avatar for Paladine
Member Avatar for Lord Soth

ShowDriveSerialNo shows it with ShowMessage GetDriveSerialNo returns a string. You don't need both.

Software Development pascal
Member Avatar for hingman
1
1K
Member Avatar for TrustyTony

This does not look very efficient with transponation, sort and transponation back, so I am happy to hear about better alternatives.

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

Another task from C++ forum is trivial in Python even taking handicap of not using Counter.

Software Development python
0
525
Member Avatar for TrustyTony

My not OO version of timer for work and pause time (but it does use attributes for functions, which are objects, to avoid global declarations in functions).

Software Development python tkinter
0
826
Member Avatar for clarence_cool03

{-='Smallest, Largest & Sum of 5 numbers using Dev-C LaNGuaGe'=-}

Software Development c
Member Avatar for arindam31
0
3K
Member Avatar for sknake

I wanted to export a list of all email addresses I had corresponded with and was unable to find a free product to compile the list so I came up with this. You could take it a step further and scrape additional email addresses from the message body. As far …

Software Development email
Member Avatar for Rajwin.aravind
0
341
Member Avatar for TrustyTony

Another quick code over breakfast inspired by 'spying' the other forums.

Software Development python
Member Avatar for Archenemie
1
707
Member Avatar for ddanbe

Short piece of code to add a "menu" to your Console application.

Software Development
2
5K
Member Avatar for K0ns3rv

A little program I made to try and remeber C++, first program I've written in C++ in about a year. Tested and working under windows 7 64 bit, run via command line. If you have any improvements or ideas please leave a comment. Cheers K0ns3rv

Software Development c++ mathematics
Member Avatar for mrnutty
1
323
Member Avatar for TrustyTony

Next quiz is posted as code snippet. It is quite interesting code. What it does? And where [B]in your system[/B] you already have this code? (in little different format) (If you have not follow tip in page [url]http://python.org/download/[/url])

Software Development python
Member Avatar for TrustyTony
0
230
Member Avatar for sandeepparekh9

Lets say you have lots of data your listview. Now you want to Group This data According to a Perticular Subitems. For Example: Suppose i have some books data in my ListView. this listview items contains Author name and Books Title. And there are 2000 Books in list view. Now …

Software Development listview
0
291
Member Avatar for vegaseat

One more application of the Python Image Library (PIL). This short code creates thumbnails from all JPEG files in the current folder. The thumbnail image file is prefixed with a T_ and saved to the same directory. The program checks for existing files with this prefix, so we don't create …

Software Development image python
Member Avatar for thenate
1
2K
Member Avatar for TrustyTony

The code demonstrates running program limitted time by following going over endtime expressed in seconds since midnight, so might fail for playing just midnight (add check that endtime is less than 24*60*60 if you want to be sure). Exciting action :) of the program is that it shows remaining time …

Software Development pascal
0
447
Member Avatar for CsharpChico

A Simple method to create a short url using google

Software Development google
0
174

The End.