2,322 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
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 …

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 …

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 …

0
191
Member Avatar for tlox

Hello everyone. i have a student database, from which i search a student by entering the student ID at the web interface.Im using a repeater to display search results. Within this repeater i have a link button that should redirect to a page that will display full information about the …

Member Avatar for asemoonabi
0
2K
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.

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 …

Member Avatar for TrustyTony
0
372
Member Avatar for gbertoli3

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

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)

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 …

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 …

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 …

Member Avatar for codeholic
2
1K
Member Avatar for Paladine
Member Avatar for metalix

View the full tutorial at [URL="http://www.effectivewebdesign.co.nz/tutorial.php"]http://www.effectivewebdesign.co.nz/tutorial.php[/URL] I have tested this many times and it works fine. Please don't complain unless you really can't get it working, Just PM me and I'll fill in the blanks Happy Coding :)

Member Avatar for Rogueit
0
885
Member Avatar for Lord Soth

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

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.

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.

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

0
826
Member Avatar for Luckychap

I have seen many beautiful clocks using images and and canvas and flash. So I thought of developing one with pure HTML,CSS3 and javascript, no images at all. This clock can be completely design using CSS. A brief description of Javascript used:- 'AnalogClock' is the name of the class which …

Member Avatar for Luckychap
0
479
Member Avatar for clarence_cool03
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 …

Member Avatar for Rajwin.aravind
0
341
Member Avatar for TrustyTony
Member Avatar for Archenemie
1
707
Member Avatar for ddanbe
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

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

Member Avatar for TrustyTony
0
230
Member Avatar for Luckychap

This is my first step towards HTML5. This is currently tested on Chrome browser where it is awesome. It will not work on FF and definitely not on IE. I am working on it. Just copy-paste the code in blank html file and run on chrome. 'Scroller' is simple menu …

Member Avatar for Luckychap
0
1K
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 …

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 …

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 …

0
447
Member Avatar for CsharpChico
Member Avatar for ddanbe

I find C# very well suited for doing math and all sorts of calculations, so here is an example. Just start a Console application and fill in the code. Have fun! The code also shows a use of delegates and some Console functions. If you don't know what the Newton-Raphson …

0
3K
Member Avatar for samueal

This is the code snippet used to get the files/folder present in a particular folder/sub directories.

Member Avatar for CsharpChico
-1
490
Member Avatar for TrustyTony

There was little buggy version of Python base conversion around, so here quick hack for my own program, including test with random numbers to verify it.

Member Avatar for TrustyTony
0
933
Member Avatar for sandeepparekh9
Member Avatar for CsharpChico
0
278
Member Avatar for sandeepparekh9

Function to Convert Dataset to Excel. It will export all the table of the given dataset to the given excel. Example: [CODE]ExportDatasetToExcel(dsFinal, "d:\\my.xls") [/CODE] where dsFinal is my Datase and second parameter is the excel file location. Make sure the excel file exist.

Member Avatar for Fa3hed
0
1K
Member Avatar for TrustyTony

Lookup table is usually the fastest method to find function value, if number of values is small. Here we demonstrate the principle by using task of showing the value of byte as binary string or transforming binary string to byte binary value.

0
492
Member Avatar for Beat_Slayer

Well, it bothers me to build menus for every shell application that needs one. So, I've written a module to handle that, like in the good old turbo pascal times. :) Here it is, the module comments are pretty explainatory, I think, and the sample usage if run as script …

Member Avatar for Beat_Slayer
0
3K
Member Avatar for iau

I wish it show as unfulfilled:bb,cc extra provided:dd as my conditions and provided strings will be unconstant, anyone can suggest me some ways to do it?

Member Avatar for diafol
0
255
Member Avatar for sandeepparekh9

Listing All The Installed Softwares In Computer Using .Net Don't Forget To add [B]using Microsoft.Win32 [/B] For Complete thread with screen shots see here:[snipped]

