Archive

Archive for the ‘linux’ Category

Creating Hierarchical User Permissions Tutorial

May 11th, 2010

Dealing with multiple users on a single box can be frustrating at first. Especially when they edit the same files. I wanted to create a sort of hierarchy of users with my root and personal accounts at the top, and a pool of sub-accounts below. Here’s how I solved this problem in Ubuntu:

First, create a common group:

groupadd <group-name>

Next, make sure all of the sub-accounts use the new group as its default account.

For new users:

useradd -G <group-name> <username>

For existing users:

usermod -a -G <group-name> <username>

When a user creates a file or directory, they normally would use their own group. What we want is that any account in the common group to use the new group as its default:

usermod -g <group-name> <username>

Last, change the sub-users’ default umask settings so that it treats its own settings exactly the same as the group settings. Make sure to only run this command as one of the sub-accounts:

umask 0002

Now you have a list of accounts with limited permissions that your main account will always have access to. Now this is not an optimal, and probably secure solution, but since this only for my development environment, its good enough.

linux, programming , , , , , ,

NerdTree: Vim Plugin For IDE Style File Editing

April 23rd, 2010

I’ve always been a big fan of VSTreeExplorer since I started using Vim. Recently, I came across NerdTree, which is a much better alternative. It really makes it much easier to manage multiple tabs and sessions and has many more keybindings and mouse interactions making it the closest to the Visual Studios experience in Vim. Here’s a really good animated gif with a basic tutorial on its use:

linux, programming, technology , , , , , ,

Pure Linux DVD Ripping

April 10th, 2009

Whenever I wanted to rip DVD’s for longterm storage, I’ve always used Wine + DVDShrink. I just now discovered a pure linux program, Handbrake, for ripping DVD’s and so far, it has worked out really well This article does a really good job explaining it. Merry Ripping!

linux , , , , ,

Netflix Entry 1: Test runs

December 8th, 2008

I decided for my first 2 entries into the Netflix prize, I would see just how good/bad current scores are. For those who have never heard of the Netflix prize, see my post here.

First, I will predict a 3 for every rating just to see how much deviation there really is from that average ranking. And for my second submission, I just use a random number between 1 and 5 to see how well a random prediction fares with the rest of the leaderboard. After setting those two scripts up and submitting, I never got back a score. I’m not that dissappointed but maybe they saw that i was just sending them random/constant data and decided I was not worth their time. Made me feel kinda sad…

Also, I was having some difficulties initially writing my script in python, so I decided to just hurry up and do it in PHP and then port it python later. The first thing i noticed between the two scripts was just how much faster python is than php. I ran each script three times and calculated the averages. Below are the results:

Language Script Time
Python Constant 30.037 seconds
PHP Constant 40.388 seconds
Python Random 9.312 seconds
PHP Random 19.464 seconds

I know I’m probably beating a dead horse here but python is WAY faster. And nothing really intensive or complex is going on here: string concatenation, random number generation, and writing to a file. That is it. Python performs the constant value prediction ~50% faster and the random value prediction ~25% faster.

As I get more comfortable with python and its vast library of scripts, it will definitely become my goto scripting language. For all you Ruby enthusiasts, especially you, Travis, the ruby language is very well thought out, but until anybody can come close to NumPy/SciPy, I will stick to python for now.

Netflix, linux, math, programming

Replacing Eclipse as My IDE With Vim

November 15th, 2008

Code editors are among the most important applications for a programmers. They are also the source of some the most heated debates online. Whether you use a full-fledged IDE like Eclipse or VisualStudios, or even a souped up text editors like Emacs or Vim, everybody has a favorite. My first IDE was Borland Turbo C and after a couple of months, “purchased” a free copy of VisualC++ (later known as VisualStudios). Finally paid for a student version when my parents found out I was really interested in programing.

VisualStudios was my main IDE until I started web development and moved to Linux. For more than a year now, I’ve been using Eclipse because their plugin system has enabled people to create really good editors for Java, PHP, Javascipt, Flex and HTML/CSS. Because it’s all in one program, the editor is really heavy and fairly bug prone. Recently, I’ve been making the switch from using Eclipse exclusively to moving most of my development to Vim.

