2,322 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for Jaks_maths
Member Avatar for raghuram1987
0
339
Member Avatar for TrustyTony

This function I did to improve calculator program by eliminating problems with Pythons problem of dividing integer with integer and giving integer division result.

Member Avatar for TrustyTony
0
405
Member Avatar for vegaseat

A short look at creating lists of file names or full path names using the versatile Python module glob. Glob follows the standard wildcard protocol.

1
3K
Member Avatar for Ntsoaki

Hi i am new at python,i am getting problem in the above code,the problem reads as follows: Having several accounts on several servers, one has to remember many passwords. You can imagine a situation where someone forgets one of them and he or she only remembers that it consisted of …

-1
337
Member Avatar for _Nestor

This is a text based solitaire game I wrote. It tested it on Ubuntu Linux and Windows and it worked okay for me. Move cards between rows using their row number (7 for the deck) Let me know what people think. Critiques welcome..... don't be too harsh ;)

Member Avatar for _Nestor
0
4K
Member Avatar for spacerat

The other code snipplets I found were either recursive or too complex. I therefore developed a simple, fast and yet non-recursive method; thats useful especially when working on the graphics card with CUDA as recursion is not possible there. (c) Sven Forstmann

Member Avatar for chtulu
1
649
Member Avatar for TrustyTony

