2,322 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for Bench

For anyone who gets fed up with the somewhat verbose syntax involved in populating an STL map container with static arrays of std::pair (Or any of the other somewhat tedious ways of writing 'pair' combinations), here is a function which allows two different (statically allocated) arrays, of equal length, to …

Member Avatar for vijayan121
0
2K
Member Avatar for raj26061990

The two numbers are accepted as Commamnd line arguements and GCD of those numbers are found using a recursive method.

Member Avatar for raj26061990
0
2K
Member Avatar for Beat_Slayer

Aproach to the implementation of K-Nearest Neighbor (KNN) using the Euclidean algorithm. Sample Usage: [CODE]mywork = Words_Works() lit = 'literature.txt' mywork.add_category(lit, 'Literature') # adding files as category comp = 'computers.txt' mywork.add_category(comp, 'Computers') phy = 'physics.txt' mywork.add_category(phy, 'Physics') # saving categories dictionary to file mywork.save_categories() # can be loaded calling load_categories() …

Member Avatar for Beat_Slayer
0
795
Member Avatar for Luther von Wulf

This function reformats a numeric sequence to include grouping in the usual human readable format. "123456789" becomes "123,456,789", for example. The formatting is localized to the current running machine. In a German locale the previous example becomes "123.456.789". In a Hindi locale it becomes "12,34,56,789". Printing numbers for human consumption …

1
489
Member Avatar for TheVenerableZ

I made a PHP class that dramatically simplifies sending text messages with PHP. I know this isn't really a "help me out!" type question per se, but I would like to share the code because I have found it to be tremendously useful. You're free to do whatever you'd like …

Member Avatar for ﻼim
0
2K
Member Avatar for LevyDee

Hi guys, I just thought I would add this because it was a pain for me to muster up due to the lack of information through google and msdn on the topic. Enjoy =)

Member Avatar for Geekitygeek
0
2K
Member Avatar for indianscorpion2

this code is to find the factorial of a number by the recursion principle. trace the control flow in this program very carefully.

Member Avatar for Adak
0
176
Member Avatar for majestic0110

I just wanted to demonstrate a quick point regarding Constructors & inheritance. Look at these two classes and think about what you might expect to see after the main method has run. Notice that ClassB is a subclass (inherits from) of ClassA. So, what do we expect the output to …

Member Avatar for masijade
3
668
Member Avatar for swetz

I have written a code to validate a string.but i am getting an error in the 3rd sentence as "the name "NullToString"does not exist in the current context"...can anyone help me out...

Member Avatar for nick.crane
0
179
Member Avatar for Ramy Mahrous

Here's I wrote some code to validate user input without using if\else statements. I believe in scalability is the most important aspect in our problems solution. Let's say we are required to permit only numerics in some text boxes; we shouldn't develop something like that [iCODE]if(((e.KeyChar < '0' || e.KeyChar …

Member Avatar for ADias-Jayasinha
0
369
Member Avatar for ryuurei

I had been working on this program for a while. It was inspired by the slowness of Windows' search feature. I made it so I could simply look for files to see if/where they existed quickly. I eventually added in the feature to delete files. It was no major extension …

Member Avatar for tls-005
3
453
Member Avatar for mrnutty

Its a typical implementation of mergesort algorithm. It runs in a stable time of O(n*log(n) ). Just thought, I would add it to the library. Its been tested, although not very throughly, so if any bugs are found, just post it here, so others can be aware of them. Its …

Member Avatar for Rashakil Fol
0
885
Member Avatar for ApocDen

This is a very simple WYSIWYG Text editor that only has three options Bold, Italic, and Underline. just copy and paste on the page you want it on. it is really easy to add more features. ENJOY

Member Avatar for Taywin
0
350
Member Avatar for William Hemsworth
Member Avatar for William Hemsworth
2
7K
Member Avatar for ApocDen

1. Imports System.IO 2. Create class "CreateThumbnails" or any class and place following function inside that class You need one function to response call back to main function Function ImageAbortDummyCallback() As Boolean Return False End Function

0
567
Member Avatar for vegaseat

Python programming can have its lighter moments. Here we use one of those moments to draw an optical illusion using the Tkinter canvas to draw a rectangle, some lines and circles.

2
726
Member Avatar for Beat_Slayer

ITunes Library Persistent ID Editor. Sample usage: [CODE]fxml = 'iTunes Music Library.xml' # path to xml file fitl = 'iTunes Library.itl' # path to itl file itk = ITunesLibKeys(fxml, fitl) print itk.file_xml # prints path to xml file print itk.file_itl # prints path to itl file print itk.xml_key # prints …

