Friday, October 26, 2012

Kubuntu 12.10 No Menubars in GTK?

Today, when I launched Audacity on my Kubuntu 12.10, I was greeted with a window with no menubar for File, Edit, etc. It reminded me of how there are no longer menubars in a lot of Windows apps.

No menu bars... where'd they go?
I thought about it a bit, trying to figure out why this happened. The conclusion I came to was that this must be the result of some change in Ubuntu 12.10 related to Unity...

Image from: http://lh5.ggpht.com/_1QSDkzYY2vc/TG2xHSwOo7I/AAAAAAAABt4/LAODgOgafAM/unity3.png
Notice how Ubuntu integrates the menu bars from GTK applications into Unity?
In Ubuntu, apparently, in order to make menu bars show up in Unity instead of the application's window, they export the menus through DBus. This makes sense for Ubuntu, I guess; it's part of the reason why I never really liked the whole Unity thing.

However, the menus don't show up anywhere obvious in KDE:
After a quick Google search, I found one possible solution. There is now a KDE widget that does the same thing as Unity's menu-bar-stealing-system.

Huh, this is new...
Well, my menus are there... but YUCK!
Surely there must be a better way... thankfully, the fix is extremely easy.


How To Fix It

Simply uninstall appmenu-gtk and appmenu-gtk3. Restart your apps, and your menus will be back!

sudo apt-get remove appmenu-gtk appmenu-gtk3



If I had to guess, GTK apps must install these packages by default since that's what they'd need in Ubuntu. However, these packages are just dumb for KDE users. Thankfully, the fix is very easy.

I hope this is a bug and not a feature. If Ubuntu starts to deviate so much to make Unity run, I hope Kubuntu/Xubuntu won't suffer. If they do, Ubuntu will lose even more users than it already has. Not that there aren't good alternatives, Mint Debian is continually getting better. And Fedora's not bad, I just like the Advanced Packaging Tool (APT) much better than any alternatives.
Unity has had this feature for longer than just 12.10 though. Anyone know why this suddenly became a problem in 12.10?

Thursday, October 18, 2012

Why I Like Buckling Springs over Cherry MX Switches

If you're into mechanical keyboards, you almost certainly are familiar with Cherry MX Switches, they're the most popular these days. Especially MX Blues...

Personally, I prefer the buckling springs on the old IBM clicky keyboards.

Don't get me wrong, I think Cherry MX Blue switches are great, but I still think buckling springs are better.

The thing I don't like about Cherry tactile switches is that there is a noticeable "bump" on the release of a key.

