Thursday, May 31, 2012

Focuswriter, ubuntu 12.04, typewriter sound effects

In short, in Ubuntu 12.04, if you get "unable to load typewriter sounds" in Focuswriter, open a terminal and enter "sudo apt-get install libsdl-mixer1.2-dev" (if you try "libsdl-mixer1.2" you will get package not found).

Focuswriter (sudo apt-get install focuswriter) is a full-screen tool in Ubuntu for distraction-free writing.
http://flattr.com/thing/417372/FocusWriter-1-3-0-Released-Distraction-free-writing-on-Ubuntu
You can theme it like so, though I prefer the console-like green on pure black, monospace font.
What I really like is the typewriter sound effects (it helps me concentrate & feel productive instead of despairing over my papers). I got the typewriter sounds working in 10.04 through some magic I've forgotten. Now I have a clean install of 12.04 on my netbook, but when I went into Settings > Preferences > check Typewriter sound effects > Ok, it said "unable to load typewriter sounds".

http://gottcode.wordpress.com/2011/06/27/even-more-bugs-fixed-in-focuswriter/#comment-276
@Lito: You need to install the package libsdl1.2-mixer to get typewriter sound effects because they are now fully optional.

Okay... so I try "sudo apt-get install libsdl1.2-mixer" but get package not found. https://bugs.launchpad.net/ubuntu/+source/focuswriter/+bug/897055
According to this bug report, it should just magically be fixed. And according to ubuntu.com, this package is in Precise.
Turns out the package is actually called "libsdl-mixer1.2-dev" for ubuntu. So "sudo apt-get install libsdl-mixer1.2-dev" and yay typewriter sound effects will load.


If you get a package not found error, run "sudo apt-get update" to make sure you have the latest packages. If you still don't see it, Ubuntu Sofware Center > Edit > Software Sources and make sure all the sources under "Ubuntu Software" and "Other Software" are checked.

SMS gateway to Cosm using Tropo

Here I present a terrible way to use Tropo to create an SMS gateway to Cosm feeds while waiting for the official Cosm SMS gateway to exit beta status.

This stores your Cosm API key in plain text (I don't know how to avoid this) so it is a terrible solution, but a very easy one.

Background

I read http://cosm.com/docs/quickstart/curl.html
curl --request POST \
--data '{"title":"My feed", "version":"1.0.0"}' \
--header "X-ApiKey: YOUR_API_KEY_HERE" \
--verbose \
and
http://api.cosm.com/v2/feedshttps://www.tropo.com/docs/scripting/capturing_incoming_text.htm
currentCall.initialText

How to translate that into python? See http://stackoverflow.com/questions/111945/is-there-any-way-to-do-http-put-in-python.

The app

Create a new Tropos application and use a hosted file.
** If you don't know how to setup Tropo to do the following, see Appendix 1.

File Name: smstocosm.py
File Text:


import urllib2

val = currentCall.initialText
say(val)
test = ('{ "version":"1.0.0", "datastreams":[{"id":"potvalue", "current_value":"%s"} ]}' % val)
contenttype = "X-ApiKey"

#Edit to your Cosm api key and feedurl,
apikey = "COSM-API-KEY"
feedurl = "http://api.cosm.com/v2/feeds/YOUR-FEED-NUMBER"

opener = urllib2.build_opener(urllib2.HTTPHandler)
request = urllib2.Request(feedurl, data=test)
request.add_header(contenttype, apikey)
#request.add_header('Content-Type', 'your/contenttype')
request.get_method = lambda: 'PUT'
url = opener.open(request)


This file can later be edited at https://www.tropo.com/hosting/.
** If you don't know what your Cosm Api Key or feed URL is, see appendix 3.

Now add a new phone number for your app.
** see appendix 2 if you're unsure how.

Text that number with a value (e.g. "45"). Wait a few seconds and Tropo will text you back that same value (acts as a confirmation message that Tropo got it). Then wait another 30 seconds or so and refresh your Cosm feed URL. Voila! Your new value shows up there.

Todo next for me, connect a pot to an Arduino Uno + GPRS shield from Sparkfun, have the pot values sent to Cosm via SMS.

===

Appendix One.

https://www.tropo.com/docs/scripting/creating_first_application.htm
1) Start by clicking on the "Your Applications" Quick Link.
2) Click on the link to Create New Application near the top right of the new page.
Click on the Tropo Scripting icon.
4) For Tropo Scripting Application Name, enter in a name like Tropo Test.
5) Click on the "Use a Hosted File" link and choose "Create a new hosted file for this application".
The File Name can be whatever you'd like, it just needs to end with the language extension you intend to use (.rb for Ruby, .php for PHP, etc). For the File Text, see above.

Appendix Two.


8a) To the right of the Skype phone number is an "Add a new phone number" link - go ahead and click on it.
8b) Select your preferred area code and then click the + sign next to the area code to add it to your application. Click the X at the top right to close the window and you'll be returned to your application settings page.
9) That's it!

Appendix Three.

Note: If you don't have an API key for Cosm yet, follow http://community.cosm.com/quickstart_no_code (actually that is for the old pachube interface, I updated it for the new Cosm interface below):