Here tool functions, which came up during discussions earlier. Expanded slightly, added elimination of traceback prints by try..except. Added dd.mm.yy routine as that is format in my home country Finland. Optimized docstring beginnings to be informative in editor tooltip (at least IDLE shows, but code must be run or imported …

Member Avatar for TrustyTony
1
976
Member Avatar for ReDuX

Do you work with datasheets regularly ? Always getting .pdf files open in your browser and having to wait EONs for them to download/display ? Well here is a resolve for that most frustrating of problems with Adobe's "Handy file intercept" feature. Use this script to FORCE the browser to …

Member Avatar for w3m
0
156
Member Avatar for msaqib

This is an automated system for Bank Management. It uses files to handle the daily transactions, account management and user management. Nice graphical layout and mouse functionality. Manager can add, edit and delete the users and manage the user accounts. Code From: <URL SNIPPED>

Member Avatar for jephthah
-2
318
Member Avatar for TrustyTony
Member Avatar for peter_budo

In my current project we need to provide drag&drop functionality of items from left to right and vice-versa and on click of the button send array of item IDs to server. Main problem was that we couldn't get array across to server and online examples that we found did not …

2
908
Member Avatar for ddanbe

Drawing on a Form does not always happen when you want it. The Refresh() method of a control comes in handy here. See the following snippet and experiment by commenting out the Refresh. Start a new WindowsForm project. From the toolbox, add a Label, ProgressBar and Button control on the …

Member Avatar for g2gayan
1
3K
Member Avatar for William Hemsworth
Member Avatar for William Hemsworth
1
3K
Member Avatar for jcao219

Most people would do something like this: [icode]input("Press any key to continue") #or raw_input[/icode] This way, if the user presses a key other than the Enter (return) key, then the program will still continue. It looks something like this: [URL="http://i42.tinypic.com/2yvp9hj.png"]http://i42.tinypic.com/2yvp9hj.png[/URL]

0
220
Member Avatar for mister-fett

Since no one has posted in this forum as of yet, I decided to tap out a quick scheme. This program, when run through the Mr Ed part of dr scheme available from [url]www.drscheme.org[/url] , will cause a window to pop up with text and a button. By clicking the …

Member Avatar for Rashakil Fol
-1
306
Member Avatar for Diamonddrake

This simple class encapsulates the exAnimatewindow api call. I got tired of adding all the jazz to every form I need to use as a pop up, or any borderless forms I used. (Windows 7 and vista don't animate windows with no border by default) This class could easily be …

1
255
Member Avatar for vegaseat

Looking at the First In First Out (FIFO) data situation. Just like a line at the grocery store check-out. Its counterpart FILO would be like a stack of dinner plates.

Member Avatar for mitrmkar
2
234
Member Avatar for cwarn23

Hi, I have made an encryption and decryption script for those who want to encode data and decode the encoded data. This script may especially be useful for those who do not have the mbstring library installed as it uses a math grid. So for example you can store the …

0
340
Member Avatar for codiction

This particular snippet will display a chessboard in a new frame. Needless to say save it in a file named "chessboard.java".

Member Avatar for mundvawala
0
1K
Member Avatar for Daaave

This snippet shows how to open, read, write and close text files. This skeleton can be modified to handle any type of file, from untyped to text to typed files.

Member Avatar for Deffcon
0
482
Member Avatar for Comatose

Swaps Two Elements Of An Array (So that say, indice1's value would become indice2's value, and vice versa). Simple Code Piece Really...

Member Avatar for vb5prgrmr
0
259
Member Avatar for vegaseat

A demo of the Tkinter listbox widget that shows you how to create the listbox, make it scrollable, position it within a grid, load it with data from a file, select a line of data with the mouse and display it. Also, sort the lines, add a line, delete a …

Member Avatar for Tcll
3
15K
Member Avatar for shahzadhard

Imports System.Data Imports System.Data.SqlClient Public Class Form2 Dim myconnection As SqlConnection Dim mycommand As SqlCommand Dim dr As SqlDataReader Dim dr1 As SqlDataReader Dim ra As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click myconnection = New SqlConnection("server=Pakistan;Initial Catalog=Mumtaz;database=Mumtaz") myconnection.Open() mycommand = New SqlCommand("insert into …

Member Avatar for nevintom26
0
427
Member Avatar for Tech B

My friend gave me 10,000+ ROM's for Sega, SNES, NES, and GBA. They where all individually zipped. I go fed up trying to unzip them one by one, and decided to write a script to do it for me. It unzipped about 5,000 in under a minute. Python's zipfile module …

Member Avatar for Tech B
0
623
Member Avatar for realone

Hello All, Can anybody help me, i am having challenges getting collections value into the database Here is my sample code. but is not working at all rather is crashing the applications Dim collections As New System.Enrolment.CustomerBiometricsCollection() collections = Me.PrintCaptureWizard1.ShowDialog() Dim dbs As New DBClass Dim mee As String mee …

0
137
Member Avatar for hondros

This is a nice command prompt I wrote up a month ago. It's still in the Beta stages however. Anyways, here's a brief overlay of what it does: 1) Takes user input of a function, creates an x/y table and plots it 2) Change the x-range 3) Graph waves (Main …

Member Avatar for hondros
0
222
Member Avatar for ddanbe

There seems to be a lot of shuffling going around here lately. So I looked [url=http://en.wikipedia.org/wiki/Shuffling]here[/url] to learn about the Fisher-Yates shuffle etc. But unless my English is not good enough I did not find anything about the way we shuffle a card deck here. Take a deck in your …

Member Avatar for ddanbe
2
781
Member Avatar for vegaseat

We take a look at the various functions of module time, counting seconds and milliseconds, measuring the time a simple for-loop takes, inspect a list of time data and ways to display it in a useful manner. An attempt is made to find the day of the week, given a …

Member Avatar for Kanem
2
2K
Member Avatar for apegram

[CODE] int[][] jaggedArray = (from line in File.ReadAllLines(fileName).Skip(1) select (from item in line.Split('\t').Skip(1) select int.Parse(item)).ToArray()).ToArray(); [/CODE] This is a crazy example. It was sparked by what is probably a homework thread on another forum here, but it is basically reading in a tab-delimitted text file, stripping out the first row …

Member Avatar for ddanbe
3
700
Member Avatar for cwarn23

Hi and this function I wrote as part of a larger project and acts exactly like the php explode function. Although there a few slight differences between this function and the php explode function it can easily be tweaked to act identical. Also with this function it does not use …

Member Avatar for tetron
1
677
Member Avatar for Tech B

I used [URL="http://www.parallax.com/Store/Education/KitsandBoards/tabid/182/CategoryID/67/List/0/SortField/0/Level/a/ProductID/313/Default.aspx"]Parallax's Basic Stamp Homework Board[/URL] and an [URL="http://www.radioshack.com/product/index.jsp?productId=2909788"]accelerometer[/URL] to use as a mouse. It works better than I thought it would. [URL="http://sourceforge.net/projects/pyserial/"]PySerial[/URL] is used to grab the debugged values from the stamp. The circuit is compiled of two push buttons, 2 LEDs to tell when a button is …

0
275
Member Avatar for emanicom

The top code is my Loop for the mortgage program. The second code is my Array list for the Mortgage program. Is there a way to combine the 2 to do the following:* Use an array for the different loans. Display the mortgage payment amount for each loan. Then, list …

Member Avatar for emanicom
0
185
Member Avatar for Gribouillis

This snippet defines a class LebsegueSet which instances represent sets of real numbers, namely finite unions of intervals. Set theoretical, topological and measure theoretical operations are implemented in pure python. Use freely and enjoy !

1
257
Member Avatar for Comatose

Another Small And Simple Function To Take Each Character of a string, and put it into an Array, This helps significantly when you need to sift through a string. This Function Uses The spush (String Push) Function, Also In Code Snippits.

Member Avatar for jfc2k4
-2
913
Member Avatar for YoungCoder
Member Avatar for corewizard
Member Avatar for chumsie
0
131
Member Avatar for hondros

This simple script will copy all music files that were not purchased from the iTunes store to a directory of your choosing. It requires the ID3 module (Created by some person, from somewhere, I forget where, but I DID NOT make this module). The syntax is as follows: [code] ipoddir …

0
480
Member Avatar for tayspen
Member Avatar for Themanhunt

Lets say that you are working on a program such like Notepad, for instance. You want to make a Ctrl+S key event to save your work. This is the ONLY way I have found out that does not cause any conflictions at all. In the KeyUp Sub of, leys say, …

Member Avatar for Themanhunt
2
856
Member Avatar for The web master

here is a javascript code for puting a message in your status bar on your website.Just change testing 123 to your message.:)

-2
168
Member Avatar for selvaganapathy

This code snippet convert Number to String in VB6. For instance input 100 will be return as Hundred, It converts upto Core....

Member Avatar for SoftwarePaladin
0
308
Member Avatar for code_warrior

[I][COLOR="Red"]This code enables the user to enter a number and finds the prime from 2 to the entered number..Please name it PrimeNumbers.java Hope it'll help u..[/COLOR][/I]:D

Member Avatar for atong
0
263
Member Avatar for kvass

This program creates 2 methods for convenience: menu() and binaryQ(). The menu method accepts several strings as its parameters. The first of the strings is the question to be displayed at the top of the menu. The following strings are the menu choices. For instance, if you call [icode]Confirmer.menu("What is …

Member Avatar for kvass
-1
199
Member Avatar for umut78

Thanks to the MS [ICODE]filter[/ICODE] property that disables Cleartype while applying effects. [B]Instructions:[/B] [LIST=1] [*]Paste the snippet to HEAD section of your document. [*]Paste this HTML to HEAD section of your document: [CODE=CSS] <style type="text/css"> .faded { filter: progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=90); } .okay { filter: progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=100); } </style> [/CODE] [*]Add these class, …