Vim is a very good text editor and I chose it ahead of Emacs because in my opinion, the commands are simpler. Most of the common functionality of Eclipse can be found in Vim: search/replace, syntax highlighting, XDebug-ing, and much more. The debate between gui editors or vim/emacs is basically a moot point. They are just tools. Certain people’s thinking patterns are just more suited to one tool than the other. Since I use the command line for almost everything I do, using vim allows a much easier transition between editing files, writing scripts and interacting with remote hosts. For me, vim, along with all of the standard linux apps (find, grep, tail, ssh, scp, etc…), allows me to work more efficiently than any other tool so that is what I use.

linux, programming , , , , , , , , , , , , , , , , ,

Memcached Pool Bash Start Script

November 14th, 2008

If you installed Memcached using Yum under the RedHat flavor of Linux, they have this really nice init.d scripts for starting and stopping Memcache. I modified it in order to support creating a bunch memcache instances using contiguous ports. What’s great is that only the “start” script has to be modified since the “stop” script uses a special RedHat function, killproc, which can accept a program name or path and kill all instances of that program. I’m still a noob at bash scripts but here is my only changes:

NUMBUCKETS=3 #only new value needed
start() {
    for ((i=1;i<=$NUMBUCKETS;i+=1)); do
        FULLPORT=${PORT}${i}
        echo -n $"Starting $FULLPORT ($prog): \n"
        daemon $prog -d -p $FULLPORT -u $USER -c $MAXCONN -m $CACHESIZE $OPTIONS
        RETVAL=$?
    done
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
    return $RETVAL
}

linux, programming , , , , , , , , , ,

Vim Tips

September 23rd, 2008

Since switching to Linux, I have slowly fallen in love with Vim. I love how Vim makes it so that “your hands should never have to leave your keyboard” (Chris). The biggest drawback to using Vim, and Emacs, is that there’s a fairly steep learning curve. You pretty much have to abandon your comfort zone and force yourself to learn all of the different key bindings.

I’m very lucky in that I work with two vim gurus: Chris and Travis. Basically any question I have ever had with Vim, these two were able to answer them. But for times when they are not around I love using these sites:

This is a very short list because Vim is based on a few basic concepts and building on top of that. Once you get the basics, learning how to use buffers and macros gives you the ability to edit your files in any manner.

linux, programming , , , , , , , ,

Useful Linux Commands: Find and Search

September 1st, 2008

Learning Linux commands is probably the largest hump anybody new to Linux faces. Over the last year, I’ve compiled some useful, and somewhat non-obvious scripts that are really helpful to me on a weekly basis. Here are commands that deal with finding files and searching for text within a file:

Find and delete a directory:

find /PATH/TO/DIR -type d -name SEARCH -exec rm -rf {} \;

Find and delete a file:

find /PATH/TO/DIR -name SEARCH -exec rm -rf {} \;

Search within files:

 grep -r "SEARCH" *.EXTENSION /PATH/TO/DIR

Find and search within files:

find /PATH/TO/DIR -name "SEARCH" | xargs -I{} grep -H SEARCH {}

For more advanced options there’s always:

man find
man grep

linux , , , , , , , , , , , , ,

Removing Trackerd

August 27th, 2008

Trackerd is probably the least useful tool that comes with Ubuntu. While indexing, it maxes out cpu and memory. Of course it allows you to search, but the search never finds what I’m looking. In my experience, i’ve found that find and grep are much more useful, especially if its only within a subdirectory.

Trying to remove trackerd is much harder than one would think. Using apt/aptitude proved fruitless since trying to remove/purge trackerd or tracker-utils does absolutely nothing. From Travis, I use these two scripts to basically prevent trackerd from running:

killall trackerd
mv /usr/bin/trackerd /usr/bin/trackerd-old

You might want to use ‘whereis trackerd’ to find out where your trackerd binary is actually located before using the move command.

linux , , , , , , , ,

Ubuntu Sound and Video Problems

June 23rd, 2008

For the longest time, I’ve had terrible luck with sound and video problems with Ubuntu on a Dell Dimension E521 with nVidia sound and video cards. I thought it was terrible support by nVidia. Everytime I would update my computer, it would totally trash my video settings and sometimes, my sound settings.

Today after doing a bunch of updates, both my video and sound went to crap. With the help of my favorite Linux hacker, Travis, we figured out that I was actually running the server version of the Linux kernel. Next, I uninstalled all instances of the server kernels, uninstalled all nvidia drivers and modules, and rebooted. From there, I followed the basic steps to install nVidia drivers, configured my screen settings and now I am able to run all of the fancy Compiz visuals and my Ubuntu install has never been better.

linux , , , , , , , , , , ,