This effect is nearly absent (in fact, it's slightly the opposite effect, it feels more like a springy pop) with buckling springs.

This is visible in the force diagrams.

Cherry Switches. MX Blue (and Brown) switches have a noticeable drop in force on the return, this results in a noticeable bump in the return of the keypress. It has the opposite feeling of the Buckling Springs' return path.
Buckling Springs. Notice how the return path is almost completely smooth? It actually jumps up a little near the end of the return of the key press.

As you can see from the two diagrams, the feel of the key return is completely opposite on the Cherry tactile switches versus the IBM buckling springs. The actuation is fairly similar though.

This is the main reason I don't like MX Browns, I'm not really a fan of the tactile feel of Cherry switches... I do like MX Blues, but mainly because I like the clicking (even if I can't hear it with headphones). It's been awhile since I've used Browns though, so, perhaps I wouldn't notice a huge difference between blues and browns if I can't hear the click. All I remember was that I originally thought Browns and Blues were the same, except for the noise, but I remember them feeling different when I tried them...
Also, the actuation force is too low on MX Blues for me... would love to see some keyboards with MX Greens (basically, MX Blue switches with MX Black springs), but they don't exist.

Either way, bucking springs are better.

Saturday, October 6, 2012

Kubuntu: Line In Hardware Passthrough

If I record music through Line In, I also want to be able to listen to it in real time while recording.

I don't want to use additional hardware splitters or software playthrough in Audacity (which has high latency). In Windows, I would normally enable playthrough for Line In through Control Panel or through the driver software for my soundcard. However, I couldn't find an easy way to do it through kmix. I eventually found that alsamixer will do what I want, and it's an easy enough fix.

Open a terminal, type "alsamixer".
Using the arrow keys, scroll right to "Line", hit "M" to unmute, and press Up until the volume is at its maximum. You should now hear all input through Line In immediately on your speakers.


Wednesday, August 22, 2012

Kubuntu 12.04 KMix Window Auto Starting

For some reason, the KMix configuration window pops up on login for me sometimes. I don't know why it starts, but there's not an obvious way to stop it.

After some Googling, I found a forum post with a fix: https://www.linuxquestions.org/questions/linux-software-2/kmix-window-on-startup-278600/

Edit:
~/.kde/share/config/kmixrc

Change
Visible=true

To
Visible=false

Save then Logout/Login and it shouldn't pop back up again.

Alternatively, you could just remove ~/.kde/share/config/kmixrc
Make a backup first.

Stop Google Talk's Auto Volume Adjustment

People can very rarely hear me well over the telephone. I don't know why. I sometimes use my computer because my cell phone has a terrible mic, but people still have a hard time hearing me sometimes... it also didn't help that Google Talk would constantly adjust the microphone input volume either.

I'm using Kubuntu 12.04, and the microphone input volume would constantly lower itself as I talked on GMail through the Google Talk Plugin. It would just raise and lower the volume slider as it saw fit. So frustrating.

After much Googling, I found a solution (Linux only, there's a similar registry fix in Windows though). Should work for Ubuntu, or any other Linux distro really, since it's a problem (er, "feature") of the Google Talk Plugin.

http://productforums.google.com/forum/#!category-topic/gmail/contacts-and-sync/n1cpJq1mC8U

Edit the file (create it if it doesn't exist):
~/.config/google-googletalkplugin/options

If it's already there, there will be a line that starts with "audio-flags="
Change it (or add it if it doesn't exist) to:
audio-flags=1

Save, Reboot, and Test

Friday, August 10, 2012

IBM Model M (1391401) Bolt Mod / Rivet Replacement (With Pictures)

The IBM Model M is a sturdy keyboard. It's main flaw is that it uses cheap, plastic rivets to attach the main main plastics to the steel plate. These can break over time, and they also pose a problem if you want to access the springs.

I opted to do a bolt mod on my Model M because I was having trouble with a key and needed to access the hammer under the spring. However, if you have any dissatisfactions with the feel of certain keys on your Model M, a bolt mod (and possibly a spring/hammer swap with a lesser used key or new springs/hammers) will probably make it better. I don't notice a huge difference in the overall feel of the board, except that all the keys feel more consistent now. Some people say it has a stiffer feel after a bolt mod, I'd agree with this, but it's not a large difference.

There are several guides on the Internet detailing this process. Essentially, one chisels off the plastic rivets, and replaces them with small bolts and nuts.

I took some pictures during the process, so I decided to write my own how-to guide based on my experiences. Geekhack is a good resource, but it was unavailable during the time I did this mod in July.

If you decide to do this mod, feel free to use my pictures for guidelines, but I'd recommend following one of the guides on Geekhack if you can; they're far more "tested" than mine. Also, there's a pretty good guide over at Overclockers:

http://forums.overclockers.com.au/showthread.php?t=1024488

---------- Tools & Parts ---------



You could probably get by with similar sized nuts and bolts, but these are what Ripster's guide suggested, and they worked perfectly. So, unless you already have a bunch of supplies that you think will work, I'd recommend getting these exact sized metric nuts and bolts.

---------- Preparation ----------

Get together a table, a towel, some safety glasses, and two identical books that are at least one inch thick (so that the exposed springs don't get damaged after you remove the keycaps). It'd be helpful to get some jars for various parts (springs, keycaps, etc) too.

Take apart the main frame of the keyboard by removing the four screws. Inside, there will be a circuit board attached to the PCBs between the plastic and steel. Carefully disconnected the circuitboard and its ground wire and set it aside for later. Don't lose track of the bolt and nut for the grounding wire. Be very careful not to tear or bend the old PCB plastic.

You should now be left with the steel plate and plastic barrel housing with the PCBs sandwiched in-between. You can remove the keycaps, but DO NOT remove the buttons under the keycaps because it will expose the springs (and you really don't want to damage those).



Chiseling off the plastic rivets.
Start by chiseling off the plastic rivets. There are around 50. Be careful and take your time. Try to cut them as cleanly as possible, it will save you work later. Wear some eye protection, because these things fly off like projectiles and could hurt your eyes. Also, wear some somewhat heavy gloves in-case your knife/chisel slips.

The steel plate separated from the PCBs and plastic housing.
Now that you've successfully flung little plastic circles all over the room, you can lift the steel plate from the rest of the pieces. It's best to stack these pieces in order when you remove them, so that you don't lose track of the order they go in (there are three layers of acrylic sheets).

Removing the rubber sheet revealing the springs.
Once you've removed the PCBs, you can peel away the rubber sheet to reveal the springs and their hammers. At this point, the springs can be safely removed and placed aside for later. If you want to take note of the commonly used springs (spacebar, enter, backspace, etc) for swapping purposes, now is the time. However, I found all but one of my springs to be in nearly identical condition, so I actually only separated the letters from the other keys (in the end, I put them all in one cup anyway, so I don't think it matters all that much).

The damaged hammer in question. It was under the "w" key, it would register a key press before the click. Turns out, the plastic on one side of the hammer had signs of stress, that was enough to affect the key, even after I changed the spring three times.
The removed buttons.
With all the springs removed, you can finally remove the buttons from the board. I don't have a specific recommendation on how to do this, I was able to pop them off with my hands in most cases, but a screwdriver or a flat, rigid object might help with a few of the keys. Once removed, this is the perfect opportunity to clean the keys and buttons. Either run them though the dishwasher or just soak them in some soapy water then dry them off.

Now, it's time to smooth out the remains of those rivets. I used a serrated blade. Sandpaper might work, but be careful not to hurt the little plastic half moons at the base of each rivet.

Using a serrated knife blade to flatten out the remains of the plastic rivets.
With the plastic rivet remains smoothed, it's time to drill some holes! You could probably use a handheld drill for this, but I was lucky enough to find a drill press. If you have access to one, I'd highly recommend using it.

Using the drill press with the 1/16" bit to drill through the rivets.
Use the 1/16" drill bit to carefully drill a hole straight through the remains of the plastic rivets (this is why you sanded/cut them, so they're easier to drill a hole through). 

A few warnings though. Always look before you drill, in one case, there was a plastic piece that holds the little metal bar under a few keys. If you drill through this, you will ruin it. Also, the bolts will get in the way of the two metal supports under the numpad's "+" and "Enter" keys. They're not necessary for keyboard operation, but if you want them, don't drill through here. You might as well leave the farthest right column near the numpad undrilled if you're worried. Also, keep in mind that you're dealing with plastic that is over 20 years old, it can crack and break.

Make sure to go right between the two plastic half moons. A couple mistakes is probably fine (I messed up a few, drilled a bit to close to the edge of the rivet and the screw shows out the side a bit). Oh, and don't worry about the bottom row (near the spacebar), because you'll need washers to complete the bolt mod there.

Finished drilling holes.
One you have a completed drilling, you're ready to start putting things together. With a small screw driver, screw in all the bolts into the holes you just drilled. This will take some time, so be patient.

Finished screwing in the bolts.
In this picture, you can see the little plastic half-moons I was talking about earlier.
Once all the bolts are screwed in, you can start putting everything back together.

Suspend the plastic upside-down between two books. Insert the springs. Make sure it doesn't fall and damage the springs.

Then, place the rubber mat over the springs, followed by the PCBs and, finally, the steel plate.

Now it just needs the steel plate and the nuts.

After fastening the nuts on top of the steel plate, it should looks like this. Don't over-tighten things, your hands are probably almost strong enough. An adjustable wrench can be a livesaver in this step.
After placing a handful of nuts on the bolts, everything will probably hold together. At that point, you can start replacing buttons and keycaps. Now is a good opportunity to test everything before you screw on all the nuts.

Screwing on the nuts is the most tedious, time-consuming step. Take your time and stay calm.

Everything's all put together now!
I had to re-do the nuts a few times, unfortunately, before everything worked right. It's very important that the hammers stay in their place, if they get mis-seated during the process, you'll have to undo all the nuts! Try to avoid that!

Also, I'd recommend that you don't mix new and old hammers and springs. I got a new set on eBay, but they were different enough from the originals, that I could notice the difference. If you need to replace a few, either use the new ones on the F-keys and swap; or get an entirely new set...

---------- Conclusion ----------

I'm very happy I did the bolt mod. This keyboard still has many more years of useful life. The build quality on these boards is pretty incredible, and by doing a bolt mod, you're making it even better.


Intel DZ77BH-55K Linux HD Graphics Issues (xorg.conf fix)

I recently built a PC with an Intel DZ77BH-55K motherboard. I was hoping to avoid some graphics issues by using the built-in Intel HD Graphics. Unfortunately, although there are no show-stopping driver issues with this board, the default configuration in Kubuntu 12.04 (and others) isn't right.

The problem is, I was using the HDMI output, and the resolution on my monitor was fine until kdm started. After inspection, I noticed that the video driver seems to think there is a VGA1 connected, despite the fact that the motherboard has no VGA output. As a result, the 1024x768 VGA1 output was used as the default, and the HDMI output was a clone of it (at 1024x768). This can be fixed by disabling VGA1 and setting HDMI2 to the right resolution, but it's on a per session basis.

I did find a way to semi-permanently fix it through a xorg.conf file. If you want to generate one yourself, switch to a virtual terminal (Ctrl+Alt+F1) and run "sudo service kdm stop" (or gdm or whatever). And then run "sudo X -configure". You can modify the new ~/xorg.conf.new to your needs.

I removed everything except the HDMI output. Here is the result. If you're using HDMI on a DZ77BH-55K board, you can probably just drop this into /etc/X11/xorg.conf, reboot, and you shouldn't have any problems on a fresh install (if you've messed with the settings in KDE already, just remove "~/.kde/share/config/startupconfig" first.


Disable HDMI Sound on NVIDIA/AMD GPUs

I am using Kubuntu 12.04.

Add:
blacklist snd_hda_codec_hdmi
to the end of:
/etc/modprobe.d/blacklist.conf

Wednesday, August 8, 2012

The Magic SysRq Key

I always wondered was the SysRq key did, it's always there right under Print Screen, yet, I never knew what it did. If you want to see it do something, you can try this: if you're using Ubuntu (or most Linux I'd imagine) switch to a fullscreen console (Ctrl+Alt+F1 [or any F* except F7]) and hit Alt+Print Screen (SysRq) then Alt+Scroll Lock

Wednesday, June 27, 2012

Why I'm using a 1988 keyboard...

This summer, while sorting a junk heap of old keyboards, I found a real gem -- a 1988 IBM Model M mechanical keyboard in pretty good condition.

This keyboard is a well known model, and is very popular among keyboard enthusiasts. I cleaned up the board, and now I've been using it as my primary keyboard for a few weeks.

My favorite keyboard.
How many electronics do you own that have a birth certificate?

So, what makes this 24-year-old board better than your fancy gaming keyboard? or even your high-end mechanical board?

Here are a few reasons:
  • PBT Plastic
    • Most keyboards (even most "high-end" mechanical boards) have keycaps that are made of ABS plastic. PBT plastic is more difficult to work with, but is far more resistant to wear.
      • Your ABS keyboards will probably start to look a bit shiny after a few months/years. However, my Model M's keycaps still have a good texture even after decades of use in a school.
24 years and the keys still have a texture
  • It's built like a tank...
    • How many keyboards these days have a heavy steel plate inside? The IBM Model M features a (very heavy) steel plate, that gives the keyboard both it's weight and durability.
      • You could probably snap a cheap modern keyboard easily. The Model M could probably survive being thrown across a room.
Ripster's image of a bolt mod on a Model M. Gives a good picture of the steel plate that gives these boards their weight.

  • Buckling Springs Are Better
    • IBM buckling spring keyboards like the Model M are notoriously noisy, much noiser than even Cherry MX Blue switches. This is because you receive a loud click upon successfully actuating a key.
      • This is what sets mechanical keyboards apart from "rubber-dome" keyboards that rely on a sheet of rubber underneath your keys. Mechanical keyboards have real switches and springs. The Model M isn't a true mechanical (no switch), but it feels like one.
GIF of IBM buckling springs.
Image from the Mechanical Keyboard Guide on Geekhack.org
  • No-nonsense layout
    • The Model M has a perfect, no-nonsense 101-key ANSI layout. None of that crap with the over-sized Enter key and microscopic Backspace (why make enter so big but backspace so small? why?)
  • Detachable, coiled cable
    • I've seen very few coiled cables these days. I don't know why. I really like the coiled, detachable cable on the Model M. It just sits on my desk and doesn't get tangled.
  • It's vintage aesthetics make a great contrast to my "modern" hardware
    • If anyone tells me that I should get a "new" keyboard (haters-gonna-hate I guess), I'll calmly explain why I love my keyboard, and why I actually prefer the old look (it looks so awesomely out-of-place on my desk).
Disadvantages

Now, the Model M is a great board, but it's not perfect. Here are some possible disadvantages.
  • No NKRO
    • It's no secret that the Model M has 2-key rollover (meaning, worst case, you might not be able to hit three keys at once). I'm not even much of a gamer, and this has gotten in my way a few times.
    • https://en.wikipedia.org/wiki/Rollover_(key)
  • It's still membrane-based
    • Unless you have a rare IBM Model F, underneath the springs is a plain old membrane (just like your rubber-domes). This is why it is 2KRO, and why it's not a true mechanical keyboard.
  • 101-key
    • Personally, I like the 101-key layout (no Windows key or Context Menu key), but many people, especially if you use Windows (I don't usually), will find it inconvenient.
  • The way that the plastic is attached to the steel is just plain cheap
    • This can be fixed with a bolt mod, but after many years, the plastic anchored to the steel plate will get weak. Fixable if you have some basic tool skills and some parts, but annoying nonetheless.
  • It's really really difficult to open and work on
    • The bolts holding the plastic together are 5.5mm (7/32 inches), not only is this fairly uncommon, but the shafts where the bolts are located are very narrow as well.
    • You also can't get to the hammers or membrane without doing a bolt mod.
  • It's draws more power than it should
In conclusion, the most important features to me in a keyboard are: PBT plastic, clicky and tacticle feel (buckling spring, Cherry MX Blue/Green), and a good ANSI layout. NKRO is highly preferred if possible.

The Model M isn't perfect, but it's pretty good, and it's better than most keyboard's I've used in my days. The downside, however, is that I've become extremely picky about keyboards, and I can't even find a high-end mechanical one that I like as much. The days where I could be happy on a $15 keyboard are over.

Unicomp still make replica Model Ms... but I don't think the quality is quite as good (though, I'm sure they're still great boards because they're very close to the original).

I'd really like to see a true Cherry MX Green keyboard on the market. The MX Green switch is like a heaver version of the MX Blue (buckling springs are quite a bit heaver than Blues). All we've got right now are "ghetto-Greens" (MX Blue switches with MX Black springs).

Now, if I could just get my hands on an AT Model F...

Monday, May 21, 2012

StartSSL and Nginx

I recently got a signed SSL certificate for my personal web site for free from StartSSL. In order for most browsers to accept the site and not produce SSL warning messages, an intermediate CA certificate must be added. StartSSL has info for web server software, but not nginx.

I found a blog post that presented a very easy solution. Find the file that Nginx is serving from the "ssl_certificate" directive, and run the following commands on it (where "ssl.crt" is your certificate)
curl http://www.startssl.com/certs/sub.class1.server.ca.pem >>ssl.crt
curl http://www.startssl.com/certs/ca.pem >>ssl.crt

Restart Nginx, and you're ready to go!

Thursday, May 17, 2012

How To: PPTP VPN on Ubuntu 12.04 (pptpd)

I recently started renting a 128 MB RAM Xen VPS for $15/quarter with a promotional offer for nqhost.com as seen on http://www.lowendbox.com/blog/nqhost-15quarter-128mb-xen-vps-in-dallas/
Since nqhost.com offers unmetered bandwidth through a SoftLayer data center in Texas, I decided to set up a VPN server for my own use.

In this tutorial, I will be showing you how to set up pptpd (poptop) on Ubuntu 12.04 to provide PPTP VPN services.

The following instructions are inspired by http://eran.sandler.co.il/2010/08/30/pptp-vpn-on-ubuntu-10-04-for-your-iphone-ipad/


Install Software
sudo apt-get install pptpd ufw

Allow Ports 22 and 1723 on UFW and Enable UFW
Warning: if you are connected to SSH on a port other than 22, please adjust the first command accordingly so you don't get kicked off.

sudo ufw allow 22
sudo ufw allow 1723
sudo ufw enable


Edit /etc/ppp/pptpd-options
Comment out (by placing a "#" at the beginning of the line) the following lines in "/etc/ppp/pptpd-options":
  • refuse-pap
  • refuse-chap
  • refuse-mschap
If you don't want to require encryption, comment out "require-mppe-128" (might be good to disable it just for testing and re-enable it later)
Add the following:
ms-dns 208.67.222.222
ms-dns 208.67.220.220

*note, you can use any DNS servers you like, the two above are OpenDNS's public DNS servers.

Edit /etc/pptpd.conf
At the end of the file "/etc/pptpd.conf", add:
localip 10.99.99.99
remoteip 10.99.99.100-199


These values do not have to correspond to your network. It is best to pick un-accessible/unused addresses here if you only want to use the VPN for Internet access.

Edit /etc/ppp/chap-secrets
The format for "/etc/ppp/chap-secrets" is [Username] [Service] [Password] [Allowed IP Address]
Add something like this to the end (replacing sampleusername and samplepassword with whatever you want):
sampleusername pptpd samplepassword *

Reboot pptpd
Finally, you can reboot the pptpd server with:
sudo /etc/init.d/pptpd restart

Edit /etc/sysctl.conf
Un-comment the following line in "/etc/sysctl.conf":
net.ipv4.ip_forward=1

The following command reloads the configuration (you can also just reboot at the end of this guide):
sudo sysctl -p

Edit /etc/default/ufw
Edit "/etc/default/ufw" and change the option "DEFAULT_FORWARD_POLICY" from "DROP" to "ACCEPT"

Edit /etc/ufw/before.rules
Add the following either at the beginning of "/etc/ufw/before.rules" or just before the *filter rules (recommended):
# NAT table rules
*nat

:POSTROUTING ACCEPT [0:0]
# Allow forward traffic to eth0
-A POSTROUTING -s 10.99.99.0/24 -o eth0 -j MASQUERADE

# Process the NAT table rules
COMMIT


At this point, you can run "sudo ufw disable && sudo ufw enable" or just reboot to be safe. You should be able to connect now. It took me several tries before I could get it to work, and it looks like the "require-mppe-128" line was what gave me so much trouble. I ultimately enabled encryption, but not before I tested it without.

Friday, May 11, 2012

Swap Whitespaces/Underscores in Filenames

I have a folder where some of the files are name "like_this" and some are named "like this". I want to convert all the underscores in all the file names to spaces. Run this command in the directory where you want this to happen (you can swap the '_' and ' ' characters accordingly):

find . -depth|rename 's/\_/ /g'

Wednesday, May 9, 2012

Mirroring a Web Site Directory with wget

I recently decided that I wanted to copy some course web sites from my university's CS department for use during this summer when I'll be on an unreliable Internet connection. There's also httrack, but I couldn't get it to copy everything correctly.

Solution: wget

wget -mk -w 0.25 --no-parent http://example.com/sites/directory
  • -m mirror
  • -k convert links
  • --no-parent don't grab http://example.com, just stuff in the specified directory.
  • -w wait time (seconds) between page grabs (be nice, otherwise you might DoS their servers)
And viola, you have an offline copy of the site directory now!

Wednesday, March 28, 2012

Dropbox on Linux without Root

On the CS department machines at school, we do not have root access to install applications, however, I wanted to use Dropbox to sync my homework with my other computers so I could work on it anywhere.

This method is working on Fedora 16.

1) Download the Ubuntu .deb from the Dropbox web site

Even though I'm not using Ubuntu, I still used the .deb on the Dropbox site. It probably doesn't matter too much since all we need is the binary package.

https://www.dropbox.com/install

2) Extract the .deb file and then extract data.tar.gz

ar vx nautilus-dropbox_*.deb
tar zxvf data.tar.gz

3) After extracting data.tar.gz, move the dropbox binary to your home directory

mv usr/bin/dropbox ~/
cd

4) Install Dropbox

~/dropbox start -i

You'll probably see some errors about missing libraries. It should be OK to ignore those.

You'll be asked the standard Dropbox installation questions.

5) Running it again next time you login

By default, Dropbox will not start automatically when you log in. You can, however, start it again by running:

~/dropbox start

You could always find a way to run this command automatically when you log in. I'll leave that up to you and your desktop environment.


I'm sure this method is not perfect, but it worked successfully for me today. I will update with bugs and workarounds if I find them.

Thursday, February 23, 2012

nginx Self-Signed SSL

In this tutorial, I will be setting up nginx to listen on 443 for SSL connections. I will be creating a self-signed SSL certificate. I am running Ubuntu Server 10.04, your configuration locations may be slightly different.

Sources:

1) Generate a Private Key

openssl genrsa -des3 -out server.key 1024

2) Generate a CSR

openssl req -new -key server.key -out server.csr

3) Remove Passphrase from Key