0
177
Member Avatar for fallopiano

Here I have a simple range function that can use floats as steps or increments. In a time test (using Psyco 1.6, python 2.5, and a basic PC), the normal frange function was able to go up to 1,000,000 from 0, by .3 , and finish that in about 0.5929 …

Member Avatar for Gribouillis
0
576
Member Avatar for vegaseat

You can use Python modules math, wave, and struct to create and save a synthetic sine wave of given frequency and duration (size) ...

1
3K
Member Avatar for Stack Overflow

Greetings, String parsing isn't always an easy task. Especially in cases where you need to split a single string into a great multitude, but also accounting for maximum performance. The following code presented does this task simply. Using precise allocation techniques perform greatly when writing an algorithm to precision.

Member Avatar for Ancient Dragon
0
2K
Member Avatar for Krstevski

This simple library containing some methods of Ajax. Example about addContent(url, target): With this function you can change the content of the someone DIV tag. E.g: index.php [CODE=php] <html> <head> <title>Untitled Document</title> <script type="text/javascript" src="ajax.js"></script> </head> <body> <div id="test"> <a href="javascript: addContent('test.php', 'content')"> Change </a> </div> <div id="content"> <label> This …

0
864
Member Avatar for sandorlev

Hello! I started to create my own tiny 'framework' mainly built on the socket and the thread module. I haven't been doing too much thread programming before. My problem is that when I try server.waitForConnections(2), at the second connection, it says [code] Unhandled exception in thread started by Error in …

0
474
Member Avatar for tux4life

Some things you need to know: [LIST] [*]This code is not efficient, if you want a more efficient solution, then turn to the STL algorithm [URL="http://www.cplusplus.com/reference/algorithm/next_permutation/"]next_permutation[/URL]. [*]When there are double characters (i.e. characters which occur multiple times) in the string to permute then some permutations will be generated multiple times. …

2
1K

The End.