Thursday, May 26, 2022

AIGLX/Beryl

Beryl is a super-sweet, super-configurable fork of Compiz (also see earlier post). Here I will describe how I got it set up on my system and some cool things to do with it. Setup Here are my specs:
  • 2 Hyundai 17" screens
  • 32-bit OS (Ubuntu Edgy Eft 6.10)
  • nVidia Geforce graphics card
Following the instructions on the Unofficial Edgy Eft Starter Guide, I got AIGLX/Beryl to work on only one screen without problems. To enable Twinview (sharing one desktop accross two physical screens), enter sudo nvidia-settings in a terminal and go to X Server Display Configuration (this, by the way, beats the hell out of hacking the /etc/X11/xorg.conf file). Click the Configure... button on the middle right and select Twinview. Be sure to back up your xorg.conf file before clicking Save to X Configuration File at the bottom and then exiting out of the settings manager. Hit Ctrl+Alt+Backspace to restart the X server. Unfortunately, Beryl on Twinview made windows appear without titlebars or borders. I also got this message in the terminal when I disabled the session startup scripts and tried to run beryl-manager in the terminal: beryl: No GLXFBConfig for depth 32 beryl: No GLXFBConfig for depth 32 beryl: No GLXFBConfig for depth 32 So, to the xorg.conf file! Under the Screen section, add this line: Option "AddARGBGLXVisuals" "true" I restarted the X server again and everything worked fine. Well, let me qualify that: at least nothing was obviously wrong. Some things are still somewhat slow like window resizing and scrolling. It appears that others are having similar problems. However, this works well enough for me. Features/Cool things to do All these commands (and the themes) are completely configurable... just fool with the settings by clicking on the red stone in the system tray and selecting one of the managers... here are just some of the default settings
  • Ctrl+Super_L: water drop on desktop (hold down keys and move mouse for trail)
  • Shirt+F7: Window wake
  • Shirt+F9: Raindrops
  • Super+Mouse Wheel: Zoom
  • Alt+Mouse Wheel: Make a window transparent/opaque
  • Super+N: Make a window negative
  • Super+M: Make the whole screen negative
  • Alt+Left Mouse Button: Drag a window
  • Alt+Click Wheel: Resize a window
  • Ctrl+Alt+Left/Right: Spin the cube
  • Ctrl+Alt+Left Mouse Button: Drag the cube
  • Alt+Tab: Switch applications
  • F10: Expose-like effect
Here's where to configure desirable features in the Beryl Settings Manager:
  • A 3D world: Have windows separated in a third dimension from each other (drag and rotate the cube to see!)
  • Animations: Flames, Magic Lanterns and such
  • Scale: Expose-like effect
Some Beryl demos on YouTube

Monday, May 09, 2011

How to get a RSS feed from a Twitter account