Member Avatar for vishalrane
0
184
Member Avatar for MrBlack

[CODE] namespace ConsoleApplication8 { class Program { static void Main(string[] args) { Person p1 = new Student(); p1.Sing(); p1.Run(); Console.WriteLine(p1.GetType().Name); Console.Read(); } } class Person { public void Run() { Console.WriteLine("Person Run"); } public virtual void Sing() { Console.WriteLine("Person Sing"); } } class Student : Person { public void Run() …

Member Avatar for Bridgekeepers
0
281
Member Avatar for kha_tsn

This code is to generate excel with grid lines in it with file name as you given in the code which will disply when you opening throug the download dialog box, Regards, khaleel

Member Avatar for ngabach
0
467
Member Avatar for ManicCW
Member Avatar for uv4u
0
173
Member Avatar for TrustyTony
0
365
Member Avatar for sandeepparekh9

A Function To Concat String Array Values By Specified Delimiter Let 's Say I have Following Array: string[] st = new string[5]; st[0] = "Animation"; st[1] = "Action"; st[2] = "Romance"; st[3] = "Drame"; st[4] = "Comedy"; Now I want to Merge all of it with ',' Delimiter Like Below: …

Member Avatar for maximocn
-1
284
Member Avatar for sandeepparekh9

Listing All The Installed Softwares In Computer Using .Net Don't Forget to add [B]Imports Microsoft.Win32[/B] for complete thread with screen shots check here: [snipped]

0
2K
Member Avatar for sandeepparekh9

A Function To Find Strings Between A Given Word/String For example : let's say you have following Text: Title Author Product* ~~~~~ ~~~~~~ ~~~~~~~~ "Aurora's Eggs" Douglas Niles Story (Dragons 2) The Dragons Douglas Niles Novel The Kinslayer Wars Douglas Niles Novel The Qualinesti Paul B. Thompson Novel & Tonya …

Member Avatar for sandeepparekh9
0
455
Member Avatar for sireesha g

Hi All, I have an xml [CODE] <?xml version="1.0" encoding="UTF-8"?> <columns> <column> <name></name> <displayname></displayname> <attributes> <attribute> <name>width</name> <value>100</value> </attribute> <attribute> <name>text-align</name> <value>left</value> </attribute> </attributes> </column> <column> <name>VersionCode</name> <displayname>Version Code</displayname> <attributes> <attribute> <name>width</name> <value>200</value> </attribute> <attribute> <name>text-align</name> <value>right</value> </attribute> </attributes> </column> <column> <name>MaterialType</name> <displayname>Material Type</displayname> <attributes> <attribute> <name>width</name> <value>100</value> </attribute> <attribute> …

Member Avatar for xml_looser
0
631
Member Avatar for iamthwee

[CODE]// create two new instances of LoadVars, one to send and one to receive data var dataOut:LoadVars = new LoadVars(); var dataIn:LoadVars = new LoadVars(); // define what should happen when the response is received, // using 'this' to refer to dataIn and get data from it dataIn.onLoad = function() …

Member Avatar for iamthwee
0
437
Member Avatar for sandeepparekh9

hi.. You will need Taglib - Sharp Library for this purpose . For Complete understanding and project Download Go to: [snipped]

Member Avatar for katmai539
-1
232
Member Avatar for dx135

You can use a decorator to modify the function object once, by assigning initial values to some new attributes. Then use these attributes as you would use static variables in other languages. Here is the result: (1, 1, [1]) (3, 2, [1, 2]) (6, 6, [1, 2, 3]) (10, 24, …

2
511
Member Avatar for tux4life

I've written a C++ function which converts an integer to a (C++-)string ... [CODE=C++] ... string s = itos(5698); cout << s << endl; /* Will print '5698' on the screen */ ... [/CODE] You MAY use this code for anything you want but [B][COLOR="Red"]you aren't allowed to sell this …

Member Avatar for ztdep
0
1K

The End.