Login to Cosm and click on "Keys" in the top right corner (or go to https://cosm.com/users/USERNAME/keys, where USERNAME should be replaced by whatever username you chose when you signed up).

Click the blue "+key" button (https://cosm.com/users/USERNAME/keys/new)

Give it some label, select "use any public feed", and select permissions options 'read' and 'update' (because you will want to use this key both to retrieve and to update Cosm datastreams). Ignore "advanced restrictions".
Click "create".

After clicking "Create" note down the feed ID that you have just created (e.g. http://www.pachube.com/feeds/15556 would be feed ID 15556).

Thursday, May 17, 2012

project ideas

todo:
nyanscooter: electric scooter with nyan graffiti attachment. Either water rainbow trails, or chalk rainbow trails, or LED trails at night.

nyan "that was easy" button

Thursday, May 10, 2012

Inkscape 42''x36'' Scientific Poster w/ SVG source (Caffeine's Impact on Sleep)

This is a followup post to Caffeine's Impact on Sleep, Inkscape A0 Scientific Poster draft

Finished my 42''x36'' poster today (turns out 2.671, my Measurement and Instrumentation class, didn't want A0). I saw some awesome horizontal and vertical designs Tuesday, and now I have this super-cluttered and not very aesthetically pleasing poster *sigh* Oh well. I liked my draft version better for its simplicity and think I have too much text on this final version.
Larger size PNG image available on dropbox,
!! PDF version available (large file, ~10Mb), as well as SVG source!!

Again, thanks to Alexander Erlich for the Inkscape template
Also, thanks to netalloy for the coffee cup vector
And thanks to OnlyPositive for the picture of the sleepy cat.


Google Docs
Spreadsheet here. I calculated averages and stddevs with =AVERAGE( ) and =STDEV( ) respectively, and turned formatted time (e.g. 07:30:00) into decimal hours (e.g. 7.50) (also applied Format > Number > Two decimals) using the formula =INT(F4)*24+HOUR(F4)+MINUTE(F4)/60

Matlab
Here is the matlab code I used. It's very messy and I don't actually understand what it means. In fact, I had to do post-processing of the Matlab > Export Setup > Rendering, Resolution = 300 > Export > figureN.png in the GIMP prior to dropping it in Inkscape to get the images I wanted.

figure 
caffeine4=[0 0 0 0 0 0 0 0];
sleep4=[6.95 10.87 9.75 7.52 10.95 9.43 8.75 10.23];
day=[25 26 27 28 29 30 31 32];
[AX,H1,H2] = plotyy(day,sleep4,day,caffeine4,'plot');

title('Phase 4: Daily Hours Slept and Caffeine Intake');
xlabel('Date (in April)');
%xlim([26 13]);
set(gca,'XTick',25:1:32);
%set(gca,'box','off');

set(get(AX(1),'Ylabel'),'String','Amount Slept Daily (hrs)'); 
set(get(AX(2),'Ylabel'),'String','Daily Caffeine Intake (mg)') ;
axis(AX(1),[25 32 0 11]);
axis(AX(2),[25 32 0 700]);
set(AX(1),'YLim',[0 11], 'YTick',0:1:11, 'box','off');
set(AX(2),'YLim',[0 700],'YTick',0:100:700,'box','off', 'box','off');

set(H1,'LineWidth',3,...
                'MarkerSize',7,...
    'LineStyle','-',...
    'Marker', 'o',...
    'MarkerEdgeColor', 'none',...
    'MarkerFaceColor', 'b');
set(H2,'LineWidth',3,...
                'MarkerSize',7,...
    'LineStyle','-',...
    'Marker', 'o',...
    'MarkerEdgeColor', 'none',...
    'MarkerFaceColor', 'g');

Above code resulted in this graph:
This data was actually 25 April to 2 May, but instead of learning about timeseries in MATLAB, I just cheated and stuck "April / May" in the xlabel and used 31 and 32 to not break my code. I planned to post-process in gimp to turn "31 32" into "1 2" but forgot to do so.

For phase 3, I couldn't figure how to get rid of the 20.5 and 21.5 tick marks when I expanded to graphs to reasonable size, so I did post-processing in GIMP. Here are the two images I smushed together into the third:
 +=


Misc. other tricks too lazy to document fully:
Using "shift-J" in Vim to turn newlines (ctrl-click-drag to get a column of values from google doc separated by newlines) into spaces, which Matlab uses to delimit vector data.

Making Instagram-like effect with kitten in top-left corner via kitten > right-click Add layer mask > (1) Gradient tool white-to-back, radial, click-drag from center to slightly past edges of images. This transparency-ed a large part of the cat face so (2) Ellipse select most of cat face, Gradient tool white-to-light-gray, radial, click-drag from center to edge of ellipse.

Inkscape, Filter effect > Make arrowheads match color to the lines. (If you decide to change the color of the arrowheads).

Saturday, May 5, 2012

Caffeine's Impact on Sleep, Inkscape A0 Scientific Poster draft

This post is continued at Inkscape 42''x36'' Scientific Poster w/ SVG source (Caffeine's Impact on Sleep) 
click on this to see it full-size. It is an A0 poster template.  Here's my svg source.

Finished my draft poster for 2.671 Measurement and Instrumentation (required communications course for MechE undergrads). Basically, we are given free reign to design and collect data from our own experiment, and we have to present in a Poster Session at the end of the semester (I present next Thursday).

Well, I'm abysmally behind in this class but catching up, and I made this fluffy poster Thursday night - Friday morning. (Fluffy, as in not much content and no math). What follows is an overview of the tools I used, and at the end my poster / my Inkscape svg source file.

My Inkscape file is based on the wonderful Inkscape template I found online. I found it aesthetically pleasing compared to the default 2.671 template. (If you search for "2.671" on Google you'll find some posters other classmates made using the default template).


Actually here's Eli's poster, which shows the default powerpoint template scheme if not the exact template:
elimarcdavis.blogspot.com/p/go-forth-and-measure.html