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, $fileName, 2**20) { [...]
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 }
URI Regular expressionsE-mail regular expressions
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 of [...]
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 Google Docs page to a new window [...]
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 = first; printf("%lu\n", [...]
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, max_divisor, prime_test; int [...]
Option ExplicitDim gFSODim dirListingDim fileNameset 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 Dim fileName Dim fileArray [...]
In the sidebar section for Blogger template, include:The following is a modified version of tag cloud source I found. PHP | copy code |? 0102define(’PREFIX’, ‘labels/’); // for url03define(’SEARCH_DIR’, ‘/home/username/www/labels’); // server location of labels subdirectory04 05define(’THIS_FILE’, ‘labels.php’); // name of labels file (this file)06 07if(file_exists(SEARCH_DIR.’_cloud_include_cache.php’) &&08 filemtime(SEARCH_DIR.’_cloud_include_cache.php’)>(time()-(60*60)))09{10 echo file_get_contents(SEARCH_DIR.’_cloud_include_cache.php’);11}12else13{14 build_cloud();15}16 17/**18* build_cloud builds a tag cloud from the labels files.19* It actually uses [...]