2013

Archive for 2013

Ultrasonic 3D scanner fail

Weeks ago I tried to make a ultrasonic radar like, but things didn't work out very well. I will post everything here soon.

Break DNA in pieces using Matlab

Ok, the idea here is to try to unite the bits later.

% Copyright 2014 Érico Porto

% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at

%     http://www.apache.org/licenses/LICENSE-2.0

% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.

npont = 10000;
sizeofpiece = 300;
dnastr = textread('acetobacterpasteurianus.txt', '%s', 'delimiter', '\n','bufsize', 4000005);
rdnastr = cat(2,dnastr{:}) ;
tamanhoRd = length(rdnastr);
stringsd = randi(tamanhoRd,npont,1);

rstringsd=cell(npont,1);
rstringsd(:) = {''};

for i=1:npont
    maxed = min(stringsd(i)+sizeofpiece,tamanhoRd);
    rstringsd{i} = rdnastr(stringsd(i):maxed);
end

disp('Monte Carlo successfully applied to the DNA');
disp(sprintf('%d strings of %d chars created',npont,sizeofpiece));

QRCodes are the easy way to transfer websites to phone


At least if you are not in your computer.

If I want to pass a web site from computer to WhatsApp or other text to my phone world, I use this website to generate a Qrcode for it: http://qrcode.kaywa.com/

If the website is to big use a URL shortener to make the Qrcode more readable through your cellphone camera.

Update:

Just found out today that there is a way to make it better...

https://chart.googleapis.com/chart?chs=400x400&cht=qr&source=qrcode&chl=https://www.ericonotes.blogspot.com

modify the end of the url on top, and you can exchange it for any website.

QR code for Ericonotes on Blogger  

DIY Spectrometer



Some time ago I had some time, a spare webcam, Matlab and some Legos lying around, so I began building a Spectrometer from it. Now, to the hardware, you just need a dark box, with no light infusing in it, and a piece of dvd to use as diffraction grid. This website will help to answer most questions: http://publiclaboratory.org/tool/spectrometer

At the time, their software didn't ran on my computer so I started prototyping my own in matlab. The code is below:

% Copyright 2014 Érico Porto

% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at

%     http://www.apache.org/licenses/LICENSE-2.0

% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.

vid = videoinput('winvideo', 1, 'YUY2_640x480');
preview(vid);
pause(4);
color_spectrum = ycbcr2rgb(getsnapshot(vid));

%correct the orientation
binImg = im2bw(color_spectrum,0.24);
I = bwlabel(binImg);
a= regionprops(I,'MajorAxisLength','Area','Orientation');
[areaMaxArea, indexMaxArea]= max([a(:).Area]);
angle = a(indexMaxArea).Orientation;
color_spectrum = imrotate(color_spectrum,-angle,'bilinear','crop');
%now I want to get the main rectangle
binImg = im2bw(color_spectrum,0.08);
I = bwlabel(binImg);
a= regionprops(I,'BoundingBox','Area');
[areaMaxArea, iMA]= max([a(:).Area]);
subImage = imcrop(color_spectrum,round(a(iMA).BoundingBox));

%here I'm guessing the light wavelength!
%I think I need to use 380nm and 750nm as my bounding
XAxis=zeros(size(subImage,2),1);
XAxis(1)=380.0;
XAxis(length(XAxis))=750.0;

%find blue - 472nm
[intensity, blueI] = max(mean(subImage(:,:,3)));
XAxis(blueI)=472.0;

%find green - 532nm
[intensity, greenI] = max(mean(subImage(:,:,2)));
XAxis(greenI)=532.0;

%find red - 685nm
[intensity, redI] = max(mean(subImage(:,:,1)));
XAxis(redI)=685.0;

%Now I will run and fill the zeros...
beginI=1; endI=blueI; 
for i = (beginI+1):(endI-1)
    XAxis(i)= XAxis(beginI) + ((XAxis(endI)-XAxis(beginI))/(endI-beginI)) * (i-beginI);
