1,916 Reusable Code Snippet Topics

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

Software Development delphi pascal python
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.

Software Development
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.

Software Development python tkinter
Member Avatar for e-papa
0
760
Member Avatar for abelLazm

This is the simple code to read an image from the database.

Software Development image
Member Avatar for bahed121
2
251
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.

Software Development java
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

Software Development
2
506
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 …

Software Development python tkinter
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.

Software Development python
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 …

Software Development
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 …

Software Development
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.

Software Development python
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.

Software Development python
Member Avatar for e-papa
0
731
Member Avatar for e-papa

This is a program that can calculate, the GPA of a student on a 5.0 scale,it's written in python 3.x and no modules are required.

Software Development python
Member Avatar for TrustyTony
0
6K
Member Avatar for Asif_NSU

Gaussian elimination is designed to solve systems of linear algebraic equations, [A][X] = [B] This program reads input from a file which is passed as an argument when calling the program. Say the matrix is in file name matrix.txt so we call the program in this way: ------------------------- gauss matrix.txt …

Software Development algorithm c
Member Avatar for xNourax
0
1K
Member Avatar for vegaseat

Crypting with xor allows one to write one function that can encrypt and decrypt a file. In this example a text file is used, but it could be an image file as well. Once you have created the encrypted file you simply send it through the same function again to …

Software Development encryption python
Member Avatar for TrustyTony
3
7K
Member Avatar for #include<DAN.h>

A fun little program that uses your internal motherboard speaker or "Beep" speaker and your keyboard to make a musical instument very similar to a musical KeyBoard.

Software Development c++
Member Avatar for KumarUtkarsh
0
174
Member Avatar for BevoX

Alright no more prime number generators I promise, but I had to fix the last one... This one uses the Sieve of Eratosthenes algorithm. It can generate prime numbers even faster, than the previous version. 1 million prime number in 2,331 second, ten million prime number in less than 22 …

Software Development algorithm c++
Member Avatar for KumarUtkarsh
0
156
Member Avatar for PdotWang

This is an answer to a question in C++ area. [url]http://www.daniweb.com/software-development/cpp/threads/355232[/url] It should be ready to be modified to code in C++, C#, or Java, because VB.Net is fully OOP. Even though it can be used for vectors, you may still want to modify it to a Vector Class.

Software Development vb.net
Member Avatar for spixy
0
718
Member Avatar for ywang

[I]<<mod edit: answer to [URL="http://www.daniweb.com/software-development/python/threads/32007/1496502#post1496502"]this post[/URL] from the sticky "[URL="http://www.daniweb.com/software-development/python/threads/32007"]projects for the beginner[/URL]">>[/I] [CODE] #1 * 8 + 1 = 9 #12 * 8 + 2 = 98 #123 * 8 + 3 = 987 #1234 * 8 + 4 = 9876 #12345 * 8 + 5 = 98765 #123456 …

Software Development c++ python
Member Avatar for vegaseat
0
1K
Member Avatar for PdotWang

With ListView and ListBox, you can have multiple selections when you set the property to do so. There are different ways to delete all selected items from a ListView and ListBox, right or wrong. I have some lessons learned on the topic. (1)Use For Each loop in ListView. (It works) …

Software Development listview vb.net
Member Avatar for WolfPack
0
3K
Member Avatar for ndeniche

This snippet is to create a user control that will only take numbers. Numbers will accept decimal values, for which the NumberBox is validated to take only one. The implementation for the control is the same as it is for the TextBox, since it is inherited from this class and …

Software Development vb.net
Member Avatar for PdotWang
0
2K
Member Avatar for Momerath

This snippet shows how to use Mutex to prevent multiple copies of your software from running. For a WinForms application, this code goes into the Program.cs file. The magic starts in line 14 where we attempt to create a Mutex. A Mutex is a form of a lock, but it …

Software Development
Member Avatar for CsharpChico
5
560
Member Avatar for TrustyTony

