I used to play around with Ruby a lot. Here’s another script, where I was downloading fedora ISOs and giving myself feedback as to the progress of the operation (yes, I was in cygwin also). #!/usr/bin/rubyrequire ‘net/ftp’require ‘fileutils’ftp=Net::FTP.new("ftp.linux.ncsu.edu")ftp.login("anonymous", "me@email.com")FileUtils.chdir("/cygdrive/c/downloads/fedora")files=ftp.chdir("pub/fedora/linux/core/3/i386/iso") def mecallback() print ‘filename: ‘, (File.size($fileName) * 100.0 / $fileSize), "%\n"end $fileName="FC3-i386-disc3.iso"$fileSize=ftp.size($fileName)print ‘filename: ‘, $fileName, "\n"ftp.getbinaryfile($fileName, [...]
Archives for July 2008
Ruby is so elegant
This is a script to log in to a server via Telnet and run a single script remotely. require ‘net/telnet.rb’ myserver.com = Net::Telnet::new("Host" => "myserver.com", "Timeout" => 30, "Prompt" => /[$%#] \z/n) myserver.com.login("username", "password") { |c| print c }myserver.com.closemyserver.com.cmd("./check_missing.sh") { |c| print c }
Regular expressions reference
URI Regular expressions E-mail regular expressions
.htaccess redirect guide
My favorite tip: Changed file extension? This example is perfect if you’ve decided to switch to .php from .html pages. It will look for any .html page and redirect it to .php (ie http://www.example.com/yourpage.html and redirect it to http://www.example.com/yourpage.php). Now, be careful with this, it does mean any html page. I did this on one [...]
Rip page to new window in firefox
On the bookmark toolbar, right-click and select “New Bookmark…” Under name, give your bookmark a fitting title, like, “Rip page.” Under location, enter the following code: javascript:var x=window.open(document.URL, ‘_blank’,'width=800,height=600′) Or… just drag the following link to your bookmark toolbar. Rip page. Update on August 5, 2008: I found the following works well for ripping a [...]
Optimized prime number generator
Same specs as previous system, 8 hours to find all primes to ULONG_MAX. #include <stdio.h>#include <malloc.h>#include <limits.h>#include <math.h> struct linked_list{ unsigned long number; struct linked_list *next;}; int main(int argc, char **argv){ unsigned long divisor, max_divisor, prime_test; unsigned long max_prime_to_store; struct linked_list *first=NULL, *current=NULL, *last=NULL; first=(struct linked_list *)malloc(sizeof(struct linked_list)); first->number = 2L; first->next = NULL; last [...]
I miss C programming. Program to find prime numbers
Uses unsigned long long, goes up to ULONG_LONG_MAX. Intel Core Duo 2 processor, running Cygwin on Windows XP, and compiled using gcc 3.4.4. Stops at first million results due to time. Can reasonably get to 10 million, if you’re willing to wait. #include <stdio.h>#include <math.h>#include <limits.h> int main(int argc, char **argv){ unsigned long long divisor, [...]
VBScript to push files into an array based on a wildcard
Option ExplicitDim gFSODim dirListingDim fileName set gFSO = CreateObject("Scripting.FileSystemObject") dirListing = ListDir("c:\??*d*") If UBound(dirListing) = -1 then Wscript.Echo "No files found."Else For Each fileName in dirListing WScript.Echo FileName NextEnd If ‘==============================================================================’ List a directory, with the last part of the directory being the path’==============================================================================Function ListDir (ByVal Path) Dim fileRegex Dim searchFolderName Dim searchFolder Dim searchFolderFiles [...]
Tag Cloud for ftp blogger blogs
In the sidebar section for Blogger template, include: The following is a modified version of tag cloud source I found. define(‘PREFIX’, ‘labels/’); // for url define(‘SEARCH_DIR’, ‘/home/username/www/labels’); // server location of labels subdirectory define(‘THIS_FILE’, ‘labels.php’); // name of labels file (this file) if(file_exists(SEARCH_DIR.’_cloud_include_cache.php’) && filemtime(SEARCH_DIR.’_cloud_include_cache.php’)>(time()-(60*60))) { echo file_get_contents(SEARCH_DIR.’_cloud_include_cache.php’); } else { build_cloud(); } /** * [...]
Posts