via Simple Desktops on 10/18/11
Colours

Mac OS X systems come with the curl command line tool which provides the capability to retrieve web pages from a shell prompt. To use the tool, using Finder on the system, you can go to Applications, Utilities and double-click on Terminal to obtain a shell prompt.

Curl is also available for a variety of other operating systems, including DOS, Linux, and Windows. Versions for other operating systems can be obtained from cURL - Download. If you will be retrieving encrypted webpages using the HTTPs protocol, be sure to get the binary version that includes Secure Sockets Layer (SSL) support.

A program with similar functionality is Wget, but that isn't included by default with the current versions of the Mac OS X operating system.

On Mac OS X systems, curl is available in /usr/bin and help on the options for curl can be found using man curl, curl -h , curl --help, and curl --manual. An online manual can be viewed at cURL - Manual.

To retrieve a webpage that requires a userid and password for access with curl using the HTTPS protocol, you can use a command similar to the one below where userid and password represent the userid and password required to access that particular webpage.

curl -u userid:password https://example.com/somepage.html

If you don't want to include the password on the command line, you can just specify the userid after the -u; curl will then prompt you for the password.

$ curl -u jsmith https://example.com/somepage.html
Enter host password for user 'jsmith':

If you wish to save the output in a file rather than have it go to stdout, i.e., rather than have it appear on the screen, you can use the -o/--output filename option where filename is the name you wish to use for the output file. Curl will provide information on the number of bytes downloaded and the time that it took to download a webpage.

$ curl -u jsmith:somepassword -o somepage.html https://example.com/somepage.html
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 22924    0 22924    0     0  16308      0 --:--:--  0:00:01 --:--:-- 26379

References:

  1. cURL and libcurl

I needed to submit a form on a webpage using cURL. The form submission was using POST rather than GET. You can tell which method is being used by examining the source code for a page containing a form. If POST is being used, you will see it listed as the form method in the form tag as shown in the example below. A form that uses GET, instead, would have "get" as the form method.

<form method=post action=https://example.com/cgi-bin/SortDetail.pl>

You can use the -d or --data option with cURL to use POST for a form submission.


-d/--data <data>
              (HTTP) Sends the specified data in a POST request  to  the  HTTP
              server,  in  the  same  way  that a browser does when a user has
              filled in an HTML form and presses the submit button. This  will
              cause curl to pass the data to the server using the content-type
              application/x-www-form-urlencoded.  Compare to -F/--form.

              -d/--data is the same  as  --data-ascii.  To  post  data  purely
              binary, you should instead use the --data-binary option. To URL-
              encode the value of a form field you may use --data-urlencode.

              If any of these options is used more than once on the same  com-
              mand  line,  the  data  pieces specified will be merged together
              with a separating  &-symbol.  Thus,  using  '-d  name=daniel  -d
              skill=lousy'  would  generate  a  post  chunk  that  looks  like
              'name=daniel&skill=lousy'.

              If you start the data with the letter @, the rest  should  be  a
              file  name  to read the data from, or - if you want curl to read
              the data from stdin.  The contents of the file must  already  be
              URL-encoded.  Multiple files can also be specified. Posting data
              from a file named 'foobar' would thus be done with --data  @foo-
              bar.

To submit the form using cURL, I used the following:

$ curl -u jsmith:SomePassword -d "Num=&Table=All&FY=&IP=&Project=&Service=&portNo=&result=request&display_number=Find+Requests" -o all.html https://example.com/cgi-bin/SortDetail.pl

In this case the website was password protected, so I had to use the -u option to submit a userid and password in the form -u userid:password. If you omit the :password and just use -u userid, then cURL will prompt you for the password. So, if you want to store the cURL command in a script, such as a Bash script, but don't want to store the password in the script, you can simply omit the :password.

The -d option provides the parameters required by the form and the values for those parameters, which were as follows in this case:

ParameterValue
Num 
TableAll
FY 
IP 
Project 
Service 
portNo 
resultrequest
display_numberFind+Requests

The format for submitting values for parameters is parameter=value. Parameters are separated by an ampersand, &.

URLs can only be sent over the Internet using the ASCII character-set. Special non ASCII characters, which include the space character must be represented with a % followed by two hexadecimal digits. The space character can be represented by + or by %20. So, though the value for "display_number" is "Find Requests", it needs to be sent as Find+Requests or Find%20 requests. You can see a list of other characters that should be encoded at URL Encoding.

In this case, I didn't need to specify values for many parameters in the form, because I wanted the query to cover all potential values for those parameters. So I can just use parameter= and then follow that with an & to specify I am submitting the next parameter in the list.

