2,322 Reusable Code Snippet Topics
Remove Filter ![]() | |
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. | |
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 … | |
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 … | |
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. ![]() | |
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 … ![]() | |
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. | |
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 … | |
[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 … | |
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) … | |
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 … | |
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 … ![]() | |
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 … ![]() | |
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 … | |
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] … | |
This is a function that will find the factors of a given number for you. EDIT: Better algorithm using vectors (thanks all at cprog :) ) | |
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! | |
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 … | |
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 … | |
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 … | |
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 … | |
Solves simple string-based expressions. Currently only supports integers, but can easily be expanded to support float-types. | |
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 … | |
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. … | |
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 … | |
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 … | |
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, … | |
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 … | |
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. | |
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 … | |
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 … | |
Here is simple C program for analog clock. Comipler: TurboC | |
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 ? | |
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. | |
[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 … | |
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 … | |
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 … | |
Saw somebody was viewing this thread and thought the qrange needed one update. From post [url]http://www.daniweb.com/code/snippet216627.html[/url]. | |
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. … | |
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 … | |
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 // … | |
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 | |
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 … | |
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 … | |
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 … | |
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 … | |
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 … | |
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 … | |
Placing ComboxBox in DataGrid Cell is a task usually found in Invoicing application. Here is my version of same. |
The End.