cp server.key server.key.org
openssl rsa -in server.key.org -out server.key


4) Generating a Self-Signed Certificate

openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

5) Copy the .crt and .key files to /etc/ssl/

cp server.crt /etc/ssl/certs/
cp server.key /etc/ssl/private/


6) Configure nginx

Add the following to /etc/nginx/sites-available/default

ssl_certificate /etc/ssl/certs/server.crt;
ssl_certificate_key /etc/ssl/private/server.key;

server {
    listen 443;
    ssl on;
    location / {
        proxy_pass http://127.0.0.1:8080;

    }
}


Of course, if you're not running nginx as a reverse proxy, your information in location / {} will be different. This is only an example to illustrate the use of the extra SSL options.

Reboot nginx

/etc/init.d/nginx restart

If everything goes well, you should be able to browse to https://127.0.0.1 (where 127.0.0.1 is the IP of your server).

Configure nginx as a Reverse Proxy for Apache

In this tutorial, I will be setting up an Ubuntu 10.04 Server running Apache on port 8080 and nginx on 80. Apache will forbid connections from anything but localhost, and nginx will act as a reverse proxy and forward requests to Apache.

1) Modify /etc/apache2/ports.conf

Find the following lines in /etc/apache2/ports.conf:

NameVirtualHost *:80
Listen 8080


