2,322 Reusable Code Snippet Topics

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

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 …

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 …

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.

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 …

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.

Member Avatar for spixy
0
718
Member Avatar for Graphix

Hey everybody, Lately I have written the game Hangman in many different languages (C, JavaScript, Java and PHP so far). Here is the code snippet for PHP! It uses a words file, on the bottom of this post you will see a small example of a few words. The source …

Member Avatar for Nick Evan
0
2K
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 …

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

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 …

Member Avatar for PdotWang
0
2K
Member Avatar for Krstevski

Hello friends, now I will show you how to make a simple anti spam protection (without using captcha) who is very effective. The original idea (for educational purposes) is taken from here: [URL="http://delicon.mk/blog/kontakt-formular-koj-ne-saka-spam-botovi/"]Part 1[/URL] [URL="http://delicon.mk/blog/kontakt-formular-koj-ne-saka-spam-botovi-2/"]Part 2[/URL] Sorry about the links and macedonian language, but I respect my friend and I …

Member Avatar for TechySafi
0
1K
Member Avatar for ApocDen

the code is very simple and all it does is get the ip of a member or guest and logs it in a text file. if the log.html doesn't exist it will auto create one for you, as long as the path is correct. Also make sure you set proper …

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

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

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

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!

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 …

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 …

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 …

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 …

Member Avatar for ReaperUser101
0
220
Member Avatar for Alex Edwards

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

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 …

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

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 …

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 …

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, …

Member Avatar for Ssyxz
2
737
Member Avatar for Wraithmanilian

This code is for a stand-alone file, named "thumbnail.php" or something similar. Once uploaded to your server, it can be called from inside an IMG tag. There are four options for this script without modifying anything. [LIST=1] [*]First, you can resize the image to a percentage of the original, as …

Member Avatar for Web Dev Rob
0
379
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.

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 …

Member Avatar for ddanbe
3
2K
Member Avatar for dazzlindonna
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 …

Member Avatar for BNF
1
1K
Member Avatar for Luckychap
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 ?

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.

Member Avatar for tomason
0
752
Member Avatar for Brianbc

[CODE]<?php /* +-----------------+------------------------------------------------------------+ | Class | setup | | Author | Brian Onang'o | | Version | 1.0 | | Last Modified | 10:16 AM 10/2/2010 GMT+3 | +-----------------+------------------------------------------------------------+ | This program is free software; you can redistribute it and/or | | modify it under the terms of the GNU …

Member Avatar for Brianbc
0
239
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 …

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 …

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

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

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 …

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 // …

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

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 …

Member Avatar for justiceigwe
-3
379
Member Avatar for FlamingClaw
Member Avatar for TrustyTony

I have left my source of information as docstring comment on code side. If you want to solve the problem yourself do not run the code. This code actually gives the correct answer. I have not reacted to the border case comment in my formula source as it is quite …

0
1K
Member Avatar for ckid

HI friends!! I am very new to this type of groups, and this is my first post to this group, before asking u all a help I am just posting this code to u all, , please respond for this code Huffman algorithm is one used for image compression and …

Member Avatar for nilu28
0
3K
Member Avatar for RenanLazarotto

I've found this a little hard to find, so I decided to share with you guys. This small code will allow your app to accept arguments. Just copy the whole code into the main sub (I didn't tested elsewhere) and edit the code inside the for to do what you …

Member Avatar for anoopkh
0
1K
Member Avatar for KevinADC

A bare-bones code snippet to remove duplicate lines from a file. There are a number of ways to accomplish this task but this is a fast and dependable method using perls inplace editor and a simple hash to get the job done. This probably should not be used for really …

Member Avatar for sensamurai
1
1K
Member Avatar for ravenous

I have to calculate the modal value of [icode]std::vector< int >[/icode] quite often, so I thought I'd share my general method for people to look at, use and/or comment. In my case, the vectors usually contain values in the range 0 - 255. The code first creates a [icode]std::vector< int …

Member Avatar for vijayan121
0
1K
Member Avatar for Shalvin
Member Avatar for debashishm
0
146

The End.