greynode » Unix http://greynode.org ingĂ©nierie de tous les aspects de vie Fri, 15 Apr 2011 16:12:00 +0000 en hourly 1 http://wordpress.org/?v=3.1.1 Cartoon Shader using GLSL http://greynode.org/2010/05/14/cartoon-shader-using-glsl/ http://greynode.org/2010/05/14/cartoon-shader-using-glsl/#comments Fri, 14 May 2010 21:01:58 +0000 enum http://blog.greynode.org/?p=230

Read the rest of this entry »

]]>
Here is an example of a shader written in the OpenGL Shading Language (GLSL). It is very simple shader, only assigning 4 different color values, yet the result is pretty cool. I’ll post the link to the source code once I add it to my git repository.

For introductory material on GLSL, check out Lighthouse 3D (where I got this cartoon example). Also check out the orange book for more in-depth discussion and examples on shaders.

]]>
http://greynode.org/2010/05/14/cartoon-shader-using-glsl/feed/ 0
Why No Games on Linux? http://greynode.org/2010/05/11/why-no-games-on-linux/ http://greynode.org/2010/05/11/why-no-games-on-linux/#comments Tue, 11 May 2010 20:54:26 +0000 enum http://blog.greynode.org/?p=226 Thought I would share an interesting article on why there are no games on linux. Want more games on linux? Solve these problems!

]]>
http://greynode.org/2010/05/11/why-no-games-on-linux/feed/ 0
Incremental Backup on FreeBSD with tar http://greynode.org/2010/05/10/incremental-backup-on-freebsd-with-tar/ http://greynode.org/2010/05/10/incremental-backup-on-freebsd-with-tar/#comments Mon, 10 May 2010 22:46:38 +0000 enum http://blog.greynode.org/?p=221

Read the rest of this entry »

]]>
Recently the rsync server at work broke down, and I needed a quick solution for incremental backup using just FTP. As it turns out, the FreeBSD version of tar is not GNU tar. So in order to use the following trick on FreeBSD, the gtar port must be installed. Once you have the software, making an increment backup with tar is easy:

$ gtar -g /backup/tar-incremental.log -cjvf /backup/backup.tar.bz2 /etc /usr/local/etc/ /usr/www

The tar-incremental.log file must be saved as it contains information for the incremental backup. Every time you run this file a new file will be created, so do not over-write your files. A more in-depth discussion can be found on the GNU tar incremental backup page.

]]>
http://greynode.org/2010/05/10/incremental-backup-on-freebsd-with-tar/feed/ 0
pdnsd and NetworkManager http://greynode.org/2010/05/09/pdnsd-and-networkmanager/ http://greynode.org/2010/05/09/pdnsd-and-networkmanager/#comments Mon, 10 May 2010 07:52:55 +0000 enum http://blog.greynode.org/?p=211

Read the rest of this entry »

]]>
If you run arch linux or a similar minimal distro, you may be familiar with the local dns server pdnsd, used to cache DNS queries. If you try to run pdnsd on the same computer as NetworkManager, you may run into a problem. Using default configurations, your DNS lookups end up in a vicious loop redirecting to 127.0.0.1. To circumvent this problem, I did the following.

I let NetworkManager generate my /etc/resolv.conf file. I then copied it to /etc/resolv.conf.head. Once this was done, the server section in /etc/pdnsd.conf was edited to contain the following:

server {
label= "comcast;
file = "/etc/resolv.conf.head"; # Preferably do not use /etc/resolv.conf
# proxy_only=on; # Do not query any name servers beside your ISP's.
timeout=4; # Server timeout; this may be much shorter
# that the global timeout option.
uptest=if; # Test if the network interface is active.
interface=wlan0; # The name of the interface to check.
interval=10m; # Check every 10 minutes.
purge_cache=off; # Keep stale cache entries in case the ISP's
# DNS servers go offline.
}

Notice the file variable which tells pdnsd where to find the nameservers it will query. Once this is complete, the pdnsd daemon can be restarted. Now, NetworkManager must be told to use localhost for DNS lookups. This can be done by right-clicking the nm-applet icon and configuring the wireless for “Automatic (DHCP) Address Only”, and enter 127.0.0.1 as the DNS server. Once this is complete, you can test it with the following commands:

jaigner /var/cache $ dig kernel.org | grep Query
;; Query time: 75 msec
jaigner /var/cache $ dig kernel.org | grep Query
;; Query time: 0 msec

The second time the command was called, the cached result was fetched. If your Query time is greater than 1ms, it is likely that something is misconfigured.

]]>
http://greynode.org/2010/05/09/pdnsd-and-networkmanager/feed/ 0
Key Repeat in Linux Xorg Not Working http://greynode.org/2010/05/08/key-repeat-in-linux-xorg-not-working/ http://greynode.org/2010/05/08/key-repeat-in-linux-xorg-not-working/#comments Sat, 08 May 2010 19:59:46 +0000 enum http://blog.greynode.org/?p=195

Read the rest of this entry »

]]>
After installing arch linux on my laptop, I noticed a small annoyance. When I opened any sort of terminal in Xorg, they key repeat feature would not function (i.e. holding a key down would not cause it to continuously be entered). The solution turns out to be quite simple:

jaigner@turing$ xset r on

This will enable key repeat functionality.

]]>
http://greynode.org/2010/05/08/key-repeat-in-linux-xorg-not-working/feed/ 0
Automake and Autoconf Made Simple http://greynode.org/2009/11/02/automake-and-autoconf-made-simple/ http://greynode.org/2009/11/02/automake-and-autoconf-made-simple/#comments Tue, 03 Nov 2009 08:15:14 +0000 enum http://greynode.org/?p=142

Read the rest of this entry »

]]>
Instead of randomly pasting configuration code from other projects when you decide you want to use automake/autoconf, just check out all you should really know about autoconf and automake. Albeit, it may not be comprehensive, but it should get you started.

]]>
http://greynode.org/2009/11/02/automake-and-autoconf-made-simple/feed/ 0
Functional Programming with the Unix Command Line http://greynode.org/2009/06/25/functional-programming-with-the-unix-command-line/ http://greynode.org/2009/06/25/functional-programming-with-the-unix-command-line/#comments Fri, 26 Jun 2009 06:29:30 +0000 enum http://greynode.org/?p=66

Read the rest of this entry »

]]>
I was pondering the unix command line the other day while reading sed & awk, and I came to the following revelation: variables aside, the unix command line is a lot like functional programming. Using the command line, you can build a functional program by redirecting I/O between various programs, or functions. Many of the programs one uses to build one-liners are essentially pure functions. An example of a pure function on the unix command line might be the programs uniq or sort. Various other functions such as ps and wget are not so pure, as their output relies on I/O with the operating sytem or server.

All theory aside, here are a few good one-liners.

Uploading Files

tar cjvf - yourDirectory | ssh uname@host "cat > yourDirectory.tar.bz2"

This command will create an archive of “yourDirectory” and upload it to your server via SSH, all in one chained command. Quite handy for uploading local content for sharing or backup.

Edit: Apparently this command transfers large files extremely slow. Oops.

Checking FreeBSD UPDATING File Automatically

portversion | awk '/</ {print $1}' |
xargs -I '{}' awk '/AFFECTS:.*{}/ {print}' /usr/ports/UPDATING > updates.txt

Ok. So this command pertains to the FreeBSD ports system. It is not recommended that you upgrade all your ports at once. There is often information contained in the file /usr/ports/UPDATING about special instructions you may have to follow while upgrading a package. Often times you may have to recompile other packages, or add a line to a configuration file, etc. The string above will check all of the ports tht are out of date, and compare them to the UPDATING file to see if the package is contained. If it is, it writes the name of that port to updates.txt. You can then use this file to know which ports have special instructions. You should probably write an alias for this one.

Converting Line Endings

The following two commands should help with reformatting files. Often times I find myself getting web designs from someone who uses windows. Most editors on windows will save files with DOS line endings. When you open one of these files in unix (in certain editors), the line endings won’t appear properly. The following commands will circumvent this problem, in either situation.

Convert from unix (\n) to DOS (\r\n)

awk '{sub(/$/, "\r")};1' unix_endings.txt > dos_endings.txt

Convert from DOS (\r\n) to unix (\n)

awk '{sub(/\r$/, "")};1' dos_endings.txt > unix_endings.txt

And yes, I realize that I use too many commas when I write: I’m working on it.

]]>
http://greynode.org/2009/06/25/functional-programming-with-the-unix-command-line/feed/ 0
Scripting Languages http://greynode.org/2009/06/22/scripting-languages/ http://greynode.org/2009/06/22/scripting-languages/#comments Mon, 22 Jun 2009 22:02:04 +0000 enum http://www.greynode.org/?p=48

Read the rest of this entry »

]]>
I just thought I’d share with you Random thoughts on scripting languages by Brian Kernighan.

After reading this, I looked up the source code to the unix utility wc. The GNU wc program was written in C, and amounted to about 800 lines with comments. A similar program written in awk is a mere 2 lines long:

{ nc += length($0) + 1; nw += NF }
END { print NR, "lines", nw, "words", nc, "characters" }

I know you are probably thinking that I just made an unfair comparison. Yes, I did.

]]>
http://greynode.org/2009/06/22/scripting-languages/feed/ 0
Replace Text Recursively with sed http://greynode.org/2009/06/17/replace-text-recursively-with-sed/ http://greynode.org/2009/06/17/replace-text-recursively-with-sed/#comments Wed, 17 Jun 2009 20:53:31 +0000 enum http://www.greynode.org/?p=45

Read the rest of this entry »

]]>
Here is a quick little trick I discovered today when I needed to replace text in multiple files recursively:

grep -rl -e <searchterm> * | xargs sed -i .bak 's/searchterm/newterm/i'

There might be a problem with files that have spaces in the names (because xargs will take a space as the start of a new argument). To solve this problem, you should be able to do something like this:

grep -rl --null -e <searchterm> * |
xargs -0 sed -i .bak 's/searchterm/newterm/i'

If you are using GNU grep, you could also use -Z instead of –null. I happen to be using the BSD version of grep, so -Z isn’t an alias for –null.

]]>
http://greynode.org/2009/06/17/replace-text-recursively-with-sed/feed/ 0