Monday, May 26, 2014

How to use CapsLock to Left click and more

I wanted to be able to left-click with the keyboard and found that AutoHotKey could help me do that. Here's how to do it:

1. Download and install AutoHotKey
http://download.cnet.com/AutoHotkey/3000-2084_4-10279446.html
2. Run AutoHotkey
3. Modify AutoHotkey.ahk in notepad, adding these two lines. The second line allows you to still use capslock, but it is now mapped to Shift+CapsLock.
Capslock::LButton
+Capslock::Capslock
4. Make other desired changes or removals (see their documentation)
5. Re-run AutoHotkey
6. Make AutoHotkey run every time you start you computer by adding a shortcut to your script to the start menu startup folder, as described in the AutoHotkey FAQ:
AutoHotkey FAQ
You may also want to reference the following for more information.
MouseClick
Remapping Keys and Buttons

 Good luck!

Thursday, May 15, 2014

Edit a file on a Mac (hfs+) partition using a Ubuntu USB stick

  1. download and install the Lubuntu iso onto a USB stick (the dd command works for writing to USB).
  2. Download the hfsplus debian package onto another USB stick.
  3. Boot into lubuntu and install the hfsplus package (sudo dpkg -i <thepackage.deb>)
  4. mount your drive ( mount -t hfsplus -o force,rw /dev/sdXY /media/mntpoint )

Tuesday, April 22, 2014

Simple youtube audio player with VLC

There is a lot of great music posted on YouTube. Before deciding to buy it on amazon, google play, or itunes (are there any other providers of mp3 music these days?), you probably want to play it, but the standard YouTube interface is incredibly ugly, especially when you are just trying to play the music. You can make an ascii text playlist that contains the URL to youtube videos, then fire up vlc like this:
vlc --intf rc -Vdummy <playlist_or_youtube_URL>
type 'help' to see your options. If you want global control over the player, you can set global keyboard shortcuts in Tools.

Monday, September 2, 2013

Google two-step verification with an ipod touch 2g

I recently was given an old ipod touch 2g. Because it can't be updated to iOS 5+, a lot of the new apps don't work for it, including google's new apps. Because I use google's 2-step verification, that meant that putting in my regular google password didn't get me into gmail or calendar. The ipod touch 2g (and most devices, I'm guessing) can be used with google's two-step verification, as it turns out. I've successfully used this approach with Thunderbird as well:

1. Go to your account setting (go to gmail, click your name or picture, click "account")
2. Click "Security"
3. Scroll to the "2-step verification" section
4. Follow "Manage your application specific passwords" link
5. If requested, re-enter your password
6. Follow the directions in the box, "Step 1 of 2: Generate new application-specific password"
6b. (You will put in a name for your device, e.g. ipod touch 2g)
7. Click "Generate password"
8. When you set up your gmail account in the ipod touch 2g (or other device/application), use this application-specific instead of your normal password. (For ipod touch 2g: Setting>Mail, Contacts, Calendars>Add Account...)
9. That's it, good luck!!!

Thursday, September 27, 2012

Update Dell BIOS from linux

NOTE: messing with your BIOS is obviously dangerous.  Proceed at your OWN RISK!
First, install libsmbios-bin
sudo apt-get install libsmbios-bin
Now, you need to get the proper .hdr file.  It is bundled inside those little executables Dell has on their website.  So, start by downloading the latest .exe file from Dell. These can be extracted either with unzip or wine, as shown from this log file.
After trying unzip, I tried this command, and it worked:
wine O780-A13.exe -writehdrfile -nopause
Creating the file: O780-A13.hdr Now, follow these directions (as su or root):
modprobe dell_rbu
dellBiosUpdate -u -f ./O780-A13.hdr
Now just reboot, and wuala, an updated BIOS.

Thursday, August 16, 2012

How to run a ruby script

Windows users:

1. Install ruby

goto http://www.ruby-lang.org/en/downloads/ , then to the Ruby on Windows section and download and install the One-Click Installer.

2. Some scripts can be run simply by clicking on them (this is rare, though).

3. Running scripts from the command prompt

Often scripts want some kind of input or can give useful output. In this case you want to run them from the command line.  See this page on the command prompt in 15 minutes for an overview.
When you have navigated to the directory with the ruby script in it (use the commands cd and dir to get there), you are ready to run your script.  Just type:

ruby myscript.rb

Depending on how windows and ruby has been configured, you may also be able to just type