Change them to:

NameVirtualHost *:80
Listen 80


2) Modify /etc/apache2/sites-available/default

(Your distribution might just use apache2.conf, Ubuntu's a bit different, it keeps virtual hosts in separate files)

Change
<VirtualHost *:80>
to
<VirtualHost *:8080>

Now change
<Directory /var/www>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>
to
<Directory /var/www>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order deny,allow
    Deny from all
    allow from 127.0.0.1
</Directory>

(You may also wish to do the same for the "/usr/lib/cgi-bin" directory...)

3) Restart Apache

/etc/init.d/apache2 restart

If you try to access the server on 8080 remotely, you should get a 403 Forbidden.

4) Configure nginx

If you haven't already installed it...

sudo apt-get install nginx

Delete or move /etc/nginx/sites-available/default
Also, create the directory /etc/nginx/logs/

Now, create and edit /etc/nginx/sites-available/default

The file should look like this:

server {
    listen 80;
    access_log /etc/nginx/logs/access.log;

    location / {
        proxy_pass    http://127.0.0.1:8080;

    }
}



Reboot nginx
/etc/init.d/nginx restart

You should be good to go now, try browsing to port 80 on the server and you should get content from Apache, but the server will appear to be running nginx.

Attacks like keep-dead should be a lot less effective against your server now. You can also configure nginx for SSL and not have to worry about configuring SSL for Apache.