So it seems that Twitter has killed RSS feeds (I'm not sure what that has to do with implementing OAuth), but fortunately, there's an easy workaround.

You can get an RSS feed by querying another URL for the desired user. For instance, to get the RSS feed for user ggreenwald, you can find the feed at this url: http://twitter.com/statuses/user_timeline/ggreenwald.rss

Saturday, March 12, 2011

Facebook Wall question

I sometimes have the question asked of me, "Danny, you are such a strong advocate of transparency and access; aren't you being a hypocrite by not allowing others to comment on your Facebook wall?"

This has always struck me as a rather strange question because it confuses the obligations of a person with the obligations of a state or corporation. It is true that I think that, say, governments should be relatively transparent -- that's a prerequisite for accountability. I, on the other hand, am a priori accountable to no one so I don't have those same obligations.

This accusation is analogous to claiming that WikiLeaks is a hypocritical organization because its members don't share all their internal communication with the world (many in the mainstream media do make this point after each release from WikiLeaks in order to discredit the organization). As if 1) there is any equivalence between the transparency obligations of states/corporations and activist groups or 2) WikiLeaks isn't facing an existential threat from organizations that would use that internal information to try and destroy the group.

But that aside, there is a valid question contained within the query. Why do I have the personal preference of configuring my Facebook Wall settings in such a way? I just don't feel that it is worth the time and mental strain to police my Facebook profile 24/7 to expunge things said by others (whether said out of malice, ignorance or superfluousness) that I would rather not have on there. There are sufficient potentially undesirable comments that may be put on one's profile for this to be a valid concern.

Saturday, May 22, 2010

Multidimensional arrays with GCC's variable length arrays

GCC's extensions allow you to do some crazy things with multidimensional arrays. For C99, GCC implements variable-length arrays. So a declaration like this:

int matrix[a][b + 1];

Can be passed by reference to a function with this prototype:

void foo(int a, int b, int matrix[a][b+1]);

Or, if you want to get really crazy, you can use forward declarations and change around the parameter order:

void foo(int a; int b; int matrix[a][b+1], int a, int b);

No malloc needed! Much better than the old way.

Saturday, April 10, 2010

Which application is using that port?

See which ports are open, as an attacker would:

nmap 127.0.0.1

(Superuser seems to need to be used on some the following commands)

See which process is using port 25:

netstat -nlp | grep 25

Same, with a bit less info:

fuser -n tcp 25

Or you could also do:

fuser -u smtp/tcp

Discovered here

Wednesday, March 17, 2010

Sansa Clip and Karmic

Upon upgrade to Karmic Koala Ubuntu (9.10), my trusty Sansa Clip player was not autodetecting like it did under the Ubuntu distribution I was previously using. So I scoured the web and found this site which gives a workaround: when the Sansa Clip is disconnected, go to Settings->USB Mode on the Sansa Clip and set it to MSC. It should now present itself to the computer as a normal file system. Unless, of course, the file system is screwed up, in which case you'll have to go to Settings->Format and format the Sansa Clip drive before connecting it again.

Friday, March 05, 2010

Funny C tricks

Taken from Bill Rowan's Stanford ACM presentation:

The "downto" operator:

int main()
{
int i = 5;
while(i --> 0) // --> is the downto operator!
{
printf("%d\n", i);
}
return 0;
}

Cast any type to "bool" type (that is, 1 or 0):
!!foo
"Computed goto" (compiler-dependent && unary operator):
void print_loop(int s, int e) {
assert(s < e);
top:
printf("%d\n", s);
goto *( &&top + ( !!(s++/e) ) * ( &&end - &&top ) );
end:
;
}

Tuesday, January 12, 2010

Make a big file into many small files (and back again)

Adapted from this slashdot thread

Create many little files called "chunks00000" etc. from bigfile that are all just under 10MB in size: split -a 5 -b 10MB -d bigfile chunks

Put the chunks back together: cat * > newbigfile

Do the same, except with compression: tar -zc bigfile | split -a 5 -b 10MB -d - chunks

Put the compressed chunks back together: cat chunks000* | tar -zxO > newbigfile

Wednesday, December 02, 2009

Browsing as Googlebot to circumvent paywalls

Interesting technique from a Slashdot article and commenter darthflo:

Most 'papers like Google and the visitors Google sends them; so the Google Bot and hits with a google.com Referer tend to get a free pass. Use this to your advantage:

  • Google the Article's URI, click the link and off you go (with a real Google referer).
  • If it's not indexed yet and you're using Opera: Go to any Google page, press Ctrl + U, change any one link's href to the article's URI, click "Save Changes", click the link and off you go (with a fake Google referer. This works for any fake referer, by the way).
  • If they're picky, they mightn't let hits from Google through but still allow the Google bot to index their pages. Change your User-Agent accordingly. In Firefox, go to about:config and change general.useragent.extra.firefox to Googlebot 2.1 and off you go (as Googlebot).
  • As a last resort, there's quite a few ad-blocking personal proxies out there. Most of them allow you to fake Referers or change User-Agents, for any browser.

Sunday, October 25, 2009

Insidious C bugs

Here's a couple novel C bugs that I've encountered recently (using gcc). Man, it sucks when these happen.

1) No compiler warnings when not instantiating structs correctly

The following code will give no warning indicating that you have not, when declaring an array of structs using the curly bracket notation, instantiated all members of the struct:
#include <stdio.h>

int main()
{
struct a_struct {
int a;
int b;
} buggy[] = {
{ 1, 2, },
{ 3, /* oops! */ },
{ 5, 6, },
};

int i;
for(i = 0; i < sizeof(buggy) / sizeof(*buggy); i++)
{
printf("%i: %i %i\n", i, buggy[i].a, buggy[i].b);
}

return 0;
}
Here's the ouptut:
0: 1 2
1: 3 0
2: 5 6
Oops! It would have been nice for the compiler to tell us about this...

2) Forgetting to delete the semicolon when turning an assert into an if statement

Say you have
assert(cond);
But you want to make it an if statement to have a little more debugging output when it triggers. So you change it to:
if(!cond);  /* oops! */
{
dump_stats();
assert(0);
}
Whoops! Now the if statement has an empty body and the block between the curly braces will always execute!

3) Strange things you can't do within case statements

This isn't really insidious so much as annoying -- why are you allowed to do some things inside a case statement (that don't seem to make sense) but aren't allowed to do others (that seem to make much more sense)? For instance:

