Pages

Sponsorship

40% off your First Order with GoDaddy.com!
Showing posts with label Code Snippets. Show all posts
Showing posts with label Code Snippets. Show all posts

Jan 29, 2010

Substitute Strings in Files with Ruby


Uses a list of regular expressions and replacement strings to make changes in text files.

Put in file "edit-all.rb" and run with
ruby edit-all.rb *.txt

Now accepts the target and the replacement from the command line or from the keyboard.

Jan 22, 2010

Ruby CSV to XML Converter


This code will take an input CSV file and output XML. IT was easy to write, but I haven't found anything out there to do this. The first line of the CSV file should contain the element names.

Jan 15, 2010

RSS Twitter Bot with Ruby


A short Ruby script that will read an RSS feed and republish it to your Twitter account. This could be useful for livestreaming or getting some sort of commercial presence on there.

Jan 9, 2010

Ruby: Pronounceable Random Password Generator


This piece of code generates a random password of the specified length, but mixes the two sets of letters so that a pronouncable password is being generated.

Jan 2, 2010

Ruby: Extract Age from Birth Date


A Ruby function for extracting one's age by passing in the birth date as a parameter.

Dec 19, 2009

Python: Check Credit Card "checksum"


The CardChecksum function returns 1 for valid cards and 0 for invalid cards, after performing a check using the Luhn algorithm which validates all major credit cards.

Python: Find the Greatest Common Divisor


Implement the Euclidean algorithm into a Python function in order to calculate the largest common divisor of two numbers.

Dec 16, 2009

Ruby: Write A PDF File Using Ruby


Using the open source PDF::Writer library for Ruby to create PDF documents on the fly and save them on the server.

Dec 9, 2009

Ruby: Extended Euclidean Algorithm Function


A function for finding the modular multiplicative inverse, based on an extended version of the Euclidean algorithm.

Dec 2, 2009

Ruby: Strip HTML tags using Ruby


The StripHtml function strips all the HTML tags in the passed string but preserves the ones specified in the PreserveTags array.

Nov 25, 2009

Ruby: Check if an URL is available


This little Ruby function will check if an URL is available (response code 200). It will return true if the return code is 200 (success), false if any other code is returned, such as 404 (not found.)

Nov 18, 2009

Ruby: Mask all Credit Card Digits but Last Four


Mask all the credit card number digits with asterisks except the last 4, for security purposes. The function works for all types of cards (Visa, MasterCard, Amex, Discovery, etc.)