Latest Tweets:

*5
Helping old people with computers…

Helping old people with computers…

*2

bc Hates Floating Points in Linux

Whenever I need to do complex math, I usually turn to my smartphone. I found this great scientific calculator on Google Play that does just about everything I need.

But sometimes, I need to do math in a Linux script. Then, I turn to the program bc. bc is a cool program, but as I recently discovered it has some surprisingly odd problems.

Surprise #1 - bc doesn’t round, it truncates! One of the nice features of bc is that you can set “scale” to indicate the desired precision the calculations are performed at. For example, setting “scale=100” will perform the calculations to 100 decimal places! Surprisingly, however, bc loads with the scale set to 0! And when I did 1/2, I got 0, because bc calculated the answer to be 0.5 and then truncated the answer to 0 decimal places. bc does not round, at all!

Surprise #2 - bc only has 6 functions! bc is a minimal math program. So minimal that it’s math library only contains 6 functions! You can compute sine and cosine. Oddly enough, you can compute arctangent (which is the only inverse trigonometric function in bc), but there is no built-in function in bc to compute a tangent. You can compute base-10 and natural logarithms. And for all the functions its missing, a true surprise is that bc can calculate Bessel functions.

For the most part, bc seems to be limited to elementary functions on one argument.

Surprise #3 - bc’s power operator only works for whole numbers and cannot be used for roots! While you can compute the fourth power of x with x^4, you cannot compute the fourth root of x with x^0.25. If you try, bc will throw off an error that says “Runtime warning (func=(main), adr=9): non-zero scale in exponent”. This is a really annoying anti-feature. There is no way in bc to compute anything past a square root.

So this evening, I found myself needing to calculate the 35th root of some number, and when i discovered that x^(1/35) does not work in bc and throws off a ridiculous number of errors, I went looking for another solution.

I found the solution in “concalc” another console-based calculator in the Debian repositories. concalc correctly evaluated the expression z*(x^(1/(51-y))) to more decimal places than my scientific calculator could. And the best part was, I didn’t have to split the calculation up into multiple calculations the way I used to have to do in bc. Looks like concalc is going to replace bc for my floating-point math now.

z-co:

one of my coworkers got a call (i work in a call center/tech support) from a customer that was really scared because supposedly the mafia was hacking her computer and they were stalking her…when finally my coworker took remote control of the computer he couldn’t stop laughing because

image

That is priceless. You should have told her that the mafia only comes when she presses the “Any” button.

(via 0110000101111000)

I’m getting sick of Windows commercials.
Internet Explorer is not that cool!
Updates have never downloaded to a Windows computer that fast EVER, and it’s not likely to start getting that fast any time soon.
And now, Microsoft is trying to undo the horrible mistake that was Windows 8, suddenly I’m seeing Windows 9 commercials? And they are filled with previews of things that haven’t hit the market yet, so in a classic Microsoft manner, they are over-dramatized to make you think they can do anything!
Oh, now there’s a Metro-fied Start menu! Apps that seem to load at the speed of thought!

People DANCING while using their computer, because Windows users are apparently so hyper they don’t actually sit in front of their computers.
Oh, now everything won’t run in full-screen, so I can have multiple things running on the same screen! I can do so many things now on an 17 inch screen, it’s so amazing!! <sarcasm>Can I get a KAWAIII please?</sarcasm>
Oh, and let’s make Internet Explorer look cool in all the advertisements. Your bank will be so impressed you are running Windows, they might even give you extra money!!
Windows9 must be able to do anything!! And I sit back and patiently mute my speakers until the advertisement is over and I’m like, “REALLY!?”
Please stop Microsoft. IT’S NOT GOING TO HAPPEN!

I’m getting sick of Windows commercials.

Internet Explorer is not that cool!

Updates have never downloaded to a Windows computer that fast EVER, and it’s not likely to start getting that fast any time soon.

