Thursday, March 28, 2013

Manipulate Checkboxes On Any*** Page

Copy and paste the following line into your browser address bar: 

javascript:[].forEach.call(document.querySelectorAll('input[type="checkbox"]'),function(el){el.checked=true});



*** Will not work for older versions of (Internet Explorer) IE
(1) document.querySelectorAll not available untile IE v8
(2) forEach not available until IE v9 

The use of a JavaScript toolkit/framework, e.g., JQuery, relieves the developer from having to worry about incompatibility issues like the ones mentioned above.


Verify that your browser didn't automatically remove the "javascript:" from its address bar, assuming you copy/pasted the javascript.  If so, then just hand-type javascript: at the beginning and press your enter key.

Test it out here:



Alice
Bob
Cindy



JQuery Set all Checkboxes Version


If the page already has JQuery loaded, then you have less to type...

javascript:$(":checkbox").prop("checked", true);


You probably noticed that this didn't work on this blog page.

That's because this page is not using (and has not loaded) the JQuery library.

So, to dynamically load JQuery on a page, e.g., this blog page, paste the following in the address bar:



javascript:(function () {
  var s = document.createElement('script');
  s.type = 'text/javascript';
  s.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js';
  document.getElementsByTagName('body')[0].appendChild(s);
})();$(":checkbox").prop("checked", true);




Sponsor Ads



-->
-->

Wednesday, March 27, 2013

How to Install NodeJS on CentOS


NodeJS is currently not part of the CentOS standard repo's

Give it a try:

# yum install nodejs
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cat.pdx.edu
 * extras: mirrors.cat.pdx.edu
 * updates: mirrors.cat.pdx.edu
Setting up Install Process
No package nodejs available.
Error: Nothing to do



Solution

Install NodeJS from sources.


Install Dependencies


# yum install openssl-devel
# yum install gcc-c++
-- OR -- 
# yum groupinstall 'Development Tools'


Install NodeJS

# mkdir ~/sources
# cd ~/sources
# wget http://nodejs.org/dist/node-latest.tar.gz
# tar zxvf node-latest.tar.gz
# cd node-v<TAB>
# ./configure
# make
# make install
# mv /root/sources/node-v0.10.1/out/Release /opt/node-v0.10.1
# ln -s /opt/node-v0.10.1/node /usr/bin/node

NOTE:  When you cd to the newly created directory, type "cd node-v" and then hit your TAB key for tab completion.  The full directory name will be something like /root/sources/node-v0.10.1


Test NodeJS

# node
v0.10.1

Sponsor Ads(Please visit one if you liked this article. Thanks!)

Sharing Bash Functions

Intro

In order to share a bash function between all logins you can insert the function in /etc/bash.bashrc and source it in /etc/profile.

Example

In order to share a members function that all users can execute to find which users belong to a particular unix user group, then do the following:

/etc/bash.bashrc


members()
{
   cat /etc/group | grep --regex "^$1:.*" | awk -F: '{print $4}'
}

/etc/profile

# ...
source /etc/bash.bashrc


Now, when any user logs in they will be able to run members like this:

$ members users
alice,bob,cindy




Sponsor Ads


Tuesday, March 26, 2013

Getting the Right OS Version for Your VPS

If you use as many VPS services as I then you'll find that some come with very old versions of CentOS.

There may be a good reason for that.

Depending of the version of the paravirtualization-capable hypervisor used by your host provider, you may need to use/install/update an older OS version that is compatible with your hypervisor.

One of my favorite hypervisors is Xen.

One of my favorite OS versions is CentOS.

So, If you need an older version of CentOS for your VPS, then check out http://mirror.teklinks.com/centos/

It took me a while to find that resource.  Most CentOS mirrors seem to only provide the lastest version and README that says the version you're looking for has been deprecated.

I hope this saves you some time.

Sponsor Ads


How to Use Reverse Port Forwarding to Run Commands on Your Natted Server

Introduction

Have you ever wanted to run (remote) commands on a computer that sits behind a natted firewall, i.e., your computer at home that has a private IP (in the 10.x.x.x or 192.168.x.x range) from another server (Perhaps, from your server at work)?

One issue, for your connecting to your server, is that your home computer's IP not directly accessible from the public internet.  Your internet provider, e.g., ATT or Comcast, may have a cable modem that has a public IP Address (which you can see at http://www.whatismyip.com/), but that public aka WAN IP Address does not get you all the way to your computer.

One solution is to leverage ssh's reverse port forwarding feature to open a terminal session to your work server, which has a static IP address.  This will open an SSH tunnel through which you can later push commands from your work server to your home computer.


Assumptions