It would also be a good idea to drop any external traffic to port 8080 with a firewall, as Apache still responds with a 403 if the firewall doesn't block the port.

You can see the access log at /etc/nginx/logs/access.log


Also, here's some nice examples for nginx configuration, if you're interested in configuring it further: http://wiki.nginx.org/FullExample

Crop Using FFMPEG

The ffmpeg parameter for cropping is:

-vf crop=1920:800:0:140

This takes a 1920x1080 resolution input, and crops 140px off of the top and bottom. The syntax is:

-vf crop=x:y:left_and_right:top_and_bottom

Here is an example:

ffmpeg -i INPUT.mkv -acodec copy -vcodec libx264 -crf 0 -vf crop=1920:800:0:140 OUTPUT.mkv

This takes INPUT.mkv, keeps the audio, transcodes it with x264 in lossless mode, and crops 140px from the top and bottom of the video.

Saturday, February 18, 2012

MP3 vs Lossless: Analysis with Phase Inversion

Lossy audio technology, such as MP3, has changed the way we listen to music. In the early days of portable music, MP3 technology made storing multiple CDs of music tracks on flash or mini hard disk storage practical. Instead of 700 mb of uncompressed WAV files, you could simply use MP3 to fit an entire CD into about 100 mb without any noticeable quality loss.

