Scanner…
January 18th, 2011I haven’t really touched Processing in quite some time, but yesterday during desperate housewives I was a bit bored so I fired up processing and coded a “video scanner”.
Video
The idea is very simple: it takes the first vertical video line of a webcam and places it at the right side of the screen. Then all the pixels on screen are shifted one column to the left, and everything can start over.
In fact this is so simple that I’m certain this has been done over and over already, however, it’s still a pretty effect which, surprisingly, can be entertaining for quite a while.
Download
Scanner-Win.zip (not tested, might not work)
Scanner-Mac.zip
Use Apple+F / Alt+Enter for fullscreen.
Oh, if you happen to be in Linz at the moment you can see this in the shopping window of bb15 as part of the “showcase in progress” series. Google Maps Link
Actually using unicode on a mac
January 10th, 2011I really like to use unicode characters, like α, β, γ, →, ♥,♬ , etc. in my tweets and everywhere else i can.
One way to do so is to use a site like decodeunicode to search for the character and then copy&paste it.
Another aproach is to use the input methods support built into MacOS. To enable it follow those steps:
- Download unicodenames.inputplugin (use “save as” if your browser thinks this is an mp3 file)
- Move the file to your home-folder/Library/Input Methods/
- Open System Preferences > Text > Input Sources
- There scroll through the list an check “UnicodeByNames”. If it’s not there you’ll need to logout and back in.
- Also tick “show in menubar”. To be able to switch quickly i suggest you also set a shortcut for switching input sources.
However, use the “same input method for all documents” option, or things will get confusing. - Now use the menubar item to switch to your new “language” and type “music” followed by a space into any textbox.
- Enjoy!
If you want to add your own custom symbols just edit the file in TextEdit, you’ll see it’s very easy. But we warned – you’ll need to logout and back in before the changes apply.
AppStore scraper in Scala…
August 10th, 2010I’m really really excited about scala, I wrote my first script today that scrapes reviews from the iTunes store and counts the star-responses. In the end it’ll output something like:
* 1
** 0
*** 0
**** 2
***** 3
I’m quite certain the code below could be made shorter in many places, but i just love scala for being able to write stuff like:
println( " *** " + ratings.filter( _==3 ).length )
Just compare to this to the imparative style version:
int rating = 0;
for( int i = 0; i < ratings.length; i++ )
if( ratings[i] == 3 ) rating ++;
println( " *** " + rating );
URLs and store-ids taken from
http://blogs.oreilly.com/iphone/2008/08/scraping-appstore-reviews.html
Anyways, here’s the code:
import java.net._
import scala.xml._
scrapeAll( "SoundyThingie", "382900826" )
def scrapeAll( name:String, id:String ) = {
println( "Scraping " + name + "..." );
var ratings = List[Int]()
getStores.split( "\n" ) foreach {
e =>
val Array(a, b) = e.reverse.split( " ", 2 )
val storeName = b.reverse
val storeId = a.reverse
print( " >" + storeName + "..." );
val result = scrape( storeId, id );
ratings ++= result;
println( result )
}
println()
println( " * " + ratings.filter(_==1).length )
println( " ** " + ratings.filter(_==2).length )
println( " *** " + ratings.filter(_==3).length )
println( " **** " + ratings.filter(_==4).length )
println( "***** " + ratings.filter(_==5).length )
}
def scrape ( storeId:String, id:String) = {
val urlString = "http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=" + id + "&pageNumber=0&sortOrdering=2&type=Purple+Software"
val url = new URL( urlString )
val connection = url.openConnection()
connection.setRequestProperty( "User-Agent", "iTunes/4.2 (Macintosh; U; PPC Mac OS X 10.2)" )
connection.setRequestProperty( "X-Apple-Store-Front", storeId + "-1" )
val root:Elem = XML.load( connection.getInputStream )
val hBoxes = root\\"HBoxView"
val ratingNodes = hBoxes filter { e => ( e\"@alt" ).toString.trim.contains("star") }
val ratings = ratingNodes map { e => (e\"@alt").toString.split( " " ).head.toInt }
ratings
}
def getStores = """United States 143441
Argentina 143505
Australia 143460
Belgium 143446
Brazil 143503
Canada 143455
Chile 143483
China 143465
Colombia 143501
Costa Rica 143495
Croatia 143494
Czech Republic 143489
Denmark 143458
Deutschland 143443
El Salvador 143506
Espana 143454
Finland 143447
France 143442
Greece 143448
Guatemala 143504
Hong Kong 143463
Hungary 143482
India 143467
Indonesia 143476
Ireland 143449
Israel 143491
Italia 143450
Korea 143466
Kuwait 143493
Lebanon 143497
Luxembourg 143451
Malaysia 143473
Mexico 143468
Nederland 143452
New Zealand 143461
Norway 143457
Osterreich 143445
Pakistan 143477
Panama 143485
Peru 143507
Phillipines 143474
Poland 143478
Portugal 143453
Qatar 143498
Romania 143487
Russia 143469
Saudi Arabia 143479
Schweitz/Suisse 143459
Singapore 143464
Slovakia 143496
Slovenia 143499
South Africa 143472
Sri Lanka 143486
Sweden 143456
Taiwan 143470
Thailand 143475
Turkey 143480
United Arab Emirates 143481
United Kingdom 143444
Venezuela 143502
Vietnam 143471
Japan 143462"""
Evolution…
May 31st, 2010Carl Sagan is awsome!