Your work server name is workserver.  Note:  You can put this convenience domain name in your /etc/hosts file s.t., you don't have to enter that IP Address over and over again.

The (reverse) port number used for pushing commands from your work server to your home computer is 20022.

The port number that you have configured to accept SSH requests on your work server is 30022.


Commands

Run the following command to open the magical reverse tunnel:

[username@homecomputer ~]$ ssh -R 20022:localhost:22 workserver -p 30022



[username@workserver ~]$ ssh localhost -p 20022 "echo 'I am running on `hostname`' "

This will print:  I am running on homecomputer



Debugging SSH


When working with SSH it is often helpful to run the SSH client and SSH server daemon in debug mode.


Debugging SSH  Client

Just put the -v parameter to turn on verbose output:

ssh -v localhost -p 20022


Debugging SSH Daemon

Run the SSH Server in debug mode:


[root@homecomputer ~]# /usr/sbin/sshd -d

Back to Normal

Run the SSHD normally:

[root@homecomputer ~]# /etc/init.d/sshd reload




Sponsor Ads


Saturday, March 16, 2013

Facebook Privacy and the Latest Hoax


I've seen a couple of folks requesting me to UNCHECK "LIFE EVENTS" and "COMMENTS & LIKES" for privacy reasons (see below).

So, I researched it and found that it's a HOAX.

Bottom line: Don't uncheck "LIFE EVENTS and "COMMENTS & LIKES" .. b/c if you do, it just means that you won't be seeing that particular friends "LIFE EVENTS and "COMMENTS & LIKES". Facebook is not posting your information to anybody that you haven't already shared your information with.



BOGUS HOAX BELOW:

Just so everyone on my friends list knows that I completed this and I am done! Facebook has changed their privacy settings once more!! Due to the new "graph app" anyone on facebook (including other countries ) can see your pictures, likes & comments. The next 2 weeks I will be posting this, and please once you have done it please post DONE!!! Those of you who do not keep my information from going out to the public, I will have to DELETE YOU! I want to stay PRIVATELY connected with you. I post shots of family that I don't want strangers to have access to! This happens when friends click "like" or "comment"....automatically, their friends would see our posts, too. Unfortunately, we cannot change this setting by ourselves because Faceboook configured it that way. PLEASE place your mouse over my name above (DO NOT CLICK), a window will appear,now move the mouse on "FRIENDS" (also without clicking), then down to "settings", click here and a list will appear. REMOVE the CHECK on "LIFE EVENTS and "COMMENTS & LIKES". By doing this, my activity among my friends and family will no longer become public. Now, copy & paste this on your wall. Once i see this posted on your page, I will do the same





How to Protect Your Privacy on Facebook


There are two main ways to safe guard your personal information on facebook.


1. Update your Privacy Setting to “Friends Only”

To do this, go into your Personal Profile,  click on the gear wheel on the top right hand corner of your screen then click on privacy settings. You can edit all your settings there to be “Friends only” or “friends of friends”.



2. Stay off Facebook

You may think that Facebook, Google and GMail and similar online services are "free".  The fact is they profiting from using your private data.  This practice is called “Data Mining”. Google uses Data Mining everyday when it serves up its Ads.  Highly personalized marketing is effective. So if privacy concerns you, you need to seriously consider getting off the Internet all together.





Summary


This is not my typical software development posting, but it does make the think about the social applications that I develop and the fact that nefarious users may try to abuse my applications in order to create mayhem and confusion.  This is a new socia media type of security concern. Similar security counter measure analysis techniques apply to prevent this sort of events from adversely an application's user population.



References


http://www.facebook.com/help/privacy

https://www.eff.org/deeplinks/2013/01/how-protect-your-privacy-facebooks-graph-search

http://www.nytimes.com/2013/02/07/technology/personaltech/protecting-your-privacy-on-the-new-facebook.html?_r=0


Sponsor Ads(Please visit one if you liked this article. Thanks!)

Thursday, March 14, 2013

JavaScript Performance Montior


stats.js

JavaScript Performance Monitor

This class provides a simple info box that will help you monitor your code performance.
  • FPS Frames rendered in the last second. The higher the number the better.
  • MS Milliseconds needed to render a frame. The lower the number the better.

Screenshots

stats_js_fps.pngstats_js_ms.png

Usage

var stats = new Stats();
stats.setMode(1); // 0: fps, 1: ms

// Align top-left
stats.domElement.style.position = 'absolute';
stats.domElement.style.left = '0px';
stats.domElement.style.top = '0px';

document.body.appendChild( stats.domElement );

setInterval( function () {

    stats.begin();

    // your code goes here

    stats.end();

}, 1000 / 60 );

Reference

https://github.com/mrdoob/stats.js

Sponsor Ads