2,322 Reusable Code Snippet Topics
Remove Filter ![]() | |
It performs the toggle function to change the class of the paragraph tags and reverts back to the default class name when user rollout of it. You can embed the CSS style code inside the Head section of your page using HTML style tag. Code is as follows : | |
Inspired by discussion in [url]http://www.daniweb.com/tutorials/tutorial238544.html[/url] (test cases are from there) I used my magic pattern matching function transformed from numbers and adding the parts length checking loop. I like my own solution better, I do not know about you. | |
This snippet defines a decorator @mixedmethod similar to @classmethod, which allows the method to access the calling instance when it exists. The decorated functions have two implicit arguments [i]self, cls[/i], the former having a None value when there is no instance in the call. Using python's descriptor protocol, the implementation … | |
Returns the largest sum of contiguous integers in the array Example: if the input is (-1, 2, -3, 2, 0, 5, -11), the largest sum is 7 Time complexity is O(n). | |
A simple program to calculate permutations of a string using recursion, I have used a malloc string of size 100 , you can change it to whatever value you want. The author is currently working at Microsoft,any questions can be directed to [email snipped] | |
this function will calculate a string formula which support cos, sin, log, abs, mod, and example : [10*2+(2+3)]/(5 mod 4) and you will get the answer, and this function it really easy to plugin with you code. | |
hi.. guys.. just joined daniweb.. and this is my first post this one's very easy... i suffered a lot to find this simple program.. i hope you guys like it.. here is a quick preview of it...[URL="http://lh4.ggpht.com/_blnOia1d0Pw/TQs3BhaCClI/AAAAAAAACco/3vPqJIlyG-M/gmail%20client.JPG"]http://lh4.ggpht.com/_blnOia1d0Pw/TQs3BhaCClI/AAAAAAAACco/3vPqJIlyG-M/gmail%20client.JPG[/URL] 1. First Of All Add the Following Line to your code: [CODE]Imports System.Net.Mail[/CODE] … | |
I created this simple inherited class to add a function for moving a row up or down within a DataTable. Sometimes it is desired to do so, and I've seen a few people online looking for a way to do it. Would be nicer if I knew how to properly … | |
Version 2.6 of wxPython has support for playing animated gif image files. The example sets up a panel on a frame and then uses wx.animate.GIFAnimationCtrl() to do the hard work. Actually pretty simple code. | |
I want to create 100 buttons in a Form. This is what I just tested. When you finish the following steps, you will see it is very nice. Enjoy. Step 1, Create a Form called Form1. Step 2, Add a TableLayoutPanel called TableLayoutPanel1. Step 3, Make it 10 X 10 … | |
When you want to draw something on a form you need a Graphics object. But a Graphics constructor isn’t public and if that is not enough the Graphics class is also sealed! This means you can’t create a Graphics object via the new keyword nor can you derive from the … | |
This release is an updated version of my previously released code snippet entitled "Get Internet Connection State". I've made this snippet into an actual control that you can add to your toolbox. It can be used with all versions of Visual Studio C#. I'm also posting the main source code, … | |
I've developed a code that is intended to be used in an application extension (as with all my codes) that will tell you if the current computer has an internet connection. To use just include the namespace given at the top of the snippet, then the connection state is a … | |
![]() | Went to sort a dictionary today and found that MyDictionary.Sort wasn't there. Heres a method to sort a dictionary by value. [code] Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Non sorted Dictionary Dim Dictionary As New Dictionary(Of Integer, String) Dictionary.Add(1, "Greg") Dictionary.Add(2, "Marsha") Dictionary.Add(3, "Peter") … ![]() |
Folks have asked numerous times for a code snippet of a binary search of an array. Here is heavily commented code with a few test printf() included to give you a picture of what is going on. | |
Got inspired to make computer to make moves in English Solitaire, I learned in childhood days to solve by myself consistently, no solving or game play interface at the moment (easy to add though). I added printing of the ready solution from the wikipedia, also maybe of your interest are … | |
Here are two examples of opening read streams to files on an FTP server. One example uses the FtpWebRequest method. One example uses the WebClient method. Here is a method of testing those functions: [CODE] using System; using System.Diagnostics; using System.IO; using System.Net; namespace UseFtpStreamExample { using FtpReadStreams; class Program … | |
This will allow you to login a website with python. After logging in, you now have access to all the pages for "members only" accessed with python. Could be handy for a myspace update program, webcrawlers, facebook(not recommended, facebook doesn't like scripts), and other things. Some knowledge of HTML is … | |
This code is based on code from series of programs [URL="http://www.ferg.org/thinking_in_tkinter/"]'Thinking in tkinter'[/URL] This code is not perfect, especially it does not recognize key release when mouse moves out of button area during push. Leave event could also be captured for that to stop the event in that case. | |
This is CURL Ready function , to use it just call do post if the page you are calling has post variables , or get if it has get variables :) | |
Here is a technique I use for sending an email using GMail. Notice: You might need to change your email settings under [B]Forwarding and POP/IMAP[/B] inside your GMail settings (to Enable POP). Here is a test program for using the class library (shown in the snippet box): [CODE] using System; … | |
To make some operations on XML elements you have to know their types. This snippet is about getting the types of these elements. | |
There are many places on internet for great help regarding many things. Proper implementation of really fast routines for sorting data however is not common. I am not claiming these routines to be the fastest around, but their ease of implementation and use may make them welcome. As a thank … | |
Python does not have a type like struct in C or record in Pascal, but it can be easily implemented with a class. This little code snippet shows you how to do it. | |
I couldn't find a meaningful code sample for the wxPython slider (wx.Slider), so I concocted this one and added a few explanations. It explores two different sliders, one is horizontal, the other vertical. The slider events are then fed to a function that retrieves the position values and displays them … | |
This example is demonstrates a solution for direct arranging By FlamingClaw | |
/** * @(#)dayau_0.java * * dayau_0 application * * @author * @version 1.00 2009/9/28 */ public class dayau_0 { public static void main(String[] args) { int num = 30; String AnsHex = ""; AnsHex = DectoHexDec(num); System.out.println(AnsHex); } public static int DectoHexDec(int x) { String result = ""; int remainder … | |
This snippet defines a function walk() which generically performs a depth-first traversal of a tree, using preorder, inorder or postorder rules. Here, genericity means here that there are no hypotheses on what the tree nodes are or the implementation of the tree. Walk() only needs an arbitrary object used as … | |
I post here the code for histogram using the turtle graphics module, which I posted long time ago in discussion thread. For more special graphs there exist other fancier options, but this tkinter based routine can function in most standard installations of Python. Example data.txt, like mentioned in module docstring: … | |
Hand evaluator for Texas Hold'em. If a "hand" has five or more cards, hand.rank will find the best five card hand the hand can form. Two hands can be compared using the comparison operators. The final hand can be gotten from the "hand" with hand.rank.hand. The value used for comparisons … | |
Hi people. well after I started learning C++ I thought why not try out my skills in some programming so I made my first programme. It is a very basic game commonly known as "HANGMAN" to many. It still might have some errors but it works. Hope you can modify … | |
Hey All, Here is a really simple piece of code that works as a magic 8-ball program where the user types in a yes/no question and a random response is returned. This could be a good read for new C++ programmers (like me), as it covers a lot of basics: … | |
This snippet defines a simple decorator to post-process a function's return value through a sequence of filters. As a first application, the decorator can transform a generator function into a function returning a sequence type (list, tuple, dict). | |
Converting a decimal integer (denary, base 10) to a binary string (base 2) is amazingly simple. An exception is raised for negative numbers and zero is a special case. To test the result, the binary string is converted back to the decimal value, easily done with the int(bStr, 2) function. | |
This code below add two positive numbers in any base from binary to base 36 with any length allowed by memory. The snippet comes with examples. There might be some bugs, because I haven't tested extensively, so forgive me if you find bugs. Hope people find it useful somehow. Thanks … | |
This is my code for anagrams not utilizing the ready prepared file of anagram synonyms to celebrate 11.11.11 11:11:11. If you start program it warns you about missing subdirectory dict and creates it. You may put any word files, one word per line, to file <dictionary name>.txt. Program lists available … | |
Is it Mother Date and Father Time? Any way, getting all the different date and time displays working can be imperturbably perplexing at times. You take a look at it in this Windows Console Application. | |
This is similar to earlier posts in DaniWeb by vegaseat, but it demonstrates getkey with withdrawn tkinter, restart inside object by re-calling it's __init__ method. | |
This snippet defines a decorator to automate attributes setting in class instances at creation time. It can be seen as a gadget feature but it can also be handy especially for fast class prototyping. | |
Any sequence of python strings can be disguised to look like a file opened for reading, which can then be passed on the fly to functions expecting such an input file. This code snippet defines the necessary adapter class. The obtained file-like objects store only one string of the sequence … | |
CSV is more than just comma delimited fields. There are quoting and white space rules too. This is a short function as an example of a complete way to read CSV records line by line. | |
This is a series of 3 code snippets which together form a completly working "calculator". I used a console application in VS C# 2008, but 2005 should cause no problems. To start with : here you have the code for a scanner class. A scanner reads the inputline and tries … | |
Here is class that can be fed directly from split stream like one number per line file (or [URL="http://www.daniweb.com/software-development/python/code/321725"]generator producing 'words'[/URL] from multiple numbers per line). | |
There isn't a whole lot here about security related stuff, so I figured I would post some work in progress. It is pretty well commented so following it should be pretty simple. The full story and reasons for doing what I did, and not another way can be found on … | |
This snippet composes functions of the form [icode]func(infile, outfile)[/icode] which read an input file and transform its content to write an output file. A function [icode]compose((f, g, h,...))[/icode] is defined which returns a new such file transformation function which successively applies f, g, h, using in-memory temporary files. | |
This is code to plot a "random walk" in polar coordinates.See also: [url]http://www.daniweb.com/software-development/csharp/code/379275[/url] Just posted the code of my main form, more details can be found in the zip file. I also included a sample output. I perhaps intend to use this in some sort of game, were a biologist … | |
If a word or sentence reads the same way forward and backward, then it is a palindrome. A small admonition is in place, whitespaces and punctuation marks can be ignored. Also, all the letters should be in one case, lower or upper, your choice. Ideal for Python to show off … | |
This is not about a DataGridView or something else, it is just about drawing a simple grid in a form window. Googled a bit but found not much of my liking. A Grid as a BitMap in a PictureBox? Come on! Must have been some of those GUI guys I … | |
What this script does is take in an image and export a thumbnailed version. Function Arguments: $file : Desired image to create a thumbnail of $destination : End location for the thumbnail $zoom : Setting type, explained later (default: false) $t_width : Thumbnail width (default: 150) $t_height : Thumbnail height … |
The End.