myscript.rb

Many scripts expect an argument (like a filename) after the script name.  If it does, give it the appropriate argument like this:

myscript.rb filename

Ubuntu/Debian users:

To get it, open a terminal and type:

sudo apt-get install ruby irb ri

Make sure the script is executable:

chmod +x myscript.rb

To run the script:

./myscript.rb

Wednesday, August 15, 2012

How to boot off USB stick ASUS 1201n

This can be a little tricky. Basically, you need to change 2 settings in the BIOS before it will boot off USB. You need to change the boot order and the hard drive order.  [I need to verify the actual names, but I am certain you need to change 2 settings before it will work]

Tuesday, June 12, 2012

Why I'm back to Ubuntu from Linux Mint

Many Ubuntu users were not happy with the decision to use Unity over gnome.  Unity is slick in some ways, but it is (at least originally) very slow and very un-customizable.  A lot of Ubuntu users I know switched to Linux Mint, and I did too.  Now I'm back to Ubuntu 12.03 LTS.

Why did I switch back to Ubuntu?

  • Slower updates and broken repos - Ubuntu updates are slow, but Linux Mint's are even worse.
  • No upgrade option - Linux Mint users aren't really given a simple path to upgrade when new releases come out.  I at least like to try to upgrade one or two editions before doing a fresh install.
  • Better support for Ubuntu - It's easier to search for and get online help for Ubuntu.  There are just enough interfaces (nice, albeit) in Mint that it makes some fixes take longer than they could.
  • The best desktop manager is neither unity or gnome-3 - I use the i3 window manager most of the time.  That means I don't really care what the default windows manager is because I will run my own anyway.  One can still get cinnamon, gnome-3 or mate (these are arguably the best normal wm's for linux) from within Ubuntu.

Monday, April 30, 2012

Indexing Tips for the 1940 Census

These tips were developed by Cindy Snow as a help to increase speed for people who have a membership login on the LDS Family Search website (link) and want to help indexing the 1940 census (you do not have to be a member of the LDS church or have a login to use the FamilySearch site). It is currently posted as a pdf but eventually I hope to put it up as html.

https://www.dropbox.com/s/a5n8pmob97dvjyk/IndexingTipsFor1940Census.pdf

Monday, February 6, 2012

R and Rserve on Windows

This is easy if your system is 32-bit.  If it is 64 bit you need to make sure you are using 32-bit R because the R serve binary is 32 bit!
  1. Install the windows R binary package (accepting the defaults)
  2. Put the R bin directory on your path (right click computer  Advanced Properties  Environment Variables).  
    • For a 32-bit Windows install you should use a path like this:  C:\Program Files\R\R-2.14.1\bin
    • For a 64-bit Windows install you need to link to the i386 folder: C:\Program Files\R\R-2.14.1\bin\i386
  3. Fire up R from the cmd line (make sure that it is the 32 bit R, even if you are on a 64-bit computer) and execute the command: install.packages("Rserve") -- note to where it installs Rserve.
  4. Copy the binaries Rserve.exe and Rserve_d.exe to your R bin directory referenced aboved.
  5. Fire up a new cmd line and run the command: "R CMD Rserve' and configure the firewall popup to allow rserve to work.
  6. You know if everything is working if you can execute this code inside of irb (depends on rserve/simpler [gem install rserve-simpler]):
    • require 'rserve/simpler/R'
  7. Remember to start rserve from a separate commandline window before running any other code.  Also remember that you only get one connection in windows... so make it count.

Monday, August 8, 2011

*Listen* to Youtube on linux (legally)

Per the terms of service, you are not supposed to download YouTube videos. However, it does NOT say that you cannot view them in something other than a web browser.  The main problem with youtube is how much garbage/dodginess there is.  Also, most of the time I just want to listen to the music anyway.... what to do?

The answer: use youtube-dl to provide the correct download link, then stream to mplayer and null the video.