References:

  1. cURL - Tutorial
    cURL and libcurl
  2. curl Examples
    Linux Journal | Linux Tips
  3. POST (HTTP)
    Wikipedia, the free encyclopedia
  4. The POST Method
    James Marshall's Home Page
  5. How to submit a form using PHP
    HTML Form Guide - All about web forms!
  6. HTML URL Encoding
    W3Schools Online Web Tutorials
  7. URL Encoding
    Bloo's Home Page

OS X je najrozšírenejší unix-like operačný systém na svete. Používatelia, ktorí často pracujú s Terminalom ocenili, že v najnovšej verzii 10.7 ho môžu roztiahnuť na celú…

via Boing Boing by Cory Doctorow on 8/14/11

Etsy seller EricaKnit will custom-make you an R2D2 jumper (there's a matching toque, too). 4-6 week lead time, so get your autumnal plans in gear.

CUSTOM made to order -- Star Wars R2D2 sweater (via Craft)

via Simple Desktops on 8/17/11
Fulozinha

via Simple Desktops on 8/17/11
Bambu

via Wolfram|Alpha Blog by Sam Blake on 8/3/11

In my last blog post on plotting functionality in Wolfram|Alpha, we looked at 2D and 3D Cartesian plotting. In this post, we will look at 2D polar and parametric plotting.

For those of you unfamiliar with polar plots, a point on a plane in polar coordinates is located by determining an angle ? and a radius r. For example, the Cartesian point (x, y) = (1, 1) has the polar coordinates (r, ?) = (?2,?/4). The following diagram illustrates the relationship between Cartesian and polar plots.

Relationship between Cartesian and polar plots

To generate a polar plot, we need to specify a function that, given an angle ?, returns a radius r that is a function r(?). Making a polar plot in Wolfram|Alpha is very easy; for example, we can plot Archimedes’ spiral.

plot r = theta

Or we can get a little fancier and plot a polar rose with eight petals.

polar plot 2cos(4*?)

Want to know how to graph this in Mathematica? We can easily extract the Mathematica code for this plot right from Wolfram|Alpha. By clicking the dog-ear in the bottom left of the images and then “Copyable plaintext”, you can see the Mathematica code used to generate the plots.

PolarPlot[2cos4?],{?, -pi, pi}]

Polar rose with 8 petals

Here are some other awesome polar plots:

The plot of a lemniscate:

Lemniscate

And a lituus:

Lituus

And a cochleoid:

Cochleoid

Wolfram|Alpha can also handle more complicated inputs, like r(?) = exp(cos(?) - 2 cos(4?) + sin (?/12)^5:

plot r(?) = exp(cos(?)) - 2cos(4?) + sin(?/12)^5

Now that you have seen some great examples of polar plots, let’s move on to parametric plots.

What is the difference between a polar and parametric plot? Parametric coordinates specify points (x,y) in 2D with two functions, (x,y) = (f(t), g(t)) for a parameter t. Here are some examples of 2D parametric plots to try in Wolfram|Alpha.

Try to make a parametric plot of (x(t), y(t)) = (1-t,t2).

parametric plot (1-t, t^2)

We can easily see that this is the same as the Cartesian equation y = 1 - 2x + x2. (x(t) = 1 - t ? t = 1 - x(t) so y(x(t)) = (1 - x)2 = 1 - 2x + x2)

In the above example, we didn’t even need to enter a plot range; Wolfram|Alpha picked the plot range that best suits the graph. Of course, it’s possible to specify a range for the parameter, in this case we plot (x(t), y(t)) = (sin(t), sin(3t)) for t from 0 to 100.

parametric plot (sint, sin(sqrt(3)t)) for t from 0 to 100

Now let’s look at some other cool plots that Wolfram|Alpha can create.

How about the parametric plot of the astroid:

Astroid

Or a similar plot, the deltoid:

Deltoid

If we had just said “plot” instead of “parametric plot”, then Wolfram|Alpha would have returned a Cartesian plot of 4cos(?) + 2cos(2?) and 4sin(?) + 2sin(2?), as well as a parametric plot of the deltoid.

Want some more examples? Check out these classic examples of parametric plots (the tractrix, fish curve, Tschirnhausen cubic, and Plateau curves, respectively):

In the previous plotting post, you had the opportunity to learn about 2D Cartesian plotting in Wolfram|Alpha, and now you are equipped with the ability to make 2D polar and parametric plots as well. Luckily, Wolfram|Alpha doesn’t stop there; start playing with some 3D graphs and it will not let you down!