end
beginI=blueI; endI=greenI; 
for i = (beginI+1):(endI-1)
    XAxis(i)= XAxis(beginI) + ((XAxis(endI)-XAxis(beginI))/(endI-beginI)) * (i-beginI);
end
beginI=greenI; endI=redI;
for i = (beginI+1):(endI-1)
    XAxis(i)= XAxis(beginI) + ((XAxis(endI)-XAxis(beginI))/(endI-beginI)) * (i-beginI);
end
beginI=redI; endI=length(XAxis); 
for i = (beginI+1):(endI-1)
    XAxis(i)= XAxis(beginI) + ((XAxis(endI)-XAxis(beginI))/(endI-beginI)) * (i-beginI);
end
%this ends, the wavelength vector is ready for use!

figure(2);
colormap(gray(256));
gray_spectrum=((double(subImage(:,:,1))+double(subImage(:,:,2))+double(subImage(:,:,3)))/3.0);
image(gray_spectrum);
figure(3);
colormap(gray(256));
Grayimg_reversed=flipud(gray_spectrum);
graph=mean( Grayimg_reversed ,1);

%Finally I can plot a nice graph with meaningfull axis
plot(XAxis,graph);
pause(3);
delete(vid);

For improvement, I would suggest being able to save the resulting vector with easy to some sort of table, to later use this big table to guess what I have in front of it - using Hungarian or other solver method.

Virtualbox and old Windows



I think it's always cool to once in a while boot your old computer inside your new one, just to keep track of the old stuff you've done.

So here is a tip on how to run Windows XP for free inside Virtual Box.

Import Windows XP Mode into VirtualBox #while maintaining product activation:
  1. Download Windows XP Mode (WindowsXPMode_en-us.exe | MD5: bf3726d684d3acb98185665123c9efcf)
  2. Extract xpm from WindowsXPMode_en-us.exe with a file archiver like PeaZip Portable.
  3. Add .rar extension to xpm
  4. Extract VirtualXPVHD from xpm.rar
  5. Add .vdi extension to VirtualXPVHD
  6. Create new machine in VirtualBox, specifying VirtualXPVHD.vdi as the hard disk
  7. Once initial setup is complete, uninstall Virtual PC Integration Components from Add/Remove Control Panel
  8. Install Guest Additions (Devices > Install Guest Additions...)
  9. Shut down virtual machine
  10. Download pcbios.bin (MD5: 12ccdc652b30c6d1e307c6f7deff5d24) from VMLite and copy to a directory on host computer (e.g., C:\vm\)
  11. "C:\Program Files\Oracle\VirtualBox\VBoxMange.exe" setextradata vm-name "VBoxInternal/Devices/pcbios/0/Config/BiosRom" "c:\vm\pcbios.bin"


If your games start bugging, activate the Stretch after the Guest Addition installation, and everything will run fine.

If you are looking onto Windows 3.11 and MS-DOS, well, just download those from the web and install them in a clean machine. On my case I couldn't get Windows 3.11 to auto boot after the installation, so when my machine start, I type win [enter].

Using GCALCLI to access Google Calendar



So, I had a netbook lying around, an old ASUS SURF 4G, and thought "hey, it would be cool to look my calendar on this, and make a key hanger with it's screen". So I thought, ok, I will let the browser open in google calendar and run to the street to find something to build the key hanger. Unfortunately, my ASUS has only 4GB SSD HD, so right now it's loaded with a custom Gentoo that will never update, that I've built long ago. This custom Gentoo runs an old Opera Browser. And my Opera Browser can load everything, except Google Calendar.

So I should just stop here and go outside walk on the beach... Nah, I HAVE to fix this. So how? Doing some Google Search I've discovered that there is a command line way of getting the calendar, using a python script called gcalcli. I have Python 2.7.1 already built into, so it's easy right? Uhm, wait, it depends on other things... Ok, no problem, just download everything with Pip. Oh, Pip is not Installed?

Ok. Run this:

 curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py  
 python get-pip.py  

Then you need to get Google API Client for Python. Type this:

 pip install --upgrade google-api-python-client  

Now you need python-dateutil. Go pip:

 pip install python-dateutil  