Steps:
  1. Download youtube-dl and put somewhere in your path (such as ~/bin/) and make executable.  If your player breaks, just download the latest version (up within 24 hrs of a youtube site modification) and it should work again.   They have a youtube-dl .deb package in the ubuntu repos, but it is obsoleted pretty fast (for instance 10.04 doesn't work).
  2. make sure mplayer and python are installed: (sudo apt-get install mplayer python)
  3. Use this command:
mplayer -vo null -cookies -cookies-file /tmp/cookie.txt $(youtube-dl -g -f 34 --cookies /tmp/cookie.txt "http://www.youtube.com/watch?v=pGruu89cCw8")


Of course, you will change the video link to be the one you like.  Here is some explanation of what is going on:
  • Youtube requires cookies to be enabled.  We get the video link via youtube-dl and put it into the cookie file.  mplayer is using cookies and reads the url to play from the cookie file.
  • The -g means get the url, and -f changes which file format you are getting the link to (look up youtube codes... current options are 5, 34, 35, 18, 22, 37, 38, 43, 44, 45, 17).  34 is the lowest resolution flv format at 128 kbits/s sound (and I think is standard "360").  18 would give you 96 kbits/s sound.   
  • -vo null means no video output.  Use -fs instead if you want full screen, or nothing for that option if you want regular.
There you have it.  Robust, legal, streaming audio player for youtube.

This also seems to work on short playlists, but not always:

mplayer -vo null -cookies -cookies-file /tmp/cookie.txt $(youtube-dl -g -f 34 --cookies /tmp/cookie.txt "http://www.youtube.com/view_play_list?p=460F66B8E8E56FB6")


Navigate through the tracks with ">" and "<".



Monday, April 11, 2011

rvm with Ubuntu 10.04 and 10.10

If you plan on doing a lot of development in ruby, then rvm (ruby version manager) is the way to use lots of different ruby versions and gems. If you just want to run ruby, you should use your system's package manager.

This is a condensed version of Chistopher Irish's excellent write-up

(leading $ is the bash prompt)

$ sudo apt-get install curl git-core ruby
$ bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)

If you haven't already replaced your .bashrc, you probably have a line in there like this:
[ -z "$PS1" ] && return

Replace that line with:

if [[ -n "$PS1" ]]; then

Then, add this to the last line of the .bashrc file (however, you can leave off that very final, dangling 'fi' if you did NOT have a return statement that you replaced earlier).

if [[ -s $HOME/.rvm/scripts/rvm ]] ; then source $HOME/.rvm/scripts/rvm ; fi

fi

There are going to be prerequisites to installing most ruby's. Use the command rvm notes to discover those dependencies for your system.

Okay, we'll grab some prerequisites for compiling 1.9.2:

$ sudo aptitude install build-essential bison openssl libreadline5 libreadline-dev curl git-core zlib1g zlib1g-dev libssl-dev vim libsqlite3-0 libsqlite3-dev sqlite3 libreadline-dev libxml2-dev git-core subversion autoconf

Now, we can list the ruby versions we can install, install 1.9.2, and set it as default.


rvm list known  # see which ruby versions we could install
rvm install 1.9.2-head
rvm --default 1.9.2-head  # make ruby 1.9.2 our default

Tuesday, March 15, 2011

bacon and autotest

Took a little to figure this out, so thought I would share.  You need an empty file in your spec folder called .bacon in your spec folder.  This appears to load up a lot of the proper bacon environment things into autotest.  However, if you want to override specific behaviors, you do that in a .autotest file in the top directory.


touch spec/.bacon

Inside .autotest:
require 'rubygems'
require 'bacon'
require 'autotest/bacon'

# see inside /lib/autotest/bacon.rb for template

class Autotest::Bacon < Autotest
  undef make_test_cmd
  def make_test_cmd(files_to_test)
    # I modified this to only include _spec.rb files:
    args = files_to_test.keys.flatten.select {|v| v =~ /_spec.rb$/ }.join(' ')
    args = '-a' if args.empty?
    # TODO : make regex to pass to -n using values
    # use bacon -h to see all your possible options!
    "#{ruby} -S bacon -I#{libs} -o TestUnit #{args}"
  end
end

Monday, March 7, 2011

image landscapes for ebooks (and other digital-based reading)

The problem with electronic text is that it lacks the spatial character of a book.  You don't really know where you are at in a giant, monolithic column of perfect text, especially when resizing it changes where text is located.  However, in a book, you have several spatial cues that are constant: which page, which part of the page, how deep into the book (depth) and any imperfections on the page itself or with the text.  So, with ebooks, how can you duplicate this effect?

One could write a program that lays books out so that the book is more like a book (there are cues that indicate depth, etc.).  With svg you could easily add certain permanent imperfections to the text to give it more character.

There are two other ways to add a spatial dimension to reading text:

1. Layer text, or pages, into a 3D landscape.  If the pages of your book traversed an interesting cityscape, room, landscape, or mountain path, etc., you would have spatial anchors upon which to peg the text.

2. The page itself could link out into either auto-generated or user defined images (or text).  In this way, each page is given visual character that links it to other ideas and images.

IMO, both the ideas and the implementation of these ideas (i.e., embedding pages of text, with textual imperfections into a 3D landscape, or adding pictures and text to the pages of the book itself, etc.) are obvious and trivial.  Any college student taking a web or 3D design class could do it.  It merely remains for someone to do it.

Monday, February 21, 2011

ruby list comprehension

I have seen list comprehension cited as a feature of python that ruby lacks. I want to play around with the idea to see where it goes...

[disclaimer: this is just scratch space for ideas at the moment]

(I wonder how lazy enumerators will change the ruby approach?)

A nice write up on list comprehensions in python has an example where you can use list comprehension to find prime numbers. They divide it into two steps because it gets a little hairy on one line. Here's finding primes on one line using list comprehension:


>>> [x for x in range(2, 50) if x not in [j for i in range(2, 8) for j in range(i*2, 50, i)]]
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]

It's not bad, but it's easy to get lost in there (my ruby eyes are not highly trained in python, of course).

Now, one of the things list comprehensions do is it does selection and modification in the same phrase. This part of list comprehensions is easy to implement.

[ add the equivalent python here ]


(2..10).select(&:even?).map {|v| v**2 }
(2..10).map {|v| v**2 if v.even? }.compact

Implementing this aspect of list comprehensions in ruby is less than trivial:


module Enumerable
  def lc(&block)
    block.nil? ? self : self.map(&block).compact
  end
end

The other part of list comprehensions is the fact that the evaluation happens from right to left (in the python code) so that the execution of the code is efficient.

This gets the job done, but the right-most block is executed multiple times to make it work:

(2..50).reject {|j| (2..8).map {|i| (i*2).step(50,i).to_a}.flatten.include?(j) 

# also other ways to think about this (need to finish this post)
Set.new(2..50) - (2..8).reduce(Set.new) {|np,i| np.merge((i*2).step(50,i)) }

Wednesday, February 9, 2011

Using Dropbox and git

Dropbox is really fantastic, but its version control abilities are limited. Git is a fantastic tool for versioning things.  Here's how I use both to keep detailed version history of the projects that matter to me:

Solo Repo (use a Normal git repo)


For most projects, I do not need to merge changes with multiple people, but I want a version history. For these, I set up a normal git repository. This repo has no "origin", so I never push to anything, just stage and checkin.


cd ~/Dropbox/myproject
git init
git add .
git commit -m 'first commit'
# after a while
git status
git commit -a -m 'another commit' 

Easy to do, and all my changes (even when I don't happen to check them in) follow me on all the computers I use dropbox on.

Shared Repo (use a Bare git repo)


In this case, I'll make a bare git repo and then share the folder with others. I'll assume I'm starting with an existing project directory, but it is not a git repo yet. (there are other ways to do this).


# my project is sitting on my local machine somewhere.
# I will make it a normal git repository
cd someproject
git init
git add .
git commit -m 'first commit'
# now make a bare git repository on my dopbox folder
# by convention, bare repos end in '.git'
mkdir -p ~/Dropbox/git/someproject.git  
pushd ~/Dropbox/git/someproject.git 
git init --bare
popd  # back where I was
git remote add origin ~/Dropbox/git/someproject.git
# now we can push and pull to our origin (see below if you get errors)
git pull
git push

If you get trouble when pushing or pulling to your remote, add these lines to your ~/.gitconfig file:


[push]
 default = matching
[branch "master"]
 remote = origin
 merge = refs/heads/master

Friday, December 17, 2010

Shell escaped file names in ruby

When files have crazy characters in their filename (like ' or ""), it can make creating a robust script challenging. After all, if you write the script with either a single quotation mark or a double quotation mark, the other one will trip you up:


file1 = "my'crazy'file.txt"
file2 = 'my"crazy"file.txt'
system "mv \"#{file2}\" bettername.txt"  # fails on file2
system "mv '#{file2}' bettername.txt"    # fails on file1

The answer is to use the multiple arguments invocation, which will properly escape your filename to be fully shell compatible:

system "mv", file1, "bettername.txt"  # works on file1 or file2

Thursday, December 9, 2010

Playing with (compiling) the redesigned NArray

Masahiro Tanaka has been redesigning NArray. Word is that it may be pulled into mainline ruby.

So, what is it like? Amazing from what I can tell. How do you play with it? At least on Ubuntu 10.10, this is what I did (there may be other dependencies I've neglected here):


sudo apt-get install libatlas-dev libatlas-base-dev
# modify extconf.rb:
have_header("atlas/cblas.h")   ===>   have_header("cblas.h")
# modify linalg.c
#include <atlas/cblas.h>   ===>   #include <cblas.h>
# for ruby 1.9, you also need to change a few normal array things:

diff -r ../narray-new-1.8/narray.c ./narray.c
211,212c211,212
<     n = RARRAY(idxargs)->len;
<     ptr = RARRAY(idxargs)->ptr;
---
>     n = RARRAY_LEN(idxargs);
>     ptr = RARRAY_PTR(idxargs);
232c232,233
< const static size_t zero=0;
---
> //const static size_t zero=0;
> static const size_t zero=0;
463c464
<      ndim = RARRAY(v)->len;
---
>      ndim = RARRAY_LEN(v);
761a763
>     VALUE *ptr;
774,775c776,778
<  RARRAY(v)->ptr[i] = SIZE2NUM(na->shape[c]);
<  RARRAY(v)->len++;
---
>  RARRAY_PTR(v)[i] = SIZE2NUM(na->shape[c]);
>  ptr = RARRAY_LEN(v);
>     ptr++;
diff -r ../narray-new-1.8/nstruct.c ./nstruct.c
301c301
<      ndim = RARRAY(argv[i])->len;
---
>      ndim = RARRAY_LEN(argv[i]);

now, you should be able to "ruby extconf.rb", "make", and then require 'narray' or require './narray.so'

Tuesday, September 28, 2010

Compile ruby 1.9.2 on Ubuntu

assumes you have build-essential package installed
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p0.tar.bz2
tar -xjvf ruby-1.9.2-p0.tar.bz2
cd ruby-1.9.2-p0
./configure --enable-shared --program-suffix=1.9.2
make
make check # optional
sudo checkinstall make install
# [follow the defaults until here:
# NOTE that you want the extra files inside your directory.
# those extra files contain things like the openssl libraries!!

    Some of the files created by the installation are inside the build
    directory: /home/jtprince/src/ruby-1.9.2-p0

    You probably don't want them to be included in the package,
    especially if they are inside your home directory.
    Do you want me to list them?  [n]: n
    Should I exclude them from the package? (Saying yes is a good idea)  [y]: n

# At this point, you can install the package on machines of the same
# architecture with "sudo dpkg -i ruby-1.9.2_p0-1_amd64.deb" [depending on your arch]

sudo rm /usr/bin/ruby
sudo ln -s /usr/local/bin/ruby1.9.2 /usr/bin/ruby

Okay, now you need to get rubygems working properly. Remember, rubygems comes with ruby 1.9.X, so you don't need to download it separately.

At this point, we have to ensure our soft links point where we want and to tell gems to point to ruby 1.9.2

sudo cp /usr/bin/gem1.9.{1,2}
# then edit /usr/bin/gem1.9.2
# change #!/usr/bin/ruby1.9.1 ==> #!/usr/local/bin/ruby1.9.2

# now set up the soft link so that "gem" calls our gem1.9.2
sudo rm /etc/alternatives/gem
sudo ln -s /usr/bin/gem1.9.2 /etc/alternatives/gem

Maybe it is unnecessary, but I moved my local gem folder so that all my gems are compiled from scratch again to ensure they have been built against 1.9.2. how to set up a local gem environment

mv ~/.gem/ruby/{,not_using_}1.9.1
mkdir ~/.gem/ruby/1.9.2

Tuesday, September 21, 2010

Installing graphviz on Ubuntu Lucid Lynx 10.04

If you want sfdp (a great layout for large graphs), then you need the .debs from the graphviz site (not through the ubuntu repos).

Download the develpment snapshots here
note, if you don't use the language specific bindings listed, you don't need to download those.

sudo aptitude install libdevil1c2 libgtkglext1
sudo dpkg -i graphviz_*.deb graphviz-dev*_all.deb 
graphviz-doc*_all.deb libgraphviz4_*.deb libgraphviz-dev_*.deb libgv-ruby_*.deb

Now, you can run sfdp!