Showing posts with label howto. Show all posts
Showing posts with label howto. Show all posts

Monday, December 29, 2014

Looking for a cheap Bluetooth-capable portable MP3 player? Buy a no-contract smartphone and don't activate it!

My father needed a portable Bluetooth-capable MP3 player with large or expandable memory. Portable MP3 players with such features typically sell for $80+ (Trio mini), with the nicest units being at least $150 (iPod nano) or much more. The cheap models have terrible battery life (3 hours for Trio mini). Creative solution? He bought a no-contract LG Optimus Exceed 2 from Verizon Wireless for less than $50 at Best Buy and used a 16GB microSD card that he already owned.
LG Optimus Exceed 2, Prepaid (no-contract) Phone from Verizon Wireless
This particular no-contract phone is fast, runs Android 4.4.2, and can be used without activating. In fact, it is very easy to bypass the initial activation screen with a special key sequence – volume up, volume down, back, home – pressed after restart at the language selection screen. After bypassing that screen just once, the phone is happy to run unactivated indefinitely after that – it will never present that activate screen again. Use airplane mode to prevent phone from looking for a network to save battery, and flip on WiFi and Bluetooth. It's like a $50 iPod touch. Nice deal.

You can get this phone from a number of places, as shown in links below. Of course, there are other no-contract phone choices you could make (check all no-contract carriers – Boost Mobile, Virgin Mobile USA, T-Mobile, etc.). If you're willing to compromise on the phone software or other capabilities, you can get decent "MP3 player phones" for $30 or even $20.
For example, you can get essentially the same phone from Boost Mobile packaged as the LG Realm for only $35 on Amazon right now. It's $40 from other retailers.
LG Realm, Prepaid (no-contract) Phone from Boost Mobile
So that's like a $35 iPod touch. Even nicer deal!

Tuesday, October 09, 2012

natbib-like frontend for chicago-style macros

For some reason, the ACM has baked in chicago-like citation macros into the ACM SIG proceedings LaTeX templates instead of using the far superior natbib that literally everyone else on the planet uses. I'm much more accustomed to typing \citet as opposed to \shortciteN, \citeauthor as opposed to \shortciteANP, etc. So I decided to add this little translation table to my preamble:
\def\citet{\shortciteN}
\def\Citet{\shortciteN}
\def\citeauthor{\shortciteANP}
\def\Citeauthor{\shortciteANP}

\let\chicagociteyear\citeyear
\def\citeyearpar{\chicagociteyear}
\def\citeyear{\citeyearNP}

\def\citep{\shortcite}
Unfortunately, that means I can't use any of the optional arguments to \citep or \citet. If you are just looking for a translation table so you can use the chicago-style macros directly, try this:
natbibchicago
\citet or \Citet\shortciteN
\citeauthor or \Citeauthor\shortciteANP
\citeyear\citeyearNP
\citeyearpar\citeyear
\citep\shortcite
It's crazy how chicago-style macros sometimes use "N" to mean "noun" and other times to be the first half of "NP" being "no parentheses."

Tuesday, November 08, 2011

Building ElectricSheep on Fedora 16 (and enabling in KDE4)

UPDATE: Apparently these steps also work on Fedora 17. Moreover, if you use Gnome3, there are some additional instructions that can help you get ElectricSheep setup.
Quick link: Updated makeSheepFedora16.sh install script
A while back, I wrote a post summarizing how to get ElectricSheep running on Fedora 15 with KDE 4.6.5. Today, I "upgraded" to Fedora 16 and was surprised to find that library updates were incompatible with ElectricSheep. Symbol mismatches made it impossible to simply symlink old shared libraries to new shared libraries. Moreover, the version of electricsheep that built fine on Fedora 15 would not build on Fedora 16.

So I made some modifications to Tait Clarridge's script to fix the build. My hacks seem to work for me so far; hopefully they do not introduce regressions into the already old version of electricsheep.