Not my code but I think free to share. This is intended as beginning point of learning classes or learning data structures. Read the document [url]http://mcsp.wartburg.edu/zelle/python/python-first.html[/url] As first exercise, this does not work instead of the while loop in test part: [CODE] for i in numbers: print i [/CODE] [QUOTE] …

Software Development data-structure oop python
Member Avatar for TrustyTony
0
857
Member Avatar for manutd

This is a function that will find the factors of a given number for you. EDIT: Better algorithm using vectors (thanks all at cprog :) )

Software Development algorithm c++
Member Avatar for lxXTaCoXxl
0
181
Member Avatar for bumsfeld

This Python snippet shows you how to take typical beginner's example of prime number function and work on improving its speed. The decorator function for timing is ideal tool to follow your progress you make. The improvements are commented and you are encouraged to make further improvements. Python is fun!

Software Development python
Member Avatar for TrustyTony
0
2K
Member Avatar for RwCC

This seems to come up every so often, so thought I would add it here so people can have a look if they search the site. Reading and writing to a text file is a very basic thing in C#, most of us have to do it from very early …

Software Development
Member Avatar for Vengeful
0
233
Member Avatar for ddanbe

The DataGridView class is huge and complex. It is a beast I'm still struggling with, but once you learn to comprehend it, I find it most rewarding! Some try to circumvent it by using listboxes and the lot. Why don't get your feet wet with this as basic as it …

Software Development vb.net
Member Avatar for ddanbe
2
1K
Member Avatar for jwenting

