tag:blogger.com,1999:blog-91704346946479008662024-02-19T07:33:14.908-08:00sudo or do notlinux, programming, calculators, technology...JTPhttp://www.blogger.com/profile/07535605477911297179noreply@blogger.comBlogger85125tag:blogger.com,1999:blog-9170434694647900866.post-35905076352079760772014-05-26T11:27:00.001-07:002014-05-26T11:29:38.248-07:00How to use CapsLock to Left click and moreI 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:<br />
<br />
1. Download and install AutoHotKey<br />
<blockquote class="tr_bq">
<a href="http://download.cnet.com/AutoHotkey/3000-2084_4-10279446.html">http://download.cnet.com/AutoHotkey/3000-2084_4-10279446.html</a></blockquote>
2. Run AutoHotkey<br />
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.<br />
<blockquote class="tr_bq">
Capslock::LButton<br />
+Capslock::Capslock</blockquote>
4. Make other desired changes or removals (see their documentation)<br />
5. Re-run AutoHotkey <br />
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:<br />
<blockquote class="tr_bq">
<a href="http://www.autohotkey.com/docs/FAQ.htm">AutoHotkey FAQ</a>
</blockquote>
You may also want to reference the following for more information.<br />
<blockquote class="tr_bq">
<a href="http://www.autohotkey.com/docs/misc/Remap.htm">MouseClick<br />Remapping Keys and Buttons</a>
<a href="http://www.autohotkey.com/docs/commands/MouseClick.htm"><br /></a></blockquote>
Good luck!Anonymoushttp://www.blogger.com/profile/17694150200064033101noreply@blogger.com0tag:blogger.com,1999:blog-9170434694647900866.post-54771789917795571032014-05-15T13:04:00.002-07:002014-05-15T13:06:35.893-07:00Edit a file on a Mac (hfs+) partition using a Ubuntu USB stick<ol>
<li>download and install the Lubuntu iso onto a USB stick (the dd command works for writing to USB).</li>
<li>Download the hfsplus debian package onto another USB stick.</li>
<li>Boot into lubuntu and install the hfsplus package (<span style="font-family: Courier New, Courier, monospace;">sudo dpkg -i <thepackage<package package="">.deb></package></span>)</li>
<li>mount your drive ( <span style="font-family: Courier New, Courier, monospace;">mount -t hfsplus -o force,rw /dev/sdXY /media/mntpoint </span><span style="font-family: inherit;">)</span></li>
</ol>
JTPhttp://www.blogger.com/profile/07535605477911297179noreply@blogger.com0tag:blogger.com,1999:blog-9170434694647900866.post-67681119713090432322014-04-22T08:53:00.001-07:002014-04-22T08:53:30.660-07:00Simple youtube audio player with VLCThere 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:
<br />
<pre><code>vlc --intf rc -Vdummy <playlist_or_youtube_URL></code></pre>
type 'help' to see your options.
If you want global control over the player, you can set global keyboard shortcuts in Tools.JTPhttp://www.blogger.com/profile/07535605477911297179noreply@blogger.com0tag:blogger.com,1999:blog-9170434694647900866.post-76930789635797783522013-09-02T20:32:00.001-07:002013-09-02T20:32:06.827-07:00Google two-step verification with an ipod touch 2gI 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:<br />
<br />
1. <b>Go to your account setting</b> (go to gmail, click your name or picture, click "account")<br />
2. <b>Click "Security"</b><br />
3. <b>Scroll to the "2-step verification" section</b><br />
4. Follow <b>"Manage your application specific passwords"</b> link<br />
5. If requested, re-enter your password<br />
6. Follow the directions in the box, "<b style="background-color: white; color: #333333; font-family: arial, helvetica, sans-serif; font-size: 13px; line-height: 13px;">Step 1 of 2: Generate new application-specific password"</b><br />
6b. (You will put in a name for your device, e.g. ipod touch 2g)<br />
7. Click <b>"Generate password"</b><br />
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...)<br />
9. That's it, good luck!!!Anonymoushttp://www.blogger.com/profile/17694150200064033101noreply@blogger.com0tag:blogger.com,1999:blog-9170434694647900866.post-33309376568351814342012-09-27T12:40:00.002-07:002012-09-27T12:41:23.278-07:00Update Dell BIOS from linuxNOTE: messing with your BIOS is obviously dangerous. Proceed at your OWN RISK!<br />
First, install libsmbios-bin<br />
<pre class="brush:bash">
sudo apt-get install libsmbios-bin
</pre>
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 <bios>.exe file from Dell.</bios>
These can be extracted either with unzip or wine, as shown from <a href="http://linux.dell.com/repo/firmware/bios-hdrs/system_bios_ven_0x1028_dev_0x0420_version_a09/extract.log">this log file</a>.<br />
After trying unzip, I tried this command, and it worked:
<pre class="brush:bash">
wine O780-A13.exe -writehdrfile -nopause
</pre>
Creating the file: O780-A13.hdr
Now, follow <a href="http://linux.dell.com/wiki/index.php/Tech/libsmbios_dellBiosUpdate">these directions</a> (<b>as su or root</b>):
<pre class="brush:bash">
modprobe dell_rbu
dellBiosUpdate -u -f ./O780-A13.hdr
</pre>
Now just reboot, and wuala, an updated BIOS.JTPhttp://www.blogger.com/profile/07535605477911297179noreply@blogger.com0tag:blogger.com,1999:blog-9170434694647900866.post-52830791507211940052012-08-16T23:39:00.004-07:002012-08-17T22:48:11.249-07:00How to run a ruby script<h2>
Windows users:</h2>
<div>
1. Install ruby</div>
<div>
<br /></div>
<div>
goto <a href="http://www.ruby-lang.org/en/downloads/">http://www.ruby-lang.org/en/downloads/</a> , then to the Ruby on Windows section and download and install the One-Click Installer.</div>
<div>
<br /></div>
<div>
2. Some scripts can be run simply by clicking on them (this is rare, though).</div>
<div>
<br /></div>
<div>
3. Running scripts from the command prompt</div>
<div>
<br /></div>
<div>
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 <a href="http://www.cs.princeton.edu/courses/archive/spr05/cos126/cmd-prompt.html">this page</a> on the command prompt in 15 minutes for an overview.</div>
When you have navigated to the directory with the ruby script in it (use the commands <b>cd</b> and <b>dir</b> to get there), you are ready to run your script. Just type:<br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span>
<span style="font-family: 'Courier New', Courier, monospace;"><b>ruby myscript.rb</b></span><br />
<br />
Depending on how windows and ruby has been configured, you may also be able to just type<br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span>
<span style="font-family: 'Courier New', Courier, monospace;"><b>myscript.rb</b></span><br />
<br />
Many scripts expect an argument (like a filename) after the script name. If it does, give it the appropriate argument like this:<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>myscript.rb filename</b></span><br />
<h2>
Ubuntu/Debian users:</h2>
To get it, open a terminal and type:<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>sudo apt-get install ruby irb ri</b></span><br />
<br />
Make sure the script is executable:<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>chmod +x myscript.rb</b></span><br />
<br />
To run the script:<br />
<br />
<b><span style="font-family: 'Courier New', Courier, monospace;">./myscript.rb</span></b>JTPhttp://www.blogger.com/profile/07535605477911297179noreply@blogger.com0tag:blogger.com,1999:blog-9170434694647900866.post-33598058250184404192012-08-15T09:54:00.000-07:002012-08-15T09:54:17.999-07:00How to boot off USB stick ASUS 1201nThis can be a little tricky. Basically, you need to change <b>2 settings</b> in the BIOS before it will boot off USB. You need to change <b>the boot order</b> and t<b>he hard drive order</b>. [I need to verify the actual names, but I am certain you need to change 2 settings before it will work]JTPhttp://www.blogger.com/profile/07535605477911297179noreply@blogger.com0tag:blogger.com,1999:blog-9170434694647900866.post-21630883593194110582012-06-12T10:38:00.000-07:002012-06-12T10:38:06.149-07:00Why I'm back to Ubuntu from Linux MintMany 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. <br />
<br />
Why did I switch back to Ubuntu?<br />
<br />
<ul>
<li><b>Slower updates and broken repos</b> - Ubuntu updates are slow, but Linux Mint's are even worse.</li>
<li><b>No upgrade option</b> - 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.</li>
<li><b>Better support for Ubuntu</b> - 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.</li>
<li><b>The best desktop manager is neither unity or gnome-3</b> - 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.</li>
</ul>JTPhttp://www.blogger.com/profile/07535605477911297179noreply@blogger.com0tag:blogger.com,1999:blog-9170434694647900866.post-20413603465043350362012-04-30T22:10:00.002-07:002012-04-30T22:11:52.382-07:00Indexing Tips for the 1940 CensusThese 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 <a href="https://www.familysearch.org/">(link)</a> 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.<br />
<br />
<a href="https://www.dropbox.com/s/a5n8pmob97dvjyk/IndexingTipsFor1940Census.pdf">https://www.dropbox.com/s/a5n8pmob97dvjyk/IndexingTipsFor1940Census.pdf</a>JTPhttp://www.blogger.com/profile/07535605477911297179noreply@blogger.com0tag:blogger.com,1999:blog-9170434694647900866.post-2012534504499609592012-02-06T07:17:00.000-08:002012-03-08T23:18:08.772-08:00R and Rserve on Windows<div>
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 <u>because the R serve binary is 32 bit</u>!</div>
<ol>
<li>Install the windows R binary package (accepting the defaults)</li>
<li>Put the R bin directory on your path (right click computer <span class="Apple-style-span" style="background-color: #f9f9f9; font-family: sans-serif; font-size: 22px; line-height: 19px;">→</span> Advanced Properties <span class="Apple-style-span" style="background-color: #f9f9f9; font-family: sans-serif; font-size: 22px; line-height: 19px;">→</span> Environment Variables). </li>
<ul>
<li>For a 32-bit Windows install you should use a path like this: C:\Program Files\R\R-2.14.1\bin</li>
<li>For a 64-bit Windows install you need to link to the <b>i386 folder</b>: C:\Program Files\R\R-2.14.1\bin\i386</li>
</ul>
<li>Fire up R from the cmd line (<u>make sure that it is the 32 bit R</u>, even if you are on a 64-bit computer) and execute the command: install.packages("Rserve") -- note to where it installs Rserve.</li>
<li>Copy the binaries Rserve.exe and Rserve_d.exe to your R bin directory referenced aboved.</li>
<li>Fire up a new cmd line and run the command: "R CMD Rserve' and configure the firewall popup to allow rserve to work.</li>
<li>You know if everything is working if you can execute this code inside of <b>irb</b> (depends on rserve/simpler [gem install rserve-simpler]):</li>
<ul>
<li>require 'rserve/simpler/R'</li>
</ul>
<li>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.</li>
</ol>
<ol><ul>
</ul>
</ol>
<div>
<br /></div>JTPhttp://www.blogger.com/profile/07535605477911297179noreply@blogger.com0tag:blogger.com,1999:blog-9170434694647900866.post-63400377035311528712011-08-08T10:18:00.000-07:002011-08-08T12:06:14.959-07:00*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?<br />
<br />
The answer: <a href="http://filmsbykris.com/wordpress/?p=968">use youtube-dl to provide the correct download link, then stream to mplayer</a> and null the video.<br />
<br />
Steps:<br />
<ol><li>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).</li>
<li>make sure mplayer and python are installed: (sudo apt-get install mplayer python)</li>
<li>Use this command:</li>
</ol><b>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")</b><br />
<b><br />
</b><br />
Of course, you will change the video link to be the one you like. Here is some explanation of what is going on:<br />
<ul><li>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.</li>
<li>The <b>-g</b> means get the url, and <b>-f</b> changes which file format you are getting the link to (<a href="http://en.wikipedia.org/wiki/YouTube">look up youtube codes</a>... current options are <b>5</b>, <b>34</b>, <b>35</b>, <b>18</b>, <b>22</b>, <b>37</b>, <b>38</b>, <b>43</b>, <b>44</b>, <b>45</b>, <b>17</b>). <b>34</b> is the lowest resolution flv format at 128 kbits/s sound (and I think is standard "360"). <b>18</b> would give you 96 kbits/s sound. </li>
<li><b>-vo null </b>means no video output. Use <b>-fs </b>instead if you want full screen, or nothing for that option if you want regular.</li>
</ul>There you have it. Robust, legal, streaming audio player for youtube.<br />
<br />
This also seems to work on <u>short</u> playlists, but not always:<br />
<br />
<b>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")</b><br />
<b><br />
</b><br />
Navigate through the tracks with ">" and "<".<br />
<b><br />
</b><br />
<br />
JTPhttp://www.blogger.com/profile/07535605477911297179noreply@blogger.com0tag:blogger.com,1999:blog-9170434694647900866.post-45331012298206546342011-04-11T08:22:00.000-07:002011-04-11T08:37:17.633-07:00rvm with Ubuntu 10.04 and 10.10If you plan on doing a lot of development in ruby, then <a href="https://rvm.beginrescueend.com/">rvm</a> (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.<br />
<br />
This is a condensed version of <a href="http://www.christopherirish.com/2010/08/25/how-to-install-rvm-on-ubuntu-10-04/">Chistopher Irish's excellent write-up</a><br />
<br />
(leading <b>$</b> is the bash prompt)<br />
<pre><code>
$ sudo apt-get install curl git-core ruby
$ bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
</code></pre><br />
If you haven't already replaced your .bashrc, you probably have a line in there like this:<br />
<pre><code>[ -z "$PS1" ] && return
</code></pre><br />
Replace that line with:<br />
<pre><code>
if [[ -n "$PS1" ]]; then
</code></pre><br />
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).<br />
<pre><code>
if [[ -s $HOME/.rvm/scripts/rvm ]] ; then source $HOME/.rvm/scripts/rvm ; fi
fi
</code></pre><br />
There are going to be prerequisites to installing most ruby's. Use the command <b>rvm notes</b> to discover those dependencies for your system.<br />
<br />
Okay, we'll grab some prerequisites for compiling 1.9.2:<br />
<pre><code>
$ 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
</code></pre><br />
Now, we can list the ruby versions we can install, install 1.9.2, and set it as default.<br />
<br />
<pre><code>
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
</code></pre>JTPhttp://www.blogger.com/profile/07535605477911297179noreply@blogger.com1tag:blogger.com,1999:blog-9170434694647900866.post-60045516330994205762011-03-15T15:32:00.000-07:002012-08-01T14:09:51.138-07:00bacon and autotestTook 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.<br />
<br />
<br />
<pre class="brush: bash">
touch spec/.bacon
</pre><br />
Inside <b>.autotest</b>:<br />
<pre class="brush: ruby">
require 'rubygems'
require 'bacon'
require 'autotest/bacon'
# see inside <bacon gem>/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
</pre>JTPhttp://www.blogger.com/profile/07535605477911297179noreply@blogger.com0tag:blogger.com,1999:blog-9170434694647900866.post-27953079389057837032011-03-07T10:05:00.000-08:002011-03-07T10:05:49.143-08:00image 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?<br />
<br />
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.<br />
<br />
There are two other ways to add a spatial dimension to reading text:<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.JTPhttp://www.blogger.com/profile/07535605477911297179noreply@blogger.com0tag:blogger.com,1999:blog-9170434694647900866.post-4620010766387453752011-02-21T23:08:00.000-08:002012-08-19T10:20:14.275-07:00ruby list comprehensionI 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...<br />
<br />
[disclaimer: this is just scratch space for ideas at the moment]<br />
<br />
(I wonder how lazy enumerators will change the ruby approach?)<br />
<br />
<a href="http://www.secnetix.de/olli/Python/list_comprehensions.hawk">A nice write up on list comprehensions in python</a> 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:<br />
<br />
<pre><code>
>>> [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]
</code></pre>
<br />
It's not bad, but it's easy to get lost in there (my ruby eyes are not highly trained in python, of course).<br />
<br />
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.<br />
<br />
[ add the equivalent python here ]<br />
<br />
<pre><code>
(2..10).select(&:even?).map {|v| v**2 }
(2..10).map {|v| v**2 if v.even? }.compact
</code></pre>
<br />
Implementing this aspect of list comprehensions in ruby is less than trivial:<br />
<br />
<pre><code>
module Enumerable
def lc(&block)
block.nil? ? self : self.map(&block).compact
end
end
</code></pre>
<br />
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.<br />
<br />
This gets the job done, but the right-most block is executed multiple times to make it work:<br />
<pre><code>
(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)) }
</code></pre>
JTPhttp://www.blogger.com/profile/07535605477911297179noreply@blogger.com0tag:blogger.com,1999:blog-9170434694647900866.post-22966700815106544962011-02-09T11:32:00.000-08:002011-02-09T11:32:06.295-08:00Using Dropbox and gitDropbox 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:<br />
<br />
<h2>Solo Repo (use a Normal git repo)</h2><br />
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.<br />
<br />
<pre><code>
cd ~/Dropbox/myproject
git init
git add .
git commit -m 'first commit'
# after a while
git status
git commit -a -m 'another commit'
</code></pre><br />
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.<br />
<br />
<h2>Shared Repo (use a Bare git repo)</h2><br />
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).<br />
<br />
<pre><code>
# 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
</code></pre><br />
If you get trouble when pushing or pulling to your remote, add these lines to your ~/.gitconfig file:<br />
<br />
<pre><code>
[push]
default = matching
[branch "master"]
remote = origin
merge = refs/heads/master
</code></pre>JTPhttp://www.blogger.com/profile/07535605477911297179noreply@blogger.com0tag:blogger.com,1999:blog-9170434694647900866.post-43116192972684550822010-12-17T14:52:00.000-08:002010-12-17T14:52:00.626-08:00Shell escaped file names in rubyWhen 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:<br />
<br />
<pre><code>
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
</code></pre><br />
The answer is to use the multiple arguments invocation, which will properly escape your filename to be fully shell compatible:<br />
<pre><code>
system "mv", file1, "bettername.txt" # works on file1 or file2
</code></pre>JTPhttp://www.blogger.com/profile/07535605477911297179noreply@blogger.com2tag:blogger.com,1999:blog-9170434694647900866.post-23465674760655658142010-12-09T21:40:00.000-08:002010-12-09T21:45:54.640-08:00Playing with (compiling) the redesigned NArrayMasahiro Tanaka has been redesigning NArray. Word is that it may be pulled into mainline ruby.<br />
<br />
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):<br />
<br />
<pre><code>
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]);
</code></pre><br />
now, you should be able to "ruby extconf.rb", "make", and then <i>require 'narray'</i> or <i>require './narray.so'</i>JTPhttp://www.blogger.com/profile/07535605477911297179noreply@blogger.com0tag:blogger.com,1999:blog-9170434694647900866.post-18145984962530849462010-09-28T09:22:00.000-07:002012-08-01T13:56:24.319-07:00Compile ruby 1.9.2 on Ubuntuassumes you have build-essential package installed<br />
<pre class="brush:bash">
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
</pre>
<br />
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.<br />
<br />
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 <br />
<pre><code>
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
</code></pre>
<br />
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. <a href="http://sudoit.blogspot.com/2010/05/debianubuntu-gem-environment-of-your.html">how to set up a local gem environment</a><br />
<pre><code>
mv ~/.gem/ruby/{,not_using_}1.9.1
mkdir ~/.gem/ruby/1.9.2
</code></pre>JTPhttp://www.blogger.com/profile/07535605477911297179noreply@blogger.com2tag:blogger.com,1999:blog-9170434694647900866.post-19113253070526287062010-09-21T13:17:00.000-07:002010-09-21T13:17:12.302-07:00Installing graphviz on Ubuntu Lucid Lynx 10.04If you want <b>sfdp</b> (a great layout for large graphs), then you need the .debs from the graphviz site (not through the ubuntu repos).<br />
<br />
Download the develpment snapshots <a href="http://www.graphviz.org/Download_linux_ubuntu.php">here</a><br />
note, if you don't use the language specific bindings listed, you don't need to download those.<br />
<pre><code>
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
</code></pre><br />
Now, you can run <b>sfdp</b>!JTPhttp://www.blogger.com/profile/07535605477911297179noreply@blogger.com0tag:blogger.com,1999:blog-9170434694647900866.post-4405180040510264062010-09-14T18:57:00.001-07:002010-09-14T18:57:59.969-07:00Biostatistics vs Lab Research<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/PbODigCZqL8&color1=0xb1b1b1&color2=0xd0d0d0&hl=en_US&feature=player_embedded&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed src="http://www.youtube.com/v/PbODigCZqL8&color1=0xb1b1b1&color2=0xd0d0d0&hl=en_US&feature=player_embedded&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="640" height="385"></embed></object>EGPhttp://www.blogger.com/profile/10276929334706945468noreply@blogger.com0tag:blogger.com,1999:blog-9170434694647900866.post-69912620986298252652010-09-05T22:42:00.000-07:002010-09-05T22:57:42.170-07:00for anything complicated, ruby eats bash for breakfast<a href="http://www.sklav.com/node/4">http://www.sklav.com/node/4</a> shows a bash solution to the issue debated <a href="http://www.linuxtutorialblog.com/post/solution-converting-flac-to-mp3">here</a>. Regardless of how good a bash script is, it inevitably is not very DRY, I think because it is hard to be DRY in bash scripting.<br />
<br />
Here is a ruby solution. Of course, all I did was factor, which is easy in ruby:<br />
<br />
<pre><code>
#!/usr/bin/env ruby
lame_opts = "--preset standard -q0"
if ARGV.size == 0
puts "usage: #{File.basename(__FILE__)} <file>.flac ..."
puts "output: <file>.mp3"
puts ""
puts "uses lame opts: #{lame_opts}"
puts "retains tag info"
exit
end
tag_convert = {
:tt => "TITLE",
:tl => "ALBUM",
:ta => "ARTIST",
:tn => "TRACKNUMBER",
:tg => "GENRE",
:ty => "DATE",
}
ARGV.each do |file|
tag_opts = tag_convert.map do |key,val|
# comes out as TITLE=<the title>
data = `metaflac --show-tag=#{val} #{file}`.split("=",2).last
"--#{key} #{data}"
end
mp3name = file.chomp(File.extname(file)) + ".mp3"
`flac -dc #{file} | lame #{lame_opts} #{tag_opts.join(" ")} --add-id3v2 - #{mp3name}`
end
</code></pre>Fairly easy to follow, especially since we don't repeat ourselves. Most of the code is in creating a useful help message.<br />
<br />
For Perl hackers, here is the entire script on a few lines of less than 105 chars per line:<br />
<pre><code>
tag_convert = {:tt=>"TITLE",:tl=>"ALBUM",:ta=>"ARTIST",:tn=>"TRACKNUMBER",:tg=>"GENRE",:ty=>"DATE"}
ARGV.each do |f|
tgs = tag_convert.map {|k,v| "--#{k} "+`metaflac --show-tag=#{v} #{f}`.split("=",2).last}.join(" ")
`flac -dc #{f} | lame --preset standard -q0 #{tgs} --add-id3v2 - #{f.sub(/.flac$/i,".mp3")}`
end
</code></pre>There are still ways to compress this further, but it is very concise and surprisingly easy to follow (if you know ruby).JTPhttp://www.blogger.com/profile/07535605477911297179noreply@blogger.com0tag:blogger.com,1999:blog-9170434694647900866.post-13451182821219551552010-09-01T15:46:00.000-07:002010-09-01T15:46:12.637-07:00For sets of integers, lookup speed goes: Array > Hash > SetYou have some set of integers and you need to query it repeatedly to determine if a member is in it or not. <br />
<pre><code>
require 'benchmark'
require 'set'
ar = (0...1000).to_a
ar_index = []
hash_index = {}
ar.each do |v|
ar_index[v] = true
hash_index[v] = true
end
set_index = Set.new(ar)
access = (0...1000).to_a
TIMES = 10000
Benchmark.bmbm do |r|
r.report("array index") { TIMES.times { access.each {|v| ar_index[v] } } }
r.report("hash index") { TIMES.times { access.each {|v| hash_index[v] } } }
r.report("hash include") { TIMES.times { access.each {|v| hash_index.include?(v) } } }
r.report("set include") { TIMES.times { access.each {|v| set_index.include?(v) } } }
end
</code></pre>The output (ruby 1.9.1p378 (2010-01-10 revision 26273) [x86_64-linux]):<br />
<pre><code>
user system total real
array index 0.730000 0.000000 0.730000 ( 0.745341)
hash index 0.990000 0.000000 0.990000 ( 1.003517)
hash include 1.310000 0.000000 1.310000 ( 1.332846)
set include 1.970000 0.000000 1.970000 ( 2.024808)
</code></pre>JTPhttp://www.blogger.com/profile/07535605477911297179noreply@blogger.com0tag:blogger.com,1999:blog-9170434694647900866.post-27531731354261691192010-09-01T13:17:00.000-07:002010-09-01T13:18:06.223-07:00It's faster to numerically round than to sprintf in ruby<pre><code>require 'benchmark'
class Float
def round_to(x)
(self * 10**x).round.to_f / 10**x
end
def ceil_to(x)
(self * 10**x).ceil.to_f / 10**x
end
def floor_to(x)
(self * 10**x).floor.to_f / 10**x
end
def round_to_sprintf_f(x)
("%.#{x}f" % x).to_f
end
def round_to_sprintf_sprintf(x)
sprintf("%.#{x}f", x)
end
def round_to_sprintf_modulus(x)
"%.#{x}f" % x
end
end
num = 34.2342134
place = 3
TIMES = 1000000
Benchmark.bmbm do |r|
r.report("numeric round_to (float)") { TIMES.times { num.round_to(place) } }
r.report("numeric round_to (to string)") { TIMES.times { num.round_to(place).to_s } }
r.report("sprintf (float)") { TIMES.times { num.round_to_sprintf_f(place) } }
r.report("sprintf (string)") { TIMES.times { num.round_to_sprintf_sprintf(place) } }
r.report("sprintf modulus (string)") { TIMES.times { num.round_to_sprintf_modulus(place) } }
end</code></pre>The output:<br />
<pre><code>
% ruby -v
ruby 1.9.1p378 (2010-01-10 revision 26273) [x86_64-linux]
...
user system total real
numeric round_to (float) 0.820000 0.000000 0.820000 ( 0.819920)
numeric round_to (to string) 1.990000 0.000000 1.990000 ( 1.989912)
sprintf (float) 3.620000 0.000000 3.620000 ( 3.614758)
sprintf (string) 2.650000 0.000000 2.650000 ( 2.654812)
sprintf modulus (string) 3.190000 0.000000 3.190000 ( 3.191807)</code></pre><br />
The conclusion: Regardless of whether you are going to a string or numeric after rounding, it is faster to round numerically than with sprintf. Also, using the sprintf function is faster than '%'. Usually speed doesn't matter, but when it does...JTPhttp://www.blogger.com/profile/07535605477911297179noreply@blogger.com0tag:blogger.com,1999:blog-9170434694647900866.post-55725871088793562282010-08-19T11:05:00.000-07:002010-08-19T11:05:07.875-07:00apply & sweep : Column-wise & Row-wise operations in RHow do you do operations on rows and columns in R? <b>apply</b> and <b>sweep</b> are the main tools. Here is an example of "autoscaling" (mean center and divide by standard deviation) <i>on each column</i>:<br />
<br />
[I verified that this is correct on oocalc]<br />
<pre><code>
# 1 -> across the rows
# 2 -> across the columns
m <- matrix(data=c(1,2,3,4,4.5,6,7,8,9,10,11,13), nrow=4, ncol=3)
m
# [,1] [,2] [,3]
# [1,] 1 4.5 9
# [2,] 2 6.0 10
# [3,] 3 7.0 11
# [4,] 4 8.0 13
colmeans <- apply(mymatrix, 2, mean) # the column-wise means
# mc = the column-wise mean centered data
mc <- sweep(m, 2, colmeans, "-") # subtract is the default
col_stdev <- apply(m, 2, sd) # column-wise standard deviations
mcstd <- sweep(mc, 2, col_stdev, "/") # divide by standard deviations
mcstd
# [,1] [,2] [,3]
# [1,] -1.1618950 -1.2558275 -1.024695
# [2,] -0.3872983 -0.2511655 -0.439155
# [3,] 0.3872983 0.4186092 0.146385
# [4,] 1.1618950 1.0883839 1.317465
</code></pre>JTPhttp://www.blogger.com/profile/07535605477911297179noreply@blogger.com0