0
1K
Member Avatar for vegaseat

Do I have to spell it out for you? This short C code will do just that. It will spell out an integer number in English words. The banks do that on large checks, and it would be nice to get one of those every now and then.

Member Avatar for soulcandra44
1
527
Member Avatar for ApocDen

for this to work you need to add some text boxes and name them accordingly, make sure when you add a text box add [CODE]$_POST["new_text field"] = $new_text field;[/CODE] etc etc. html coding can be used within the html tags only.

Member Avatar for metalix
0
229
Member Avatar for Rkeast

I am posting this code snippet as I continue to see login and user registration scripts that store passwords in databases as unsalted md5 hashes, and passwords in cookies as raw text. This snippet includes an example user registration function, as well as an example user login, login check, and …

Member Avatar for metalix
0
519
Member Avatar for metalix

To view this tutorial with notes at [URL="http://www.effectivewebdesign.co.nz/tutorial.php"]http://www.effectivewebdesign.co.nz/tutorial.php[/URL] yes I am aware this is more php than mysql. howerver I get asked how to do it so often I thought I'd post it here aswell :)

0
791
Member Avatar for ApocDen

this snippet is to create random passwords with a chosen length and a specified number of numbers. Uses both lower case and capital letters, which are chosen at random. And example is: wep5Q268LtTe. [B][U]How to use.[/U][/B] Using this is very easy just add to the appropriate page and call the …

0
708
Member Avatar for ApocDen

This is a User Defined Function to perform simple encryption on an input string. This is performed by transposing the ASCII value of each character in the string by the increment value (@increment in the parameter list) Pass the function the string you wish encrypted and the increment value, which …

0
314
Member Avatar for DealthRune
Member Avatar for Dave Sinkula

This code uses a structure to map a letter to an equivalent representation of Morse code. It simply loops through either a string to encode or decode looking for text to substitute with a replacement string or character. Output is presented to the stdout.

Member Avatar for Quagmire232
0
377
Member Avatar for jbronen

Hey, I'm writing a program that takes files and renames them to include a timestamp of the current time on them in c++. I'm pretty new to c++ (and programming in general) and any help or advice would be greatly appreciated. So far I have this: When I compile it …

Member Avatar for jbronen
0
845
Member Avatar for vegaseat

The code is shamefully short, but here it is. Now you can listen to the many sound files in wave (.wav) format and boing, chirp, chime, bark, booh, laugh and mooh at the people around you.

Member Avatar for jbronen
3
1K
Member Avatar for TrustyTony

Here is my practise with [URL="http://www.boggled.org/"]boggle [/URL]letter square non-overlapping word finder after some drastic debugging and cleaning. I think it is reasonable speed also. Comments wellcome.

Member Avatar for TrustyTony
0
1K
Member Avatar for Troy

This is a PHP script that allows javascript clients to request content they otherwise would not be able to. With the popularity of AJAX (using the XmlHttpRequest object in the browser), many developers are becoming aware of the cross-domain scripting limitation. This is a security feature that prevents client-side scripts …

Member Avatar for umakantp
0
6K
Member Avatar for essential

A simple progress bar that you can addUp with some common events' like redirecting the user to another source. And while they wait let this progress bar do some work for them...

Member Avatar for israelvainberg
0
204
Member Avatar for Lusiphur

As suggested by Duki in [URL="http://www.daniweb.com/forums/thread298488.html"]this thread[/URL] I figured I'd compile all the workable examples and explanations here towards the question of "Why do we use get/ set to change properties?" [QUOTE=pritesh2010]Properties provide the opportunity to protect a field in a class by reading and writing to it through the …

2
504
Member Avatar for saqib_604

Aslam o Alikum to all, here is my code to get and change the attributes of a txt file. I want to change the hidden attribute of file. In this code, when i get attribute of file, the number 20 (100000) is returned in cx. I changed this number to …

Member Avatar for muslimgirl
0
315
Member Avatar for Tech B

This bot has some common functions, along with some not so common. I've been using this code to text my wife from work when my phone dies. Requirements: [LIST] [*]Gmail account (for texting) [*]xgoogle (for lang translation) [/LIST] I know it is messy, and the variables are named poorly; sorry. …

0
482
Member Avatar for Dingbats

