FINALLY! SOME UPDATES! This website is being reconstructed. Some content will go away soon. If you want to see my new stuff, visit my github: https://github.com/jrcharney/.

September 19, 2012

Compy is sick

My hardworking netbook, my lifeboat until I can afford the parts to fix up my desktop, is currently down for the moment until I can get a couple of new parts for it too.

What's wrong with it? The simple explanation is that your computer should never make burnt toast smells. The more technical answer: I need to replace the fan and the heat sink and check to make sure that the magic smoke doesn't come out. I also had to use a Dremel tool to cut out the big screw that holds the harddrive in place. (ATTENTION AMATURES: DO NOT DO WHAT I DID! You could destroy your computer from the sparks that shoot out from using the grinding tool!) Fortunately, nothing was damaged and I took precautions to protect the other components of the computer including the screen, the mouse, and as much other areas as possible.

So that this point, a can of compressed air is useless so I sucked out much of the crap with a regular vacuum. (Never use a Shopvac!) Again, a risky move but it was worth it.

So my computer is all cleaned up, reassembled, and for the most part works, but I can't use it. Because as soon as I performed all this much needed maintenance and put everything back together, the fan was making loud whirring sounds again and that slight burning smell came back. So, it is off until further notice. Expect pictures though and some hardware hacks in the next few posts. I might just open like a Imgur account to host all the pictures, at least until I figure out a way to write my own software to resize and display images.

So what's my back up plan until then, and more importantly, if my computer is off, how am I posting this post? The great Reverent Kyle posted this video a while back so, my HP Touchpad is acting as a dummy terminal. My current app of choice: AirTerm. Connectbot and Tmux aren't simpatico with one another even with Hacker's Keyboard installed. AirTerm also has a few things I really don't like like things that make it so easy to accidentally close AirTerm. I hope future versions of AirTerm fix this. I'm hoping to finally getting around to setting up my servers local .vimrc file such as enabling spell checking (:set spell), enabling syntax highlighting (:syn on) and having new windows appear below current windows rather than above (:set sb).

There is one flaw to Reverend Kyle's dummy terminal hack: You are still running on the Touchpad's battery. Hoping fix this issue, I've ordered a Female-to-Female connector to determine why Kyle never used this method. Perhaps part of HP's hubris was that they made the Touchpad's charger and USB cable explicitly for the Touchpad. I asked one person what they though was the reason and they said that the Touchpad's power cable was thicker than a regular USB Cable which isn't true because I have several other USB-to-USB mini cables made by other manufactures and the Touchpad's USB cable is much thinner than than those cables. So, If my theory is correct, I could trick the Touchpad into using the powered USB multiplexer that I am using to plug a mouse and keyboard into the multiplexer to be used as input devices for the Touchpad.

I've also had success with the multiplexer to charge a Sony PlayStation 3 controller for which it's been a while since I've used the joystick hack that allows me to play videogames on the Touchpad. I should really make a post about that in the future.

I've already used about half of my Touchpad's energy writing this post. (Timestamps generally indicate when I've started writing.) Perhaps its just me or the Cyanogenmod folks finally figured out how to improve the battery life on the Touchpad. It's life lasts much longer if you turn off synchronization. The downside is that you don't get to see any email updates. I'm going to put this thing on its charger and probably plug in the computer keyboard later.

September 18, 2012

Bash Conditional Operator

Working on the new.sh and new_c.sh projects today, and I though it was about time to resolve a vexing issue: can bash execute conditional operations like in several other programming languages like C, C++, Java, PHP, etc.?

The answer is a resounding "YES!"

Firstly, what is the conditional operator? The conditional operator is the ternary operator that many programming languages have to execute an "if-then-else" (or "if-else" if you prefer to say it like that), in a single line. The following figure demonstrates its usefulness.

Without ?: With ?:
if ( a == b ) {
 return x;
} else {
 return y;
}
return ( a == b ) ? x : y;
The code on the right eliminated four lines of code.

Sure, you can argue that you could write the code on the left as

if (a == b ) { return x; } else { return y; }

But look how much better the code on the right looks. Add to that, only one return is used.

Commonly, the conditional operator is use for conditional assignment, as demonstrated in the next figure which looks quite similar to the previous figure.

Without ?: With ?:
if ( a == b ) {
 c = x;
} else {
 c = y;
}
c = ( a == b ) ? x : y;
Conditional assignment, FTW!

In some languages, assuming they got their order of operations right, you could even get away with this line of code.

c += ( a == b ) ? x : y;  // c = c + (x or y)

I know this isn't a big deal if C, C++, Java, JavaScript, or PHP are you forte, but but what about Bash? Bash is so literal at times.

Let's take the following code example. This next figure demonstrates a Bash, if-then-else statement, assuming we don't add any short cuts to the syntax.

if [[ $a -eq $b ]]
then
 c=$x
else
 c=$y
fi
See how much space this wastes?

Most of the time you can add a semicolon between the right test bracket. You can also do this with for, while and until loops with the do keyword.

if [[ $a -eq $b ]]; then
 c=$x
else
 c=$y
fi
Subtile.

So we made no significant change to this line of code. But we're only doing one thing. Let's flatten this to one line, like if we were trying something out in the command line.

if [[ $a -eq $b ]]; then c=$x; else c=$y; fi
Take note of where the semicolons are!

So we've managed to whittle this down to one line, but those keywords are still there. Here's where the magic happens.

[[ $a -eq $b ]] && c=$x || c=$y
I will now make the keywords disappear! TA DA!

"But this doesn't look like the condition operation syntax", I hear you cry. Well, let's make it look like it.

c=$( [[ $a -eq $b ]] && echo "$x" || echo "$y" )
The final form, at least for this example.

Now, I see there many be a few folks dissatisfied that a couple of echo commands got in there. There is of course this alternative.

function getX(){
 echo "$x"
}

function getY(){
 echo "$y"
}

c=$( [[ $a -eq $b ]] && getX || getY )
It looks like a conditional assignment to me!

or even

function getX(){
 c=$x
}

function getY(){
 c=$y
}

[[ $a -eq $b ]] && getX || getY
I'm pretty sure this works.

But honestly, I'm content with either of the following two forms.

 [[ $a -eq $b ]] && c=$x || c=$y 
 c=$( [[ $a -eq $b ]] && echo "$x" || echo "$y" )
They both work, and that is good enough for me!

At any rate, I'm considering practicing this syntax in the future, maybe even in the latest version of the new and new_c programs.

September 16, 2012

A couple of things.

OK, I though about it. My first though was modifying the syntax highlighting in .rc files by using the following command in vim.

:set syntax=sh

But then I realized that .rc files are ment for configuration like ~/.bashrc, so I renamed my module files bach to .sh files. Either way they worked.

Of course, if you want to rename all the files in a directory you will probably need to use the following command.

for i in *; do mv $i ${i/%.rc/.sh}; done

Included bash scripts do not need to be set to executable and in you don't need to modify $PATH to include another file. (Or at least you shouldn't. YMMV.) Interestingly enough, you don't need to put #!/bin/bash at the top of the included files either.