So to get ElectricSheep running on your Fedora 16 system, try downloading and running my modified makeSheepFedora16.sh script. As a bonus, it (hopefully) will install ElectricSheep as a screensaver if you are running KDE. However, the same DPMS caveats about mplayer from old post still apply until Fedora updates their mplayer to a recent version (why does it take these people so long?).

Tuesday, September 20, 2011

Duplex Printing from the Command Line to an HP LaserJet Printer

My department has several HP LaserJet printers available to access within the department via LPR and SMB. However, if you are working from a personal laptop connected to the university wireless, those servers will not be available to you. Instead, you must print by piping your documents through SSH to a department server that does have access.

Unfortunately, doing duplex printing (i.e., two-sided printing) to an HP LaserJet printer from the command line is not trivial. So, using the GSview documentation as a guide, I put together a small bash script (available for download as hplj_duplex_print) that does the trick.
#!/bin/bash

declare -a input_file
if test $# -eq 0; then
    input_file=("-")
else
    input_file=("$@")
fi

( echo -e "\e%-12345X@PJL JOB"
  echo "@PJL ENTER LANGUAGE = POSTSCRIPT"
  echo "<< /Duplex true /Tumble false >> setpagedevice"
  gs -sDEVICE=psmono -sPAPERSIZE=letter -q -sOutputFile=- \
    -dNOPAUSE -dBATCH "${input_file[@]}"
  echo -e "\e%-12345X@PJL EOJ"
  echo -e "\e%12345X"
  ) | lp -d your_HP_printer_spool_name
You should replace the your_HP_printer_spool_name with your printer's spool name. You might want to tweak some of the options (details below), but the general structure will remain the same. The opening and closing escape sequences communicate to the HP LaserJet printer that a PostScript file is coming. Then the setpagedevice PostScript directive instructs the printer to use its duplex module.

Regarding tweaking:
  • Again, make sure to change your_HP_printer_spool_name to your spool name. You may also want to change lp to lpr, but you will likely have to change -d to -P then.
  • You may want to change the gs (GhostScript) options to suit your purposes. For example, you can change the psmono device to one of the other GhostScript devices like psgray or psrgb.
  • The Tumble switch determines whether to do short-edge (true) or long-edge (false) duplex printing, and so this script defaults to the latter case. If you prefer vertical flipping, change the /Tumble false to /Tumble true. You might also make this a configurable command-line switch on the script.

Wednesday, August 31, 2011

Electric Sheep on KDE 4.6.5 with Fedora 15 (using Intel graphics card)


This post begins with a few important updates; scroll down to see the bulk of the original post.

Fedora 16 update: If you are using Fedora 16, then see updates from a newer post about how to get ElectricSheep built and running.

DPMS Update (getting monitors to sleep/standby/suspend/turn off on schedule again): It turns out that electricsheep is preventing my monitors from getting DPMS sleep/standby/off signals because of a bug in mplayer that was fixed today in SVN r34074. If you pull down the updated mplayer and build it yourself, your DPMS problems with electricsheep will be fixed. If you aren't willing to pull down the SVN source and build the fixed binary, you could use something like this sample electricsheep-wrapper script that starts both electricsheep and a secondary process that reads waiting times from xset q, sleeps for those times, and then issues the appropriate xset dpms force commands. To use the hack, all references to electricsheep in KDE or xscreensaver configuration files must be changed to electricsheep-wrapper and the electricsheep-wrapper script has to be installed in a directory in the PATH. Or, again, you can just wait for mplayer to get patched in your Linux distribution.

KDE update: electricsheep's SourceForge SVN includes a Desktop file for KDE, and so I've updated the stuff below to use it instead. It's probably a good idea to check out their updated SVN repository at GoogleCode to see if the support files have improved.