int main() {
int i = 0;

switch(i)
{
int j = 5; /* fine */
case 0:
char ch; /* error */
break;
case 1:
i = 1;
char ch2; /* fine */
break;
default:;
char ch3; /* fine */
break;
}

return i;
}
Note the semicolon following the 'default:' There's a good discussion of this problem here. Essentially, the first thing after a label cannot be a declaration. The error that the compiler gives here is usually pretty cryptic, too.

Similar links

Sunday, October 04, 2009

Youtube kung-fu on Linux

This is just a collection of commands that I have used in the past to edit video, especially for uploading to online video sites such as YouTube. This entry is small now, hopefully it grows as I figure out how to do more useful stuff.

# Cut a clip from a whole video file (-ss is base, -t is offset)
ffmpeg -sameq -i input.avi -ss 00:1:23 -t 00:02:35 output.avi

# Boost the volume of a video file
ffmpeg -sameq -vol 1000 -i input.avi output.avi
or, see Avidemux tutorial here: http://www.youtube.com/watch?v=w8K0D2t0ysE

# Dump audio of an flv video file to mp3
ffmpeg -i inputfile.flv -f mp3 -vn -acodec copy ouputfile.mp3

Wednesday, September 23, 2009

Mandating key-based logins with sshd

This page provides a pretty good summary of creating a public/private key pair on the client and adding the public key to the server's authorized_keys file.

On the server side, edit /etc/ssh/sshd_config and add the directive PasswordAuthentication no and then restart sshd with sudo /etc/init.d/ssh restart Anyone that tries to log in to your server without a public key in the server's authorized_keys file will now not even be given the chance to enter a password.

sshd_config manpage

Monday, September 21, 2009

xmonad

Xmonad is a sweet window manager. So sweet, in fact, that I've decided to use it. Here's a quick reference, basically the manpage rearranged (mod = alt by default) ... (also, remember to change the session login to "Run Xclient script" so that other things, like xmodmap, can be run in .xsession):

=== Launch ===
mod-shift-q -- Quit xmonad
mod-q -- Restart xmonad (and reload config file)
mod-shift-return -- Launch terminal
mod-shift-c -- Close the focused window
mod-p -- Launch dmenu

=== Layout ===
mod-space -- Rotate through the available layout algorithms
mod-shift-space -- Reset the layouts on the current workspace to default

=== Focus ===
mod-tab -- Move focus to the next window
mod-shift-tab -- Move focus to the previous window
mod-j -- Move focus to the next window
mod-k -- Move focus to the previous window
mod-m -- Move focus to the master window

=== Swap ===
mod-return -- Swap the focused window and the master window
mod-shift-j -- Swap the focused window with the next window
mod-shift-k -- Swap the focused window with the previous window

=== Resize ===
mod-h -- Shrink the master area
mod-l -- Expand the master area

=== Master Area (the area on the left) ===
mod-comma -- Increment the number of windows in the master area
mod-period -- Deincrement the number of windows in the master area

=== Workspace ===
mod-[1..9] -- Switch to workspace N
mod-shift-[1..9] -- Move client to workspace N

=== Multiple Screens ===
mod-{w,e,r} -- Switch to physical/Xinerama screens 1, 2, or 3
mod-shift-{w,e,r} -- Move client to screen 1, 2, or 3

=== Mouse ===
mod-button1 -- Set the window to floating mode and move by dragging
mod-button2 -- Raise the window to the top of the stack
mod-button3 -- Set the window to floating mode and resize by dragging
mod-t -- Push window back into tiling

=== Setup ===
sudo apt-get install xmonad dwm xlockmore xclock htop

=== ? ===
mod-shift-p -- Launch gmrun
mod-n -- Resize viewed windows to the correct size
mod-b -- Toggle the status bar gap

Here are some other useful utilities to replace functionality that is present in, say, GNOME on the command line:
How to install Xmobar

First, install the necessary packages:
sudo apt-get install libghc6-http-dev libghc6-zlib-dev libx11-dev libxft-dev

I hadn't installed any packages with cabal before, so I needed to set up that as well. I found it necessary to do the standard download, untar, runhaskell Setup configure && runhaskell Setup build && sudo runhaskell Setup install for the following packages:
  • http://hackage.haskell.org/packages/archive/HTTP/4000.0.8/HTTP-4000.0.8.tar.gz
  • http://haskell.org/cabal/release/cabal-1.6.0.2/Cabal-1.6.0.2.tar.gz
  • http://haskell.org/cabal/release/cabal-install-0.6.2/cabal-install-0.6.2.tar.gz
A cabal update initializes the package database and a cabal install xmobar grabs the package.

