2,322 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for TrustyTony

This I did also after 'spying' discussions in other forum. Of course you would use sieve prime generation for bigger numbers, but I proved other simple way for a change. Slightly more advanced primes list generator would use primes % 6 in (1,5) property: [CODE]def primes(n): """ primitive non-sieve prime …

Member Avatar for TrustyTony
0
750
Member Avatar for ravenous

There are occasionally posts asking how to remove white space from string of characters (either a C-style `char` array, or a C++ `std::string`). Using functions in standard C++ libraries, this is quite an easy thing to do: #include <string> #include <algorithm> #include <iostream> #include <cctype> int main() { /* Make …

Member Avatar for Narue
1
2K
Member Avatar for TrustyTony
Member Avatar for raptr_dflo
0
1K
Member Avatar for TrustyTony
Member Avatar for TrustyTony
0
911
Member Avatar for Troy

Does your organization use Microsoft Exchange? Do you have a need to incorporate your Exchange data with your PHP web applications? You can use the WebDAV methods to query your Microsoft Exchange Server using the PHP scripting language. Once you wrap your brain around these techniques, the sky is the …

Member Avatar for dskanth
0
2K
Member Avatar for jwenting

The question how to create HTML output to the browser from a Servlet based on XML data often comes up. Here's a fully functional example on how to achieve this using Jakarta Xalan 2 and Xerces 2. The system is quite simple, most of the code is concerned with housekeeping …

Member Avatar for lemomo12345
0
933
Member Avatar for Troy III

Since the Firefox [Bug 633133] of the [B]in[/B] operator on DOM Collections has ben finally fixed - We can now write a short fast and clean function of the method "Contains" for FirefoX to check if x.contains(y). And vice- versa. What we will need is: a prototype and we'll chose …

Member Avatar for Troy III
0
633
Member Avatar for zinnqu

Using the Load and Unload events of the Forms add these subs to handle a simple fade in and out effect. This is not limited to just one form. The subroutine definition can be added to any global class allowing the use on any form or sub-form. This is the …

Member Avatar for CsharpChico
1
2K
Member Avatar for lxXTaCoXxl

The idea is to do basic math to find the difference in size between the object and the form. To do this take the object size (int1, int2) and the form size (int1_1, int2_2) then get the difference by subtraction. The math is (int1 - int1_1, int2 - int2_2) so …

Member Avatar for lxXTaCoXxl
0
227
Member Avatar for vegaseat

Continued fraction expansion is a simple way to approximate common trigonometry functions to a relatively high precision. In this example we only look at sin and cosine. The results compare well with the results of high precision packages like SymPy. The Python module decimal is used to achieve the high …

Member Avatar for TrustyTony
3
566
Member Avatar for TrustyTony

To be more clear, I post this 'unnecessary optimization' of Vegaseat's code in new thread instead of end of old one. Just to show that this is even simpler than [URL="http://www.daniweb.com/software-development/python/code/363346/1554115#post1554115"]checking if given day is first weekday of the month[/URL].

Member Avatar for TrustyTony
0
1K
Member Avatar for TrustyTony

Little clean up of vegaseat's code for generating pi decimals. Added number of decimals desired and string type return for easy use with ''.join()

Member Avatar for TrustyTony
1
618
Member Avatar for thekashyap

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. [COLOR="Red"][B]A brief on problem:[/B][/COLOR] Lets take example problem for simplicity: - I have a GSM network with a cell in it. - Cell's coverage …

Member Avatar for thekashyap
3
661
Member Avatar for TrustyTony
Member Avatar for TrustyTony
1
269
Member Avatar for vegaseat

You need the Python tkSnack module to play notes of a given frequency and duration on your external sound system (attached to the PC's sound card). The code snippet gives just a tiny hint about the capabilities of tkSnack. It works with Tkinter, normally part of the Python installation. The …

Member Avatar for Layra
3
5K
Member Avatar for prvnkmr194

Get_Number function is a function to get input from keyboard, this function restrict the user to pass wrong input........... How to use -> For example we need to take input in any integer variable n call Get_Number() like this [CODE] n=Get_Number(); [/CODE] With Full Back Space support Please comments on …

Member Avatar for TrustyTony
-1
285
Member Avatar for TrustyTony

This code determines if datetime object represent first workday of month, but it does not consider the special days like New Year (this year weekend but last year Friday). Reaction to Basic efforts in: [url]http://www.daniweb.com/software-development/legacy-and-other-languages/threads/362098[/url] There algorithm idea given by [URL="http://www.daniweb.com/members/jonkiparsky/775324"]jon.kiparsky[/URL] based docstring says 'workday' when it should be 'weekday': …

Member Avatar for TrustyTony
1
4K
Member Avatar for anilashanbhag

The script is used in my newest chrome app [url]https://chrome.google.com/webstore/developer/detail/bomkcodcgmbjjhogdjophonfhgpegoni/[/url] Site: [url]http://codestrix.co.cc/pixels/[/url] The above script is a good to get stated with HTML5 canvas. Much of it is named so as to be self explanatory but any doubts you are more than welcome to post it here.

Member Avatar for anilashanbhag
1
662
Member Avatar for TrustyTony

Response to hijacker of thread: [url]http://www.daniweb.com/software-development/python/threads/59745[/url]

Member Avatar for TrustyTony
1
326
Member Avatar for OneDreamCloser

hello all, i am getting the following error when i am trying to run my 1st Perl script: [CODE][id=0 @ 0] : IP address "3.3.3.3" corresponds to device "core". Thread 1 terminated abnormally: Not a CODE reference at ./dev_ithread.pl line 23. [id=0 @ 1] : IP address "5.5.5.5" corresponds to …

Member Avatar for erezschatz
1
449
Member Avatar for sahasrara

Dear all this program create a linked list of numbers while you dont enter 0. then bubble sort function is called and finally display function shows sorted list. I wrote it by Borland 5.02 . Have a good time!

Member Avatar for mike_2000_17
0
216
Member Avatar for Xcelled194

One of the things that always irked me about C# is its lack of an InputBox function. In VB, You can simply do [CODE=VBNET]response = InputBox("Enter your name")[/CODE] Unfortunately, there is no C# equivalent. Sure, you can call the VB one, but doesn't that kind of defeat the purpose of …

2
1K
Member Avatar for AutoPython

[B]!USING PYTHON 3.1![/B] [B]USING WINDOWS[/B] I never thought it could be so simple. However I should have clarified that it's a [B]1 character[/B] input. But the general idea is the same. Someone suggested that I explain what is going on better, so I'm going to do that. The function 'getch()' …

Member Avatar for TrustyTony
0
7K
Member Avatar for nssltd

Hey, The reason i am posting this 'snippet' is because a while back i encountered such a problem and i asked a question but never really received an answer. Basically i stumbled upon this snippet by luck when just browsing the web. I have searched the forums but found nothing …

1
625
Member Avatar for Narue
Member Avatar for VernonDozier

Here's a simple, though not the most efficient, program that flags and displays all prime numbers less than or equal to 1000.

Member Avatar for 014
0
782
Member Avatar for TrustyTony
0
791
Member Avatar for e-papa

This is a simple word jumble game, I actually adapted it from one I used from practice. It's written in Python 3.1 using the pyscripter. NO modules needed.

Member Avatar for e-papa
0
675
Member Avatar for G_Waddell

Hi Ever had the situation where you need to make a copy of a Datatable? Or where you wish to copy a datarow from one datatable to another? Well here is how by using [B]Clone[/B], [B]Copy[/B] and the [B]ImportRow[/B] DataTable Methods.

Member Avatar for sandeepparekh9
0
1K
Member Avatar for ddanbe

I mostly use Console or Forms applications in VS for my projects. Did anyone among you ever use an Empty Project when starting a new one? Well, it is as clean as you can get with Visual Studio! The world is at your feet! I use it mainly to test …

Member Avatar for ddanbe
2
969
Member Avatar for CsharpChico

[CODE]using System; using System.Drawing; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { private Panel panel1 = new Panel(); private PictureBox box = new PictureBox(); private Panel closeButton = new Panel(); private bool moveable; private Point currentPosition; private Image img; public Form1() { InitializeComponent(); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; …

-2
663
Member Avatar for ddanbe

Ever wanted to know how to implement running lights? well here is your chance to find out. Open a new Forms application enlarge the Form a bit and drop a Panel and a Timer on it. Add the class ChasingLights to the solution, see code. Implement a form Load, panel …

Member Avatar for Saikalyankumar
5
999
Member Avatar for TrustyTony

Here is experiment of how VM and Swing UI manage the sort test posted previously, instead of CPython and Tkinter. The timing is not so sweet, but at least no Java required! [CODE]K:\jython2.5.2>java -jar jython.jar swing_test.py 256000 words generated in 10.93 s Sorted in 1.68 s List prepared in 22.71 …

Member Avatar for TrustyTony
0
506
Member Avatar for Luckychap

This is Jquery plugin which can be used to change the content a its place. Features: 1. Easy to use 2. Maintain changeability of Jquery Know Issue: 1. Can take html string also as input For example: html: [code=html] <div id="editable">I can be changed right here</div> [/code] javascript: [code=javascritp] $.('#editable').editAtPlace(function(newtext, …

0
361
Member Avatar for TrustyTony

Here is code to execute these printing commands from file: [CODE]talk("How Are You") bark("I am fine") bark("...and how are you") snarl("...sorry I asked") [/CODE] from file INPUT, do printing of results to screen without tags and to file with tags, and open the html output with webbrowser.

0
312
Member Avatar for TrustyTony

I got a look one huge Java code suggestion from one [URL="http://www.daniweb.com/software-development/python/threads/86608/1525822#post1525822"]newbie high jacker of old thread[/URL], so I had to write this code. [url]http://oeis.org/A001235[/url] (for values with [B]minimum [/B]2 ways, first difference is 87539319 with three ways. You can of course change the if part of the print to …

Member Avatar for TrustyTony
0
4K
Member Avatar for TrustyTony

I did this code to compare to Delphi code in Delphi forum [URL="http://www.daniweb.com/software-development/pascal-and-delphi/threads/357771"]TListBox and sorting[/URL] which ran in my computer compiled in free Lazarus environment at time 7,235 s for generate and insert to listbox, 13,265 s sorting the listbox.

0
586
Member Avatar for ddanbe

Start a new Forms application and fill in the above code in the Forms.cs file. If after startup you drag one of the labels the text of the labels will be copied to the textbox.

Member Avatar for CsharpChico
1
1K
Member Avatar for TrustyTony

Here version of TicTacToe demo [URL="http://www.daniweb.com/software-development/python/threads/357974/1526474#post1526474"]code by wooeee[/URL] with packing style, which is more familiar for me. Also fixed indents and made it run also with Python 3.

Member Avatar for e-papa
0
760
Member Avatar for G_Waddell

Hi I thought I'd share this with you all as it is really quite simple but I spent ages looking for it. I have an ASP.Net App with a master page containing a tree view that holds a heirarchy of data (as opposed to site naviagation) What I wanted was …

0
664
Member Avatar for abelLazm
Member Avatar for pinkygirl

Hello. This demo shows how to upload multiple image files, saving them in "Image" folder and displaying them all. To do this, create a folder named "Image" in your solution explorer. I hope you like it :)

0
685
Member Avatar for Alex Edwards

This is a simple Search Engine that contains tokenized words as keys, in which they will return values associated with them in an ArrayList. All that is required is a text file from a valid extension.

Member Avatar for fayimora
0
10K
Member Avatar for abelLazm

Add this code any where in your main form and You will be able to disable the [B]X[/B] button on a winForm

2
504
Member Avatar for vegaseat

The tkSnack sound module was developed at KTH in Stockholm, Sweden. A great module to generate sound, play and analyze sound files and speech. It was written using Tkinter and its native TCL language. Alas, the latest release is from 2005. However, the important file tkSnack.py can be converted to …

Member Avatar for vegaseat
2
4K
Member Avatar for e-papa

We all know that the sum() function in python only takes two arguements, so i created a function in python that will take any number of arguements and add them together, just like the sigma letter in greek. Awaiting your replies on this one.

Member Avatar for e-papa
0
513
Member Avatar for ddanbe

You can get your hands on to usefull information from within your C# program. Use the static System.Environment class! Take a look at this snippet, which can be used as is in a Console application. I have not exhausted all the possibilities, if you want you can look them up …

Member Avatar for Usmaan
0
721
Member Avatar for lxXTaCoXxl

I know there are others out there who haven't figured it out yet I figure I'll help out. The code snippet included will over-ride the pre-designed menu highlight. :D Just change the color of the pen or brush to whatever you want the highlight to be. :) All of the …

0
3K
Member Avatar for e-papa

It solves quadratic equations, for both real and complex roots. Please answer the pol to let me know how I'm doing. This function just needs the python 3.x environment, no modules needed.

Member Avatar for e-papa
0
4K
Member Avatar for e-papa

Well just run, the only thing is that this is created using python 3.x. no modules required.

Member Avatar for e-papa
0
731

The End.