# Ninja Tricks

## November 11, 2006

### BC

Filed under: B, Mathematics — thelaziestninja @ 1:37 pm

Ever want to use a simple calculator while programming? Mathematica cost too much money? Xcalc look too goofy, and gcalctool too difficult to remember? Well, have I got a simple program for you! As far as I am aware, most major Posix distributions come with a command-line calculator called “BC.” It’s great for simple number crunching and can deal with n-digit floating point operations. It’s similar to mathematica, matlab, etc. in that it can store temporary variables, write functions, and work with arrays. Reading through the man page again, bc’s actually a simplified version of C, allowing for loops, comments, and so on. Of course, I’ve never used it to these capacities, but maybe you will find it more interesting! So far, I know that bc comes standard with Debian, Ubuntu, and FreeBsd.

\$ bc – run bc from terminal
3+1 – type in an expression

4.3333 – 2.22 – I have noticed that decimal operations do not work if we are dividing

> 2.1133

(55 % 9) – 3 – The percent sign is the operator for “modular,” which, more or less means “give the remainder”

> -2

x=46; x+2 – As described before, you can define variables. Also, as with bash, a colon separates statements.

> 48

### Shutdown

Filed under: OS, S — thelaziestninja @ 9:13 am

Terminals are my favorite means of communication with a computer. Consequently, I really hate being forced to find a start menu/gnome menu/k menu/apple menu/other nonsense when performing simpke tasks. In particular, I found that it would be extremely useful if I can shutdown a computer from a command line, rather than through said annoying menu. Hey, maybe I’m just not a mouse kind’a guy.
Posix
The command for Posix systems is pretty simple. The command “shutdown” takes at least two parameters, one being the time that you wish to shutdown the computer. Generally, this is set to “now,” but should you want to warn users logged in to the system, or at least give them some time to save their work, giving another time frame may be best. The first parameter, a flag, must indicate what sort of shutdown you wish to perform. For example, -h halts the computer, i.e. turns it off, while -r restarts said computer. The shutdown program requires super user privileges, however, so, unless you change permissions, you will need to use sudo in Ubuntu, Debian, etc. or su root in non-sudo environments.

sudo shutdown -h now

Shuts the computer down immediately.

Windows

Though one might not expect the average Windows user to have a command.exe window running at all times, I know I do. Windows asks for similar parameters, requiring a /s flag for shutdown or a /r flag for restart. By default, Windows gives users about thirty seconds, during which a message will be displayed on their screen, and, should there be a problem, you can abort (/a flag). If you’d rather not wait, you can give a time parameter that will tell Windows to shutdown in a different time period. Unlike Posix, users do not need special privileges (though I haven’t tested this from a “guest” account).

shutdown /s /t 0

Shuts the computer down, beginning in zero seconds