source inc/man_new.rc                   # contains the manual help data
source inc/std_new.rc                   # contains the functions all the other modules use
source inc/new_headers.rc               # contains the compose_headers functions
source inc/new_includes.rc              # contains the compose_includes functions
source inc/new_bodies.rc                # contains the compose_body and compose_footer functions

Just a preview of inside new.sh v3.0a where all the new source are.

As I stated earlier, the downside is there is more than one file now. The upside, the code looks more professional and works just as it would in some big 500+ line behemoth. It's a coding practice you should also consider. I mean, I'd like for new_c.sh to use the same inc/std_new file in the near future. And it is becoming more likely that new.sh and new_c.sh will be bundled into the same tarball package in the near future. Stay tuned.

September 16, 2012

Project status update

Just incase anyone was wondering "Hey, where's the new verson of [insert program here]" here's a little status update.

The next version of New.sh has been split into modules. I wasn't sure if I should have named the smaller include files as .sh or .rc, but I'm thinking of trying out releasing new 3.0a as a tarball rather than just a shell script. Basically, the same newy goodness with includes like new_c like I've been bragging about the past couple of months.

The next version of New_c.sh might also be split into modules. I might add the libraries for integrating Python, MySQL, Ruby, and Perl. Don't forget OpenGL and NCurses should be in the next version.

I want to do something with Poly.js this week. I had planned on doing something with it but my netbook conked out. I like the old way of inputing paths that SVG did so I'm writing a new method to update path points with instructions to behave sort of like that with some extra features.

Other than that, short and sweet. More updates soon.

September 13, 2012

The next big project: Mental Mathematics

It's a little know fact that computer science is a field that spurs from mathematics rather than information technology. This might explain when I pick up a book about A+ Certification it feels like a bloated watered down version of a For Dummies book, and yet I feel that if I want to earn or renew certification. (Really, you get to take the test all over again every three years! Imagine if colleges made you do that! There'd be riots in the street!) The reason they want you to renew really has less to do about learning new technology and more about making a profit.

However, if there is one thing that can never be taken away from you is your education. Which is why I'm interested in offering some support and advice on an array of mathematical topics in this new project that is meant to promote the use of mental mathematical calculations.

It is a subject I take quite seriously especially since a lot of the technology that we use is too fragile. What really motivated me to take up this project is the fact that during my senior year of college, I was conversing with a first or second year student who mentioned that her brother was looking at colleges, but he couldn't do basic arithmetic without a calculator. Even more disheartening was learning that my high school math club had disbanded. (Hey, there is much advantage to that. You could get an excuse from one class to take an even harder test once a month. So what if you got the answer wrong. You learned something from it later.) One of the biggest shockers while doing this was discovering that some of the teachers at a regional math competition did not understand the concept of double series, which in computer science can be explained quite simply as one for loop inside of another for loop.

var x = new Array(m);	// x has m elements
var y = new Array(n);	// y has n elements

/* some data to put into arrays x and y */

var sum = 0;
for(var i = 1; i <= m; i++){
 for(var j = 1; j <= n; j++){
  sum += x[i] * y[j];
 }
}
A bit of code that explains figure #2 from this page.

It was also some time around my last couple of years of college that I learned about how computers added, subtracted, and multiplied (computers don't divide, they just calculate the inverse of the divisor and multiply by a fraction of a number), as well as other methods to mentally calculate multiplication and division but are rarely taught these days to children as the calculator and the computer have made young generations of teachers let technology show the answer than have students make mistakes and verify their own work let alone teach cursive penmanship.

So I'm thinking over the next few years I work on something bit by bit to provide a comprehensive knowledge of mathematics that should be done mentally or at least written down in a notebook. It's something I've though about for a while especially after proving how Jill.js work by creating some mathematical examples. I still want to figure out how to get Canvas to produce fractals using HTML5 Canvas' ImageData object. It is quite possible.

So I just wanted to make an announcement about this project. I'm thinking of using MathJax instead of jsMath because it doesn't require you to download TeX fonts and it supports MathML and LaTeX. I'm quite comfortable with using LaTeX since Wikipedia (and to that extend MediaWiki) use LaTeX for most of their math codes. I haven't really decided yet.

Tags

Under Construction