And now, Microsoft is trying to undo the horrible mistake that was Windows 8, suddenly I’m seeing Windows 9 commercials? And they are filled with previews of things that haven’t hit the market yet, so in a classic Microsoft manner, they are over-dramatized to make you think they can do anything!

Oh, now there’s a Metro-fied Start menu! Apps that seem to load at the speed of thought!

People DANCING while using their computer, because Windows users are apparently so hyper they don’t actually sit in front of their computers.

Oh, now everything won’t run in full-screen, so I can have multiple things running on the same screen! I can do so many things now on an 17 inch screen, it’s so amazing!! <sarcasm>Can I get a KAWAIII please?</sarcasm>

Oh, and let’s make Internet Explorer look cool in all the advertisements. Your bank will be so impressed you are running Windows, they might even give you extra money!!

Windows9 must be able to do anything!! And I sit back and patiently mute my speakers until the advertisement is over and I’m like, “REALLY!?”

Please stop Microsoft. IT’S NOT GOING TO HAPPEN!

*1

Advanced BASH Scripting - Colors!!

I first became intrigued by colorizing BASH when I saw other Linux users customizing their shells with color.

And customizing a PS1 prompt was quite simple. For example, my first PS1 looked something like this.

export PS1="\[\e[00;31m\]\u\[\e[0m\]\[\e[00;37m\]@\[\e[0m\]\[\e[00;31m\]\h\[\e[0m\]\[\e[00;37m\]:[\w]\[\e[0m\]"

But if you wanted a custom prompt, the coding for the PS1 and the colors could get confusing. Sometimes I would end up breaking the PS1 because I put a bracket or a semi-colon in the wrong place.

The solution to this was to define the colors separately and then use them in the PS1. Then it was more human-readable. So it would look something like this:

Color_Off='\e[0m'
White='\e[0;37m'
Green='\e[0;32m'
Red='\e[0;31m'
BBlue='\e[1;34m'
BHIWhite='\e[1;97m'
PS1="${debian_chroot:+($debian_chroot)}\[$White\]\d \[$Green\]\t \[$Red\]\u\[$White\]@\[$Red\]\h\[$Color_Off\]\[$BBlue\]:\[$BBlue\]\w \[$BHIWhite\]\$\[$Color_Off\] "

Then customizing the prompt and colors became child’s play. The issue I kept running into was how to find all the colors I could use.

Google helped me supply the initial answer. According to TLDP BASH supports ANSI codes that you can play with to tweak out the colors. These ANSI codes appear quite limited. In most tutorials I found online, the tutorials only touched on using 2 ANSI codes (attribute code, color code), and some touched on using 3 ANSI codes (attribute code, forground color, background color).

But the main hindrance is that no tutorials went beyond that. They all seemed content with stopping at the basics and going no further. In fact the article at TLDP says very specifically “There are no bold background colours.” (NOTE: THIS IS NOT TRUE!!)

Nor did any tutorial mention any other ANSI codes that generated color.

Through all my searching on Google, I was only able to come up with a limited number of ANSI codes. They are as follows:

0 = default colour
1 = bold/intense
4 = underlined
5 = flashing text (but most Terminals don't support blink, and instead just make the text lighter)
7 = reverse (foreground becomes background)
8 = concealed
9 = strikethrough
30 = black 31 = red 32 = green 33 = orange 34 = blue 35 = purple 36 = cyan 37 = grey
40 = black background 41 = red background 42 = green background 43 = orange background 44 = blue background 45 = purple background 46 = cyan background 47 = grey background
90 = dark grey 91 = light red 92 = light green 93 = yellow 94 = light blue 95 = light purple 96 = turquoise
97 = white
100 = dark grey background 101 = light red background 102 = light green background 103 = yellow background 104 = light blue background 105 = light purple background 106 = turquoise background

So for blue text on a gray background, you would use

\e[34;47m

And if you want bold blue text on a gray background, you would use

\e[1;34;47m

The most interesting thing I noticed was that 5 (blinking), didn’t blink in most Terminals, and instead tweaked the color to be a little lighter. The color produced the blink modifier was not usually as bright or intense as 2 (bold/intense) though. So using 5 could open up more color possibilities.

The problem I ran into is that sometimes a code will react differently than expected. For example, Blue text on a white background?

\e[34;37m

would do the trick. But, what about bold blue text on a white background? You might think it was

\e[01;34;37m

but it’s not. In that case, 01 changes the color of the foreground instead of making the text bold. So that makes light blue text on a gray background!

But how to make BOLD blue text on a white background? According to TLDP, it’s impossible. “There are no bold background colors.” And other sites indicate that sometimes it’s sometimes impossible to get bold foreground with certain background colors enabled.

However, this isn’t entirely true…

The trick is to use 07 (reverse) which reverses the foreground and background colors. For example, blue text on a white background? Like I showed above

\e[34;37m

would do the trick but also

\e[07;37;44m

would do it.

Now this can give you a headache when you look at it, but it opens up some more options in colorization. 44 is a blue background color, and 37 gray foreground, but when you put them together with the 07 modifier it reverses the properties so 44 becomes a blue foreground color!

I was puzzling over how to get bold text on a background color. I wanted bold black on gray. It turns out that BASH can support 4+ ANSI codes to define a color! If you thought 3 colors was a headache, this is even more so! But the results are worth it!

It turns out you can keep adding modifiers to tweak the color. So for bold black on gray, you can use

\e[07;01;90;40m

or

\e[01;07;90;40m

But wait!! THERE’S MORE!!

There are even more colors possible! It turns out there is a sweet ANSI spot that contains 256 colors! And that sweet spot is

\e[38;05;{1..256}

Do you want to see all the colors? Open your Terminal and type the following. This will output a amazing color rainbow!

for c in {0..255}
do
echo -e "\e[38;05;${c}m ${c} Moar Colors!!"
done

Now that you know that PS1 and LS_COLORS can support so many ANSI codes, go configure your BASH!

fastcompany:

The partnership could have huge implications in the development of tiny, invisible computers.
Read More&gt;

Where do I have to get in line to get my HUD installed?

fastcompany:

The partnership could have huge implications in the development of tiny, invisible computers.

Read More>

Where do I have to get in line to get my HUD installed?

(via futurescope)

Proxy Glider

Anonymous said: what are the social networking sites that violate privacy ??

Networking is the act of connecting with people to exchange information.

When posting information to a social network, a user probably expects authorized contacts to be able to view it. The simple act of networking presumes that you are giving up the right of total privacy. In order to network, even with close friends in a closed network, you must give up some privacy. Most people expect this, and are willing to give that up. Thus, ALL social networks violate privacy to some extent.

The danger, however, is when social networks allow more information to pass through to the public than the user anticipated. Social networks that provide their services without fees usually make a profit by selling advertising. This is often done through behavioral advertising, also known as targeting. Behavioral advertising is the term used to describe the practice of tailoring advertisements to an individual’s personal interests. Social networks collect lots of information about potential customers and these profiles are repeatedly mined by advertisers trying to create targeted advertisements.

In the end, it is unfair to place blame on any particular social network as a privacy violator because ALL of them are guilty. Yes, undoubtedly, some networks are more or less responsible than others, but this generally a personal choice that must be made by each individual user.

The key to maintaining privacy is:

  1. Don’t post anything online! A good rule of thumb, no matter what the situation, is: “Don’t post anything (even privately) that you wouldn’t be comfortable being public.”
  2. Determine the content control and privacy safeguards of a social network, and choose a network that matches your needs. Don’t join networks just because your friends recommend them. Figure out first whether the network is a good choice for you.
  3. Post anonymously. There are plenty of forums and networks that allow users to post anonymously.

"I must sleep… it’s working… just three more hours…"

Commit message from http://goo.gl/Gzi9t5

"Tweaking leads to twerking. As indeed, does Googling error messages."

Commit log message for http://goo.gl/1PJZeI

mostlysignssomeportents:

I gave a talk last month in Cambridge at the Tedxoxbridge event called How to break the Internet, about how urgent it is that the Internet is fundamentally broken, and why we should be hopeful that we can fix it.

(via futurescope)

Rock-Solid Stable (with Sid)

I’ve been using Crunchbang (also known as #!) for several months now, and for a while it was good. #! was very flexible, but stable. But maybe a bit too stable if that’s possible.

#! uses Debian Wheezy and Crunchbang Waldorf repositories. But when I started looking for packages that I had used on Linux Mint, I couldn’t find the packages. Turns out these packages were in the Debian Jessie repository.

So I would add a line to my sources.list so I could get access to jessie. I would get the package I was looking for, but there were problems. The very next time I ran apt-get upgrade, the new repos would exert their influence on my computer by upgrading practically every package to the highest level. Then my computer would get odd problems, which is what generally follows when you run a not-stable source.

Needless to say, over the past several months, I’ve had plenty of time to experiment. I’ve (intentionally) destroyed a bunch of Crunchbang systems, just so I could put them back together again. And I’ve learned a lot about how to keep #! stable, and yet still permit the use of Jessie and Sid sources.

My first trick involves a process called “pinning”.

So, the first thing I did was add the deb and deb-src lines for both unstable (Jessie) and testing (Sid) to your sources.list at /etc/apt/sources.list. So it will look something like this…

image

Next, I close and save that file.

Now edit /etc/apt/preferences

Generally speaking, Ubuntu and Mint users don’t mess with their preferences files too much. This wasn’t even a trick I learned until I switched over to a rolling Debian release.

The preferences file contains instructions (called pins) that modify the version control settings that APT uses. Specifically, you can use preference pinning to instruct your system to use, optionally use, not use, a particular repo or package. You can instruct your system to freeze a particular repo or package at a level, and not accept upgrades.

What I did was instruct my system to not accept upgrades from any unstable or testing source (leaving me getting upgrades only from stable). So my preferences file looked like this when I was done.

image

As you can see, jessie and sid, testing and unstable, sources are pinned at -10. A pin level less than 0, prevents this source from being used in upgrades.

So now I can have access to those sources, without needing to risk my system becoming unstable in an upgrade.

I know that I’ve succeeded when I can run an apt-get upgrade and apt-get dist-upgrade and have 0 packages needing updates (because only stable is being used for upgrades).

But, I always go one step further…

For my second trick, I go back to my sources.list and I comment out the deb lines for Jessie and Sid, leaving only the deb-src lines open. So, now my sources look like this:

Now I have access to only the sources on Jessie and Sid.

What use is this? Well, firstly, this means that Jessie and Sid will never affect my system stability in an upgrade, because only the deb lines download packages during upgrades. Secondly, this still allows me access to Jessie and Sid, but in a special way… I can compile my own programs and backport them to Wheezy.

For more information on how to backport a package, check out this link: https://wiki.debian.org/DebianUnstable#How_do_I_backport_a_sid_package_to_testing_or_stable.3F

Basically, what you do is:

  1. Download the sources from Sid, and install any needed dependencies from Wheezy repos.
  2. Compile the source for Wheezy.
  3. Install the resulting package.
  4. Voila! You now have an upgraded program on Wheezy, with no dependency problems.

Note: this method of upgrading will not upgrade the resulting program until that particular version trickles down from sid and reaches stable. But, if there is an upgrade, you can always compile and install it again!

Now, I’m enjoying a stable system, and I can still get some bleeding-edge packages from Sid.

fastcompany:

Now that Google is allowing anyone with a cool $1,500 lying around to score themselves a pair of Glass, you’ll probably start seeing a lot more tech geeks wearing headsets in public talking to themselves. Our hands-free, hyper-tethered future is well on its way! So if voice command interfacing is the wave of the future, what good is something seemingly as reductive as an input keyboard?

That was my question—and guessing I wasn’t alone—until I saw Minuum.

Read More>

That is awesome!

(via futurescope)

cypher-neo (Sean Murphy)