Hello Everyone, my first post - so please don't shoot me if it goes wrong! I'd been looking for this for some time now and have seen a number of related queries but no solutions. I cannot take credit for the whole code here, but I did adapt it to …

0
625
Member Avatar for Black Magic
Member Avatar for TrustyTony
0
235
Member Avatar for mrnutty

This is a simple demonstration of meta programming. It shows the idea of meta programming. It basically calculates the factorial of a number before runtime. When I first saw the concept of meta programming, it blew my mind so badly. I was so surprised that one could do this. Its …

Member Avatar for griswolf
2
410
Member Avatar for G_Waddell

Hi, Ever had an application that you want to store [B][U]user specific[/U][/B] settings on? e.g. login name or Form background colours, User specifc DSN connections etc. So the next time they run the app the information is there for them? This can be achieved in VB.net with just a few …

6
2K
Member Avatar for jcao219

This is not my code! Taken from [URL="http://stackoverflow.com/questions/3230978/code-golf-four-is-magic/3231355#3231355"]this SO post[/URL]. You can use this to get the number of letters in the English representation of an integer, from 0 to 99. So for example 5 (five) is [icode]len("five")[/icode] which is 4.

Member Avatar for TrustyTony
0
176
Member Avatar for TrustyTony

Here is my try of changing integers to English written numbers. Here corrected version 3 check: [CODE]from __future__ import print_function import random,sys if sys.version_info[0]==3: raw_input=input to_19 = ["zero", "one","two","three","four","five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" ] tens = ["","","twenty", "thirty", "forty", "fifty", …

Member Avatar for TrustyTony
0
1K
Member Avatar for vegaseat

A simple program to count the words, lines and sentences contained in a text file. The assumptions are made that words are separated by whitespaces, and sentences end with a period, question mark or exclamation mark.

Member Avatar for snippsat
2
2K
Member Avatar for TrustyTony

As I was student, the bracketed plurals were absolute 'NO, NO'. With this simple function you can cleanly avoid putting bracket plural(s) after your numbers. If the number deciding singular/plural should not be automatically included, you can make version with [icode]str(n)+' '+[/icode] eliminated. If you want to put automatically space …

Member Avatar for TrustyTony
0
771
Member Avatar for appunu

I new to python . I created the one console application in python for that i used two data bases IBM_DBI and POSTGRESQL8.4. I converted the console application into windows exe for that i used py2exe. It is created, while running the exe it coudn't connect with DB2 data base …

Member Avatar for TrustyTony
0
995
Member Avatar for Rajnesh

start Server first start Client by passing the ipaddress of the server eg; java Client 10.0.1.15 if an error pops up change the port in both Client and Server programs

Member Avatar for jt86442
0
3K
Member Avatar for TrustyTony

See the link ([URL="http://norvig.com/sudoku.html"]Solve Every Sudoku Puzzle[/URL] for fine description of logic of the code) I attach the top95.txt file of tough problems and the sudoku claimed toughest of all time by Finnish mathematician Arto Inkala ([URL="http://www.kristanix.com/sudokuepic/worlds-hardest-sudoku.php"]The Worlds Hardest Sudoku Puzzle[/URL]) Solving this was piece of cake for the code, …

Member Avatar for TrustyTony
0
1K
Member Avatar for FlamingClaw
Member Avatar for nikelin

Simple package loader to load all packages contents from directory-based or from JAR-compressed class path entry.

Member Avatar for NormR1
0
416
Member Avatar for Fungus1487

This is a very brief overview of how to achieve an ON-THE-FLY creation of an appointment in the clients outlook calendar. This will not force the user to add it to there calendar but gives them the option to add it automated. Using the older .vcs file extension for outlook …

Member Avatar for elf123
0
212
Member Avatar for nikelin

Helps to filter objects by interfaces and annotations their contains/implements with respect to parental relations.

0
484
Member Avatar for dinkado

The code works perfect in IE but I can't get it to work in Firefox. Is there a work around for firefox? Your time and help are greatly appreciated. dinkado

Member Avatar for fxm
0
259
Member Avatar for TrustyTony

The code from my answer to thread: [url]http://www.daniweb.com/forums/thread292949.html[/url] Any field names with any same separator separating the values. This is straight text file reading routine, see the original thread for csv module based code. sample.dat: [CODE]id; name; email; homeaddress 123; gishi; gishi@mymail.com; 456 happy st. 345; tony; tony.veijalainen@somewhere.com; Espoo Finland …

Member Avatar for TrustyTony
0
1K

The End.