and vobject and parsedatetime Python module. It's time for:

 pip install vobject  
 pip install parsedatetime  

Ok, now you are prepared. Right now, all you need to do is download gcalcli:

 curl -O https://raw.github.com/insanum/gcalcli/master/gcalcli  

And if everything is fine, just make it executable:

 chmod +x gcalcli  

Now you can run it.

 ./gcalcli agenda  

Everything should be self-explanatory from here on. You can't validate the Oauth2 through links because Google will ask for javascript before giving you the authentication code. With gcalcli you can do much more than just seeing your agenda. Have fun accessing Google Calendar from the command line.

Coursera



Today I enrolled for the gamification course on Coursera. It's a regular course with homeworks and tests, the video lectures are awesome and I also bought the book already.

Which also reminds me that I have a ton of things to write in here about some other books that I've already read on Kindle. I will let survival of the fittest decide which project will see daylight.

So I leave this, from Why School?: How Education Must Change When Learning and Information Are Everywhere (Kindle Single) by Will Richardson:
One of the challenges I give the schools I work with is this: “How can you make sure that every student who walks on graduation day is well Googled by his or her full name?” 
On a side, the gamification definition from the FTW book.

Gamification: the use of game elements and game-design techniques in non-game contexts.

Processing genome using Flex and Bison

Is it possible? Has anyone ever tried?

I'm looking at a bacteria right now, just downloaded 2.8MB of ATCG madness. Wondering if DNA is a regular language.

XKCD Time Strip

I want to download all the pictures featured on the time strip. I think that the image name is cryptic using Skein. But, there is an easy way: people are uploading the drawings on the XKCD Wikia. So I installed wget on Windows8. Tried this without success. Any ideas?

 for ($i=50; $i -le 55; $i++)  
 {wget --wait=1 -r -P . -A png "http://xkcd-time.wikia.com/wiki/File:Time$i.png"}  
The png images downloaded are corrupted.

Simple Python to Batch search CAZy Database



This code may be old. please follow here to the most up-to-date version: https://github.com/ericoporto/CazyBatchSearch

Yes, a way to use a table to search the Carbohydrate-Active enZYmes Database. Below the Python 2.7.3 script.


'''
Copyright 2014 Érico Porto

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
'''
from __future__ import print_function  
 import httplib  
 def findEnzymeInCazy(enzyname):  
   conn = httplib.HTTPConnection("www.cazy.org", 80)  
   conn.connect()  
   conn.request('GET', "/search?tag=4&recherche=" + enzyname)  
   lines = conn.getresponse().read().split('\n')  
   for i,line in enumerate(lines):  
     if ( '<tr><td><a href="http://www.cazy.org/' in line ):  
       linkLine = lines[i]  
       j = linkLine.find( '"http://www.cazy.org/' ) + 21  
       k = linkLine.find( '.html"', j )  
       return linkLine[j:k] # beteween first and second double quotes  
   return None  
 f = open('saida.csv','w')  
 print("enzima     ; rankdomal", file=f)  
 print("enzima     ; rankdomal")   
 for line in open("enzylist.csv","r"):  
   pieces = line.split(";")  
   enzyname = pieces[0].strip()  
   enzyInCazy = findEnzymeInCazy(enzyname)  
   if ( enzyInCazy != None ):  
     print(enzyname.ljust(15) + '; ' + enzyInCazy.ljust(20), file=f)  
     print(enzyname.ljust(15) + '; ' + enzyInCazy.ljust(20))  
   else:  
     print(enzyname.ljust(15) + '; ' + "not found!", file=f)  
     print(enzyname.ljust(15) + '; ' + "not found!")  

So, you will need a file named enzylist.csv for this to work. Here take this:

 BAI68730
 BAH05588
 ACV62532
 EAL90874
 ABG47447
 ACT04224

So if you run it, you should get something like:

 python .\enzymtable_simple.py  
 enzima     ; rankdomal  
 BAI68730    ; GH57  
 BAH05588    ; GH94  
 ACV62532    ; GH94  
 EAL90874    ; GH13  
 ABG47447    ; GH18  
 ACT04224    ; GH51  