However, it has always been debatable just how much is lost when making an MP3 out of a lossless source like a track on a CD. There have been many comparisons and evaluations of lossy audio compression. Most people can pick out the tinny sound of a low bitrate MP3, and some can tell the difference even on higher bitrates, such as 128 kbps and beyond.

The image above shows the frequency analysis of a lossless track versus a 128kbps MP3 encode of the same track. All of the data in gray was lost in the MP3 track and is only present in the FLAC track. Everything above approximately 16.5 KHz was simply discarded when the MP3 was made.
Despite the loss of quality, there are no major legally licensed online sources of lossless music. Most music stores sell audio tracks at a bitrate and format that is similar to 320 kbps MP3 (some use VBR MP3, some use AAC, but they are all fairly similar at high bitrates).

The question is, can most people tell the difference between a lossless track and a 320 kbps MP3 of the same track?

Probably not.

In fact, if you did a double-blind study, I doubt many people could tell the difference. If you want to prove me wrong, test yourself here: http://mp3ornot.com/

That's how I did after 10 tests.
Whether or not you can actually tell the difference between 320 kbps MP3s and 128 kbps MP3s is not what concerns me though. There is another matter that I feel is more important than whether or not we can "hear" the difference.

It is no doubt that information is lost when making an MP3 track at ANY bitrate. The human ear *probably* can't detect these differences (especially at 320 kbps) under any normal circumstances, it is below the just-noticeable difference threshold, but there are times when these small changes stand out a lot.

