2,322 Reusable Code Snippet Topics
Remove Filter ![]() | |
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 … | |
The two numbers are accepted as Commamnd line arguements and GCD of those numbers are found using a recursive method. | |
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() … | |
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 … | |
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 … | |
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 =) | |
this code is to find the factorial of a number by the recursion principle. trace the control flow in this program very carefully. | |
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 … | |
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... | |
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 … | |
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 … | |
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 … | |
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 | |
A small game of pong I put together in about half an hour :) Enjoy. | |
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 | |
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. | |
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 … | |
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. | |
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. | |
![]() | 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 … |
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 :) | |
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 … | |
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 … | |
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. | |
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 … | |
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. | |
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. | |
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 … | |
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... | |
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 … | |
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 … | |
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. … | |
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 … | |
A simple function that converts alphabetic values into their respective lowercase value. | |
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 … | |
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 … | |
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. | |
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", … | |
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. | |
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 … | |
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 … | |
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 | |
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, … | |
The arguments are passed by value and by reference | |
Simple package loader to load all packages contents from directory-based or from JAR-compressed class path entry. | |
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 … | |
Helps to filter objects by interfaces and annotations their contains/implements with respect to parental relations. | |
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 | |
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 … |
The End.