So all should be good. Yes I run Python on Windows 8 using PowerShell. Just add the Python folder to the PATH variable, and all should run well - and also, PowerShell is much faster and easy to use than CMD.

Google Treasure Hunt


Throw the numbers on the browser for going to the gps location. Start researching on the wikipedia about Willian Kid or other pirate.

Example:
Meat | -21.53,46.05
Squid |  34.61,137.7
Boat | -28.30,-57.30
Aligator with letter C | -37.85,-25.83

Right now I could find C R and V if I remember correctly.

Small tip on faster learning when audio is required

Use 1.5x speed. Thanks LifeHacker

Farewell Google Reader

So that all got me thinking... Could I do something? So I started messing around with Python... Turns out yes, but will take a little while...

 from __future__ import print_function  
 import urllib2  
 from bs4 import BeautifulSoup  
 f = open('teste.txt','w')  
 page = urllib2.urlopen("http://kotaku.com/5991061/the-best+looking-isometric-games")  
 s = page.read()  
 page.close()  
 soup = BeautifulSoup(s)  
 txt = soup.find("div", "post-body").getText()  
 print(txt.encode('utf-8'), file=f)  
 f.close()   

So what's my idea? I need some good method to filter and get content from a webpage (usually a blog). Right now I think I will need different codes for different webpages and some way to keep these codes organized. I also need some way to know when any of these pages is updated, which I will use RSS. At the end I want to grab all this and send to my Kindle.

There are paid services right now that do just that. But I know I can probably do something similar from my computer for free.

Oh... And Google search pointed me this using Calibre: http://www.youtube.com/watch?v=aw3jCBQkfWQ

Best Translation and Other



If anyone ever need this, I got this from a friend. The best translation for Affordability in portuguese is "Viabilidade Econômica".

Meetings

I stumbled on this post today:
Every meeting has to have a leader, a stated purpose, a start and end time, and a valid reason for each and every person to be there. The leader documents conclusions, plans, action items, whatever, then follows up.

from http://www.inc.com/steve-tobak/6-ideas-for-awesome-meetings.html via lifehacker

Windows 8 on regular Laptop



I have a lot of stuff to write on lately, but this is something that I must start talking about. The Windows 8 experience.

Three days ago, was the last day to update to Windows 8 on low price, so I thought I should try it. Currently, I'm in a hotel with painfully slow internet and once a exe file started downloading before any credit card information given I was not so sure anymore to want this.

It goes like this: once you click, you will get an exe file that checks for compatibility between your computer, it's devices and the software you have installed. At the end, it will spit a big report, with everything that will work and will not work once the new OS is installed, and tells you to read this report carefully before buying. Steam was there, it said it was compatible, among with many programs: 66 were ok and 21 were not. The only software not in the compatibility list that I did cared about was Oracle Virtual Box. I think I can live without it.

Installing Windows 8


Once you bought it, it will tell you several times to keep the Windows serial number: you should keep it, but don't worry, you will not have to type that long combination. Since it's a upgrade, it will not require you any other media either, it will run quiet in a window, with constant rolling small dots telling you that the installation didn't crashed.

I selected "clean install" option, this will create a Windows.old folder in your C: drive, with all the contents from your previous Program files (both), Documents and Windows folder, so you can copy stuff from it after - I had lots of free hard disk before installation, so I'm not sure if this apply to everyone since nothing is explicitly said.

The installation runs fine, the computer restarts, and after some time you are good to go - the time the whole process takes depends on your internet connection, so don't do this in a crappy hotel like me, you will regret it. Once the computer is on, you will see the first bug... At least here I had a cable with internet connected to my computer - I could browse fine in IE10 - but it didn't detect the internet connection until I turn the Wifi on, so if you don't want to do phone activation, simple turn on the Wifi card and it will activate your Windows 8 for you.

Configuring and Drivers