For example, if you have a CD version of a karaoke track and the actual track with voice, assuming that the studio simply muxed the voice over the karaoke track, you can reproduce the original voice track by playing one of the tracks inverted at the same time as the other track. This, in theory, cancels out any similar data, leaving only the difference.

Unfortunately, it only works reliably if you have lossless copies of each track. The MP3 copies have already changed too much data to be useful.

For the demonstration, I will invert a lossy MP3 track and play it against its lossless FLAC track and see what is left over.

If you have two identical lossless copies of an audio track, and you invert one of them and play them back synchronized, you will be left with pure silence. Try this out in Audacity if you don't believe me, import two copies of the same audio file, invert one, and play them both.

This is what I will demonstrate below: if you have two different tracks mixed together, and you play the second track inverted simultaneously with the mixed track, you should be left with a pure version of the first track.

For this example, I have made three recordings from my guitar. Both are <10s clips of playing a few chords. Mixed together, they sound awful, but it will get my point across.

I created FLAC versions of each recording, and a FLAC version of the two recordings mixed together.
I also created MP3s from the FLAC versions of each of those three files.

Here they are if you are interested in trying this yourself:

The MP3 versions are transcoded directly from their counterpart FLAC files.

In theory, if we invert (in Audacity, Effects > Invert) both chords1.flac and chords2.flac and play these two inverted tracks simultaneously with chords-mix.flac, we should get pure silence. And, indeed, we do! Here is the result: flac-merged-inverted.flac, a perfectly blank track!

(Fun fact: if you play "chords-mix.flac" and an inverted copy of "chords1.flac" in Audacity, you will be left with "chords2.flac")

The mixed track played simultaneously with the inverted forms of the two individual tracks results in pure silence.

Now, what happens when we do the same with the MP3 versions? The result is not pure silence, but additional noise! mp3-merge-inverted.flac

This is all leftover noise from the MP3s. Their encoded forms lose data and introduce noise, and therefore, when we play  the inverted MP3 tracks with the mixed MP3 track, we get erroneous noise when there should be silence.
As you can see in the frequency analysis above (and you can hear scratchy noise on the track if you listened to it), there is definitely data in the MP3 files that shouldn't be there! This is because, in order to make use of space, lossy compression will mix and match data in ways that lose high frequencies that appear in Fourier analysis. Normally, you wouldn't notice this "noise", but when we isolate it, you can clearly hear it.

Thursday, February 9, 2012

Use .cshrc to run bash

On the CS department computers at school, the default shell is csh, and we're not allowed to run chsh to change it. However, bash is available, so, you can modify your .cshrc file to automatically run bash instead.

Edit ~/.cshrc so that it only includes the following code:

if($?prompt) cd ~ && exec bash --login