Validation whether a string can be parsed to a valid date according to a supplied formatting string (which should conform to the formatting rules as supplied in DateFormat). This version can also flag dates in the past as error (we need that because many of our applications should accept only …

Software Development java
Member Avatar for javaAddict
0
258
Member Avatar for ReaperUser101

Hi guys The just of what i whant to do is read lines of text from a file until it reaches a delimiter and then execute that text in a query and repeat the process till there is no more text. I am using Delphi 6(don't have a choice) and …

Software Development delphi pascal
Member Avatar for ReaperUser101
0
221
Member Avatar for Alex Edwards

Solves simple string-based expressions. Currently only supports integers, but can easily be expanded to support float-types.

Software Development java
Member Avatar for Taywin
1
3K
Member Avatar for andreasu

A simple streaming server-client pair with non-blocking user input can easily be coded in Python by using the 'select' module that provides a straightforward interface to the Unix select() system call. For Windows users however this is not an option as the acceptance of three empty sequences in the conventional …

Software Development client-server python socket-programming
0
594
Member Avatar for RenanLazarotto

Hey people! I was just surfing around the threads here, and found one asking for how to make a Installer-like GUI ([url]http://www.daniweb.com/forums/post1492819.html[/url]). I've replied there, but I think that is nice to have this on our code database. To start, let’s make na empty Project. Add a TabControl to it. …

Software Development app-store gui vb.net visual-studio
Member Avatar for RenanLazarotto
0
644
Member Avatar for vegaseat

I am afraid, I am starting to like C#, despite the somewhat bloated .Net Framework requirements. Mister Bill's Microsoft is very supportive though. The language has a nice flow compared to GUI programming in C++. Here we are looking at a standard ListBox, add some items, sort them and select …

Software Development c# gui
Member Avatar for anucom
0
714
Member Avatar for Momerath

The past few days I've posted some sorting routines customized to the tasks they were required to solve. Since I have a bunch of different sorting routines already coded, I decided to post them. Please note that some of these sorts are fast, but not a single one is as …

Software Development
Member Avatar for Momerath
3
829
Member Avatar for Momerath

When Microsoft was developing Windows Vista (and they continued this in Windows 7) they decided to add a security feature to the Program Files directories. This feature is that all the directories are read only. The idea behind this is to prevent malicious software from overwriting your exe/dll files. This, …

Software Development windows-vista
Member Avatar for Ssyxz
2
737
Member Avatar for Gribouillis

This snippet defines a function [icode]a2bits[/icode] which converts a characters string to a string of 0's and 1's showing its bitwise representation.

Software Development python
Member Avatar for Gribouillis
0
2K
Member Avatar for Momerath

Generating permutations of a sequence is a problem that is commonly asked. It's fairly easy to do if you know how many items will be used beforehand, but a generic method to do so would be better. The snippet will do a lazy generation of the permutations (the next one …

Software Development
Member Avatar for ddanbe
3
2K
Member Avatar for jephthah

i dont normally work in the console/terminal window in my day job. so, i keep rewriting this every time i respond to someone needing help related to getting user input. im putting it here partly so i dont have to keep rewriting it. this function will get a string input …

Software Development c
Member Avatar for BNF
1
1K
Member Avatar for Luckychap

Here is simple C program for analog clock. Comipler: TurboC

Software Development c
Member Avatar for Adak
0
2K
Member Avatar for mrnutty

The simplest sort, although inefficient. Below is a demonstration of bubble sort and insertion sort. The bubble sort just consists of 2 for loops and std::swap. The insertion sort uses 2 loops as well but not as much swap as bubble sort. Any questions ?

Software Development c++
Member Avatar for 88omar
1
434
Member Avatar for Mitja Bonca

Code shows how to bind the data from a database`s table to dataTable and populate dataGridView with it. And then how to pass the modified (or not) data from dataGridView back to dataBase`s table.

Software Development vb.net
Member Avatar for tomason
0
752
Member Avatar for vegaseat

Here we experiment with a gauge or progress bar made from a label displaying a variable number of spaces in color. In this example, we use from 0 to 100 spaces. This label based gauge allows you to choose many different colors, and you can even change the color as …

Software Development python
Member Avatar for naytanl
1
592
Member Avatar for TrustyTony

I had posted here already here to forum a [beautiful code for solving Sudoku puzzles](http://www.daniweb.com/software-development/python/code/294304/eleagant-and-fast-sudoku-with-generator-expressions), so I was in kind of dilemma what to do, as I read the task to do a sudoku solve as one task in Project Euler. To use the code from before and just take …

Software Development algorithm puzzle python
Member Avatar for TrustyTony
0
894
Member Avatar for TrustyTony

Saw somebody was viewing this thread and thought the qrange needed one update. From post [url]http://www.daniweb.com/code/snippet216627.html[/url].

Software Development python
Member Avatar for TrustyTony
0
636
Member Avatar for Beat_Slayer

Simple script for image transparency. Someone asked one some time ago, and i had other but for a different system, and decided to write a Python/PIL version. The value of the color used as transparent is the value of the pixel at position (0, 0). You can adjust tolerance value. …

Software Development image python tkinter
Member Avatar for gleam.uahmed
0
1K
Member Avatar for TrustyTony

Here is my newest version of the pretty printer I posted earlier. Not doing all that fancy stuff of printing looped recursive structures, but if you put one deeper structure inside flat one, works better for me than pprint module. I do not use often object oriented structures though. Dedicated …

Software Development printer python
0
662
Member Avatar for Momerath

Sometimes we need to generate sequence and perform some process on the results. This usually results in some code like this (We'll be using the [URL="http://en.wikipedia.org/wiki/Fibonacci_number"]Fibonacci sequence[/URL] in these examples): [code]void MyMethod() { // What we want to do is output to the screen the first 10 Fibonacci numbers // …

Software Development
Member Avatar for Momerath
2
631
Member Avatar for Mitja Bonca

The code gets all the files (only names, if you want to get the paths too, simply remove for loop (its only one) from the code. Files are stored into a generic list. Mitja

Software Development
Member Avatar for ShahanDev
0
1K
Member Avatar for justice igwe

well am using the turbo c++ compiler , so you must convert it to cpp ( c++) before u can use it ok. here we go. steps: (1)press the windows shortcut key and hold R or go click on RUN (2) type in the following( C:/TC/BIN/TC.EXE) hit ENTER, wait for …

Software Development c++
Member Avatar for justiceigwe
-3
379
Member Avatar for FlamingClaw

This is just a simple password program...

Software Development pascal
Member Avatar for FreeBirdLjj
0
2K

The End.