Multiple Monitors update: KDE will stretch one electricsheep across all of your monitors. Instead, if you want electricsheep to put a different instance on each monitor, use xscreensaver instead of kscreensaver. To do so, you'll have to follow the instructions for using xscreensaver on KDE, which are also on the xscreensaver man page. I modified step 4 to use my own custom system-level kscreenlocker that doesn't force everyone on the system to use xscreensaver. Additionally, to get electricsheep to show up in the xscreensaver-demo menu, you need to not only install the relevant electricsheep.xml file (find it in the source repo's or built it yourself), but you also have to add a line to your own ~/.xscreensaver configuration file. I don't know why the former doesn't generate the latter. On one of my machines, it does. On the other, it doesn't.

Of course, YMMV.


I installed electric sheep today because I was bored of my ASCIIQuarium KDE screensaver and not thrilled about the other options (some of which bail out on my dual screen Intel setup). [ If you're not familiar with Electric Sheep, you should check out the Electric Sheep Wikipedia page which discusses how the screensaver evolves over time. It's a distributed computing project, and the genetic algorithm that guides the evolution actually takes input from Electric Sheep users (well, not me, because I don't have the keyboard support to "up" and "down" the sheep I see). So the screen saver is constantly downloading and processing new AVI's, generating new content, and contributing it back to the network. I like it because it's pretty screen saver diversity at the cost of a few computing cycles and some disk space. ] It wasn't so bad, but it also wasn't trouble free. Here's what I did (which almost worked entirely without me having to do anything special):
  1. Use the Fedora-specific script from Tait Clarridge's page on downloading and installing electric sheep in Fedora (if you are running Fedora 16, see my updated script instead).
  2. Learn from Giulio Guzzinati about the need to add an electric sheep KDE Desktop file to get the screensaver into the KDE Screen Saver configuration tool.
Unfortunately, Giulio Guzzinati's desktop file didn't work for me, and so I had to build my own use the desktop file inside the electricsheep distribution. Here the file that ended up "working" for me (which is downloadable as electricsheep.desktop, but I copied from electricsheep.desktop.kde in the SVN repo).
[Desktop Entry]
Exec=electricsheep
Icon=kscreensaver
Type=Service
X-KDE-ServiceTypes=ScreenSaver
TryExec=xscreensaver
Actions=InWindow;Root;Setup;
X-KDE-Category=Fractals Screen Savers
X-KDE-Type=xv
Name=ElectricSheep

[Desktop Action Setup]
Exec=electricsheep-preferences
Name=Setup...

[Desktop Action InWindow]
Exec=electricsheep -window-id %w
Name=Display in Specified Window
NoDisplay=true

[Desktop Action Root]
Exec=electricsheep -window-id %w
Name=Display in Root Window
NoDisplay=true

X-Ubuntu-Gettext-Domain=desktop_kdeartwork
As explained in Giulio Guzzinati's post, you can place that file in
/usr/share/kde4/services/ScreenSavers/
You can probably put it in
~/.kde/share/services/ScreenSavers/
as well (you might have to create that directory first) if you'd rather do something local. That put the Electric Sheep across both of my monitors. If you'd rather put a separate electricsheep in each monitor, use xscreensaver instead of KDE's screen saver. If you're having trouble getting your monitors to go to sleep while electricsheep is running, then you need to get an updated mplayer that fixes the bug that causes that problem (see the updates at the top of this post for more information). Alternatively, you can use a hack like this electricsheep-wrapper script to re-enable DPMS-like timeouts during the screensaver. To use the hack, all references to electricsheep in KDE or xscreensaver configuration files must be changed to electricsheep-wrapper and the electricsheep-wrapper script has to be installed in a directory in the PATH. However, it probably won't be too long until the mplayer DPMS fix reaches your Linux distribution.

Thursday, August 25, 2011

Using \gobblepars to prevent LaTeX from adding empty lines at gaps

While searching for something else, I came upon a StackOverflow question from a while ago that asked how to prevent LaTeX from adding a \par at particular blank lines in the source code. The asker didn't want to remove blank spaces everywhere; he just wanted to get rid of the paragraphs at certain spots.

Of course, you can use comments to do this:
\somemacro{}
%
Some text
However, a lot of people don't like the look of that. Some of the responders on StackOverflow gave some alternatives that seemed ugly and half baked. So I came up with \gobblepars, which is a macro you can add to the end of your own macro definitions to cause them to eat up all trailing pars, or you can use explicitly. For example:
\somemacro{}\gobblepars

Some text
would do the same as the commented stuff above. Moreover, if you had control over \somemacro, you could build \gobblepars into it (in fact, even if you didn't have control, you could use \let and \def to augment an existing macro with a trailing \gobblepars, but that's a different topic).

Here's the simple definition of \globblepars (you put this in the preamble of your LaTeX document):
\makeatletter
\newcommand\gobblepars{%
    \@ifnextchar\par%
        {\expandafter\gobblepars\@gobble}%
        {}}
\makeatother
So that's pretty simple. It checks for a \par (which includes a blank line in the source) trailing it. If it finds one, it gobbles it up (i.e., gets rid of it) and then calls itself again. This process will continue until it finds something other than a \par. Hence, it "gobbles" strings of "pars".

Monday, August 22, 2011

Converting an EMF (MetaFile) on Linux using unoconv

When I needed to convert a graphic from an EMF (Windows Enhanced MetaFile) on my Linux machine today, all of my Google searchers were turning up with conversion utilities for Windows or wine at best.

Fortunately, it appears as though unoconv converts from EMF and is available in the standard Fedora repositories. I issued:
unoconv MYMETAFILE.emf
and it spit out a MYMETAFILE.pdf, and I was happy.

Monday, July 18, 2011

How we fixed our Ikea wardrobe after the bar fell

Our apartment has no bedroom closet space. There are two coat closets and a linen closet all clustered in the same wall between the living room and office and near the bathroom, but there is no storage in the bedroom. So a while back, we bought three large Ikea wardrobes that fit nicely next to each other down one of the walls of our bedroom. This particular wardrobe model was one of Ikea's budget options (i.e., it was not one of their crazy customizable types; it basically came as a complete unit). The closet bar (shown here without the shelf that is usually above it) should attach to the closet using a plastic insert like this (click on the image for a larger and clearer version):
As you may be able to see, there is a large vertical scrape a few inches beneath the plastic insert. That scrape came into our lives when the plastic insert on the left side of the bar failed ("wardrobe malfunction"), which sent the awkward-shaped metal closet bar (and the clothes hanging on it) into the floor of the wardrobe. As you can see, there is a cantilever-type support jutting out from the plastic insert that sheared off (pretty clean cut, actually):
Ikea often keeps spare parts like this on hand that you can grab for free in bins from the store, but we didn't want to drive all the way to West Chester to look for them, and we were pretty sure these wardrobes were discontinued and these (likely specialized) parts were not available. So we went to Meijer instead (it was too late to go to a hardware store to find real closet accessories) to look for a way to hack together a good pre-fabricated furniture fix.

Just before we were about to give up, we found these corner braces that looked like the perfect size and shape for our problem. They were about $2.50 for a pack of 2 (in case any of the other supports ever break later).
So here's how we used a corner brace to support the closet bar:
As a bonus, the screws that came with the corner brace were short enough to not protrude out the side of the wardrobe. They were self-tapping screws, but I didn't trust them in the Ikea-style formica-covered particle board, and so I pre-drilled some small holes first, and that worked pretty well. We used a zip tie to fix the bar vertically; however, we also experimented with binder rings that we had stowed away in our office supplies. The binder rings actually provided a much tighter fit so that the bar didn't wiggle at all; however, as strange as it sounds, the zip ties were a little more discrete as they hugged the corner brace snugly.

[ I should note that I took off the shelf to get easier access to the closet. That meant pulling out the three small brads/nails attaching the masonite-ish backing. Because the area moment of inertia of that backing is very high, I think it provides significant support to the closet structure as a whole. So afterward, I pulled the closet out and put the nails back in a different spot. I probably could have left the shelf in through the whole fix. ]

I almost like the look of our fix better than the Ikea insert (which looks like it has a tenuous hold on the bar anyway).

[ You can also find this post at Jessie and Ted's blog. ]

Tuesday, March 08, 2011

Installing Adobe Digital Editions on Linux with Wine

UPDATE: I have not had time to address the download issues some people have had when trying to install ADE. However, see the comments on this post for some additional tips on where to find an ADE installer download that you can run inside Wine.
Unfortunately, Adobe does not provide a simple download link for the Windows version of Digital Editions, and so if you want to purchase a PDF or ePub e-book with Adobe ADEPT DRM protection, it is very difficult to get up and running on Linux even if you have Wine installed. Here's how I did it.
  1. Install Wine on your system. Most Linux distributions provide Wine as an optional install (e.g., sudo yum install wine from the command line on Fedora).
  2. You will need Gecko extensions available to run the iexplore.exe web browser that comes with Wine. Visit the Wine Wiki's Gecko page for information on how to install Gecko. Your Linux distribution may have a "wine-gecko" package. If it doesn't, then follow the simple instructions on the Wine Wiki.
  3. You will also need Adobe Flash installed on your Wine system, and so you should visit the Wine Wiki's Flash page to get the install_flash_player.exe download link. Download the exe and run it in Wine (e.g., wine install_flash_player.exe from the command line).
  4. Now, start the iexplore.exe browser bundled with Wine. After I ran Wine for the first time, it setup a .wine directory in my home directory (i.e., ~/.wine). I found the iexplore.exe in ~/.wine/drive_c/Program Files/Internet Explorer. Change to that directory and run iexplore.exe (e.g, wine iexplore.exe from the command line).
  5. Now you can visit the Digital Editions installer (which is written in Flash). From the Wine Internet Explorer, enter in the URL:
    http://www.adobe.com/products/digitaleditions/ade_web_library.swf
    That should startup a little installer. Follow the prompts to download and install Digital Editions. You will even be able to launch it from there.
    • The installer will install the single Digital Editions executable to ~/.wine/drive_c/Program Files (x86)/Adobe/Adobe Digital Editions as digitaleditions.exe.
    • You can run it again but executing that file through wine (e.g., wine digitaleditions.exe from the command line in that directory)
    • Alternatively, you can use the "Digital Editions" shortcuts that the installer probably placed on your desktop.
  6. Once Digital Editions is started, you should be able to drag-and-drop ACSM files you've downloaded from e-Book commerce sites (like Google Books), and it should download the Adept-DRM'd version of your media.
    • DRM'd books are stored in the My Digital Editions folder that will be created in your home directory.
    • If you want to put them elsewhere, you need to edit the symbolic links in ~/.wine/drive_c/users/USERNAME where USERNAME is your Linux username. The My Documents folder was symlinked to my home directory by default. I got rid of the symlink and created a real directory there instead, but you could point the symlink somewhere else if you'd rather. Regardless, the My Digital Editions folder will reside inside the My Documents folder (alongside a My Books folder, but I don't know what gets put in there... maybe non-DRM stuff you put into ADE?).
Once you have your DRM'd books, you should be able to transfer them onto devices that have also been authorized with your Adept key (e.g., a Sony Reader that has been authorized with the same account you used inside Digital Editions). I suppose it's possible to get the Digital Editions running inside Wine to notice when your reader is connected, but I haven't tried it (that might involve installing the Sony Reader Library software within Wine, and I received some ugly errors when I tried to do that (but YMMV)).

Tuesday, January 04, 2011

Drawing a circle in MATLAB (curved rectangle instead of approximating with filled polygon)

Today, someone I know googled for some help drawing a filled circle in MATLAB and asked me what I thought of the code that was found. The code found, which seems to be the conventional way to draw circles in MATLAB according to Internet posters, generates a polygonal approximation of a circle and then fills it. It goes something like this (where you can use linspace(0,2*pi,N+1) and daspect([1,1,1]) (or axis square) instead of two of the commands used here):
xc = 0;
yc = 0;
r = 2;
N = 256;
theta = (0:N)*2*pi/N;
x = r*cos(theta) + xc;
y = r*sin(theta) + yc;
fill(x, y, 'k');
axis equal;
where (xc,yc) is the coordinate of the center of the circle, r is the radius of the circle, and (N-1) is the number of sides of the polygon that is inscribed inside the desired circle (i.e., the polygon's corners intersect the circle). The circle is filled with the color black, which corresponds to the 'k' parameter of the fill command. To quickly get rid of the circle without clearing the figure, change the fill command so its figure handle gets assigned to a variable (e.g., h = fill(x,y,'k');) and you can delete that figure handle later (e.g., delete(h);). I notice that some people precede the fill command with a plot(x,y); command, but that is not necessary; the fill command will construct the closed finite polygon and put a (black) border around it by default, and so there is no need to draw the border ahead of time with plot.

[ Of course, there are methods very similar to the above that use a rotating complex phasor (i.e., a complex exponential from r*exp(i*theta)) and then let plot generate the projected Cartesian plane coordinates from the complex plane. These methods are equivalent but depend on MATLAB to do the trigonometry behind the scenes, which may or may not be faster... ]

What surprises me is that there is a perfectly nice built-in MATLAB command that will draw rectangles, rounded rectangles, circles, and ellipses very quickly essentially without having to approximate them with finite polygons. It is the rectangle command. Some of the people who posted code like the above example apparently know about the rectangle command (because they use it to verify that their circular approximation is sufficiently circular); however, I guess it's not ideal for them because it references the figure to a corner as opposed to its center. Nevertheless, a lot of people who might not be as picky may not know about the rectangle command, and so here's an example similar to the above.
w = 4;
xc = 0;
yc = 0;
rectangle('Curvature',[1 1], ...
          'Position',[xc-w/2 yc-w/2 w w], ...
          'FaceColor','k');
axis equal;
The 'Curvature' property tells MATLAB that the lines connecting the corners of the rectangle should have no straight portions. By decreasing each of the 1's to 0 in the curvature property, the circle looks more like a rounded rectangle with flat sides and rounded corners. The 'Position' property places the bottom-left corner of the rectangle in its first two elements and then sets the width and height of the "rectangle". So here, a circle centered at (xc, yc) is drawn with a radius of w/2. The circle is filled with 'FaceColor'. Again, axis equal; could be replaced with daspect([1,1,1]); or axis square;. Additionally, rectangle can be assigned to a variable (e.g., h = rectangle(...);) so that the rectangle can be easily removed later (e.g., delete(h);) without having to clear the figure. So this example draws a circle, but by playing with the rectangle parameters, it is easy to draw rectangles, rounded rectangles, and ellipses as well.

It is possible that the former method might be faster, but I can't imagine it would be much faster. The latter method seems more elegant and intuitive to me, and I have to imagine that's what the people at Mathworks would advise you to use if you called them up. Having said that, I have not called them up, and so you decide for yourself.

Wednesday, September 08, 2010

How to put "1 of ..." page numbers on a LaTeX letter

Someone e-mailed me recently to ask how to add "1 of LAST_PAGE" page numbers to a LaTeX letter document. I generated the sample LaTeX document fancy_letter_numbering.tex to show how it's done using the fancyhdr and lastpage packages.

Here is my response, which gives more details:
I have attached a sample letter with "1 of ..." page numbering throughout. fancyhdr works with "letter" just as well as it works with "article." You just have to treat "\opening" just like you do "\maketitle."

In particular, put this up in your preamble:
\usepackage{lastpage}
\usepackage{fancyhdr}
\fancyhead{}
\fancyfoot{}
\cfoot{\thepage{}~of~\pageref{LastPage}}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
Then, after each "\opening" (in the case of a single letter, there will only be one), put the line:
\thispagestyle{fancy}
Otherwise you will get page numbers on every page except for the first one.
Of course, you will have to run LaTeX (or PDFLaTeX) at least twice to place the "LastPage" label properly and generate the correct page refeference.

[ Additionally, you may further customize the headings and footers making use of all of the nice features that come with the fancyhdr package. ]