Put this in your xmonad.hs (changing the paths appropriately, of course):

import XMonad
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Util.Run(spawnPipe)
import System.IO

main = do
xmproc <- spawnPipe "/home/dannyc/.cabal/bin/xmobar /home/dannyc/.xmonad/xmobarrc"
xmonad $ defaultConfig {
layoutHook = avoidStruts $ layoutHook defaultConfig
, logHook = dynamicLogWithPP $ xmobarPP
{ ppOutput = hPutStrLn xmproc
, ppTitle = xmobarColor "green" "" . shorten 50
}
}
And put this in your xmobarrc:
Config { font = "-*-Fixed-Bold-R-Normal-*-13-*-*-*-*-*-*-*"
, bgColor = "black"
, fgColor = "grey"
, position = TopW L 90
, commands = [ Run Weather "EGPF" ["-t"," <tempF>F","-L","64","-H","77",
"--normal","green","--high","red","--low","lightblue"] 36000
, Run Cpu ["-L","3","-H","50","--normal","green","--high","red"] 10
, Run Memory ["-t","Mem: <usedratio> 10
, Run Swap [] 10
, Run Date "%a %b %_d %l:%M" "date" 10
, Run StdinReader
]
, sepChar = "%"
, alignSep = "}{"
, template = "%StdinReader% }{ %cpu% | %memory% * %swap% <fc=#ee9a00>date%<fc> | %EGPF%"
}

There, you now have a bare-bones xmobar install. I figured this out by loosely following the instructions here. I don't know any haskell (yet) and this is my first time messing with the xmonad config, so I don't guarantee at all that I am doing things the Right Way. If your xmonad keeps locking up because of this configuration, see the big bold comment in the link above which points to here.

TODO
  • customize xmobar
  • some kind of screen-like titleing for workspaces
  • better fonts?
  • picture background on startup (/transparent windows?)

Monday, August 24, 2009

Video DownloadHelper Firefox extension + YouTube = Napster

Video DownloadHelper can download videos from YouTube (or other video sites) and convert the audio to mp3 (or other formats) using ffmpeg (the default). Pick the mp4 (high quality / high definition -- these are format 18 or 22) videos off of YouTube to get the highest quality audio (128 kbps).

Ah, this brings me back...

Update: Even better, now that Lala, et al are providing music streaming straight from a Google search, one need not even bother with YouTube -- faster download/conversion, and same (better?) quality.

Saturday, July 25, 2009

Photo metadata

# get exiftool
sudo apt-get install libimage-exiftool-perl

# get libexif CLI tool
sudo apt-get install exif

# erase all metadata
exiftool -all='' img.jpg

# see what metadata tags your photo has
exif -l img.jpg

# see the values of the included metadata tags
exif img.jpg

EXIF specifications: http://www.exif.org/specifications.html
For PNGs: http://pmt.sourceforge.net/pngmeta/index.html

Thursday, July 23, 2009

And now, a demonstration in how ridiculously easy it is to hack stuff with Google

Inspired by this reddit thread (look here for help deciphering the Google syntax).

phpMyAdmin -- inurl:SELECT inurl:FROM inurl:WHERE intitle:phpmyadmin

HP Laserjet printers -- "identify the document you want to print by using either option shown below, then select the apply button."

More printers
-- "Web Image Monitor" location comment "device name"

Web cams
-- inurl:"viewerframe mode="

And, let's not forget the Google Hacking Database or how to use Google to crack MD5-hashed passwords!

Sunday, July 12, 2009

batch: like at, but better

batch is a tool that is identical to at (same manpage even), except it runs a specified job when the load averages are low instead of at a certain time. Very handy if one needs a job to execute on a busy server and doesn't care when it happens, just that it happens.

Sunday, May 31, 2009

Stanford students 'better than other people'?

A telling quote from a Stanford student in today's San Jose Mercury News front-page story:

"When they welcome you to freshman orientation," Robbins says, "part of what they tell you is that you're better than other people."

Not smarter, not better at standardized test scores or kissing ass to get ahead, but unequivocally superior human beings than all those proles that attend state schools. I have to say, this quote typifies the holier-than-thou, aristocratic, snub-nosed attitude that runs through a lot of the student body (and faculty).

Saturday, May 30, 2009

My .pythonrc.py


#!/usr/bin/python

import sys
import os
import atexit

# color prompt
sys.ps1 = '\001\033[1;36m\002>>> \001\033[0m\002'

# tab completion
# from http://www.doughellmann.com/PyMOTW/rlcompleter/index.html
try:
import readline
except ImportError:
# Silently ignore missing readline module
pass
else:
import rlcompleter
readline.parse_and_bind("tab: complete")

# history
# from http://dotfiles.org/~remote/.pythonrc.py
histfile = os.path.join(os.environ["HOME"], ".python_history")
try:
readline.read_history_file(histfile)
except IOError:
pass

atexit.register(readline.write_history_file, histfile)
del os, histfile


If running 'python' on the command line does not run the file, you can always alias python to 'python -i ~/.pythonrc.py'

Tuesday, May 26, 2009

Critique of Laughlin's "The Crime of Reason"

When I saw Robert Laughlin speak at Stanford, I was terribly disturbed by some of his ideas and intrigued by others. As someone who drinks the free software/culture kool-aid, I was always of the opinion that the free flow of information helped humanity, not hurt it. As a follow up on his talk, I decided to pick up a copy of Laughlin's book, The Crime of Reason, to investigate his ideas further. The book, like is talk, contains some very interesting and important ideas but is poorly put together and rather meandering. Writing style aside, the book discusses the following topics, which I will comment on in turn:

The Intellectual Property system is necessary for economic progress

Laughlin states that "Universal access to knowledge is fundamentally incompatible with market economics." (p.45) By this he mostly means that the patent system in the United States is necessary for economic development. He doesn't provide any convincing evidence to back this up, but merely provides a false analogy equating the economy with a game of poker in which everyone has incentives to hide and steal from each other. Perhaps these dynamics apply in certain sectors of the economy (particularly looking through the lens of a physicist who has spent his entire life inside the bowels of the military-industrial complex), but in other cases they do not. The open-source software industry immediately springs to mind as an example in which companies have an interest in freely sharing knowledge with each other.

In any event, the idea of the necessity of a patent system has been completely eviscerated by Boldrin and Levine in their book Against Intellectual Monopoly. Looking at history, the acquisition of a patent in a particular field coincided with a stall of progress in an industry until the patent expired and, not coincidentally, substantially increased patent lawsuits within that industry as the patent holder sought to restrict anyone else from innovating. Patents are a type of monopoly and, as any econ 101 student will tell you, monopolies are a Bad Thing because they deprive both consumers of a low cost for products and also prevent other potential producers from making money by entering the market. Awarding patents is hardly "necessary for living" (p.49) as Laughlin claims.

How and why technical knowledge becomes illegal

The main thrust of the book has to do with the troubling tendency of modern societies to effectively outlaw knowledge. Laughlin compiles a list of fields today whose study has been criminalized in some form or another:

- cryptography
- circumvention (DMCA)
- physics (nukes)
- genetics
- bioengineering (engineered diseases)
- biology (cloning, chimeras)
- national security related processes
- chemistry
- etc.

He asserts that learning about these fields has been criminalized either in the law itself (which is rarely challenged in open court because of the potential government 'secrets' a trial could leak) or by de facto means such as withdrawal of research funds or public ostracism. This development, of course, is quite at odds with the way that learning is supposed to work in our society, as Laughlin recognizes: "Modern civilization rests on two mutually exclusive kinds of thinking -- one embodied in the free speech guarantees in the First Amendment of the U.S. constitution, the other in the Atomic Energy Act." (p.82) His most effective case in point is that of nuclear physics, in which the U.S. government has led a campaign of a quasi-legal nature to suppress the spreading of knowledge on the subject. He reasons that this censorship "set a precedent that has now led, by small steps, to a significant and growing threat to our freedom to reason and learn." (p.84) This is the most convincing, and consequential, argument of the book, and deserves serious thought by all members of our government and society. Are we really willing to sacrifice our freedoms to pursue intellectually interesting scientific facts for the sake of purported security, morality and order?

The consequences for a society which deems scientific knowledge illegal

In the final chapter, Laughlin conducts a thought experiment: what will smart people do if and when we achieve this nightmare society in which the pursuit of any and all interesting technical knowledge is illegal? Laughlin's suggestion that "The sensible course of action would probably be to give up" (p.144) is deeply unsatisfying. He then postulates that the talented technical folk (that is, everyone that didn't become a doctor or a lawyer or a businessman) will either seek employment in the service of rogue dictatorships that allow science, become 'guerrilla warriors' of a sort within their own country or go somewhere else (in the interplanetary sense) to establish a new society where there is no crime of reason. It's very romantic to think of the creation of a new order by a disgruntled segment of society (a la the emigration of persecuted religious groups to America). If it is necessary, however, is another matter entirely. It's certainly way too early, in my opinion, to 'give up' on our present society. A more enlightened public debate on this topic, if not reform, is not out of reach.

You can read other peoples' opinions on the book on Amazon