Yeah, it is not over. It didn't download any actual driver for my computer, so I had to jump to my manufacturer website - currently I'm using a A530 LG Notebook. The Windows Update also detected my missing hardware, but it didn't download or installed anything until I opened it - just click ÿ key and type windows update, to be presented to the faster way to access anything you can name in your computer.

If you have a Touchpad Synaptics, download it's latest driver to have a great experience - take some time configuring it to match your expectations, for some reason the default scroll is inverted: two fingers up to go down, and two fingers down to go up, so deselect that option. This is the first great thing you will note: the whole interface is a lot friendlier to touchpad, which in a laptop is great news.

And don't forget the Nvidia Driver. Install it, configure it to always use your Nvidia board, and you are good to go! At least I use a tablet for mobility and my laptop is just my deployable computer to travel.

Software

So, let's run that essential compatibility list. I'm going to install Visual Studio 2010 later today and add to this list.

Steam


Great news. Your Sitting there in Windows.old, Program Files (x86), so just copy it to the real program files, and run the installation from web. You will have to reinstall pretty much all games, but it will be a looot faster and no redownloading need.

But BEFORE reinstalling anything do this: download and install Games For Windows Live in Windows 7 Compatibility Mode. If you don't, all your Capcom games won't work. Trust me on this.

So, yeah, Steam will work, exactly how you know it - some games I feel like they have improved speed. The only problem is that you will wish that Gabe could really embrace it, because not having a Metro Steam is almost sad. Some people are taking care of it now: http://netbooknetwork.net/2012/steam-windows-8-metro/.

And yeah, there is default game store from microsoft, that LOOKS like the Xbox one, but no, it's not the same, it's slow, it's bugged, don't bother trying.

Kindle


You can read all your books - you are probably not doing that, but you will often want to use your notes and highlighted paragraphs as reference in your Word documents - Endnote, Zotero a like... And there is nothing here to help you do that. Why not? I don't know - this would the most helpful thing to have in this app, but it is not there.

And the only thing I would like to read on computer is my journals and magazines - but they are not available, only in the kindle device AND Android app. So, unless you don't have a real life Kindle, this app is crap.

Anti Virus


Download your anti virus software, whatever it is. I use Avast, but you can use whatever you like. Don't go explore the internet without it.

Office 2013


So, if you have a Microsoft Office 2010 license, you can obtain a 2013 license for free - only one. The Brazilian offer is here: http://office.microsoft.com/pt-br/offer/. It is great, just lower the monitor bright while using so you  don't get tired while using - it should lower the bright automatically. It support SkyDrive - and now it is a real folder in your computer, finally! I just don't know how to encrypt it, so my critical stuff is still in my documents. I will skip Office for a moment because it's weekend and I could not really explorer it.

Encryption


Yeah, if you have Windows 8 Pro, you can encrypt any folder by right clicking on it, and selecting properties. You could do this in Windows 7 Pro, but all computer only came with Windows 7 home. Nice feature, now if someone doesn't know your password, they can't stuff your HD in their computer and read your personal documents. This is great and transparent - turn it on and forget it.

Windows key


Click in it to switch between what are you doing now, to what you were previously doing, while in Metro. In Desktop, it brings you back to Metro. In Metro, use Windows+D to go back to desktop. The switching is fast. Really fast. It grows in you like rolling screens in an Android phone.


Summing it up


I could go all day talking about, because I love it: play all your games, get Evernote, Netflix. The Microsoft email app is great. The message app is great - and you will wish it had Google Talk integrated in it. I just hate how Google is not offering apps there. The great thing is that I can keep my friends and games from Steam, with all my friends from Facebook while having a fast OS, that is still great to productivity: which to me is the greatest feature of Windows, it is my typing machine of choice.

Go ahead and try it. And tell people you want more Windows 8 Apps - there are just so few of them. But I also want only quality ones - not a cluttered appstore like the Google Play. Right now I'm waiting the VLC Metro to come out. In the future, maybe Google can help out the Chromium guys to release a Chrome Metro App.

But desktop is still here, it runs everything. Notepad++, 7zip, you name it, you can run it. But not Google apps - they are not here.



Powered by Blogger.