Rooting the nook touch simple

Rooting the nook touch simple

  • Add the ability to browse the internet, read saved Pocket Articles, and browse Dropbox on your B+W Nook Simple Touch.
    • Fun Fact, after rooting, you can navigate through play.google.com on your computer and install apps remotely to your nook!
  • On firmware 1.2.1
    • Go to Settings > About to find firmware version number
  • With the NookManager 0.5.0 from here
    • Explained in more detail here
    • connect microSD to a computer and identify its address
      • diskutil list
    • diskutil unmountDisk /dev/disk# to unmount it
    • dd if=/path/to/NookManager.img of=/dev/rdisk# bs=1m
    • Then insert microSD into a powered off nook, startup, and follow on screen instructions to root
  • I also installed:
    • SearchMarket To install apps from the Android Store (default Android Market does not have newer apps)
    • Instapaper works the same as pocket (but pocket isn’t compatible)
      • Just drag the *.apk to any directory on the nook, and browse to it on the nook. More Info.
    • Opera Mobile, Way faster than the default browser
    • Google Apps, bunch of steps to install, but went well and works fine.
    • Cloudpipes for browsing dropbox (Drobox official, Downloader for Dropbox, and Dropbox / Box.net Client did not work)
    • ES File Explorer, not really that useful.

Swapping the Dictionary

  • place the microSD card with NookManager.img into the nook and bootup, select Yes, start wireless, and then select Start ADB
  • adb connect <yourNookipaddress> in the terminal on your computer
  • Lets look for the dictionary file, I know that it should be a *.db file
    • adb shell
    • find . -iname "*.db"
      • Now lets browse the results (see here). Most notably, we see:
      • /data/media/B&N Downloads/Dictionary/2940043623508/dictionary.db and /data/data/com.android.providers.userdictionary/databases/user_dict.db both look promising
    • if we then get out of the adb shell with exit, we can do adb pull <nook directory> to get both of these files copied to our computer
      • using something convenient like SQLite Database Browser we can visually browse through these databases.
        • its obvious that user_dict.db is not what we are looking for, its practically empty!
        • however, dictionary.db is much more promising
          • yet, if we were to delete the file via rm dictionary.db (while in the shell and the directory), and then adb push <local new dictionary file> /data/media/B&N Downloads/Dictionary/2940043623508/dictionary.db to overwrite the file, and then restart the nook, we would notice that the nook restart would take a while
          • Then, we would notice that english dictionary lookup still works, and our new foreign dictionary lookup does not work!
          • What could have happened? Could the english dictionary have redownloaded and replaced the one that we had just placed in the folder?
            • No, if we adb in again, and browse to the directory again, we see with ls -l that the file size indeed matches the file we placed in there, and not the one that we removed
          • So where is the real dictionary file?
          • To be continued…
    • finally: adb disconnect
Advertisements

Why Python Ruby JS are slow – Alex Gaynor

Python Ruby JS are slow

Alex Gaynor

Myths on Why Languages Are slow

  • dynamic typing
    • names are bound and change at runtime
    • adaptive compilation
    • observing types
    • method jits
    • predictive type inference
      • brian hacket
      • can’t type inference JS
  • Monkey patch availibility

Rather, Idioms of the Language determine speed

Python’s slowness:

  • hash table
    • pythoners think dictionaries are lightweight
  • object == hash table
    • too simplistic idea
    • different at a fundamental level
    • fixed set of keys, versus: mapping arbitrary set of keys to arbitrary set of values

C is fast because:

  • Bring your own buffer philosophy

Slow bits

  • allocation
  • copying
  • hash table lookups

Not Slow Bits

  • attribute accesses
  • method calls, sends
  • global, constant lookups

Removing slight jQuery Dependencies

  • $(document).ready(function () {
    • Turns Into:
    • function r(f){/in/.test(document.readyState)?setTimeout(‘r(‘+f+’)’,9):f()}
    • r(function(){
      • test for the presence of the string “in” inside the string response of document.readyState
      • then, waits for 9 ms and reruns its own call
  • var canvasHtml = $(‘<canvas width=”‘ + 500 + ‘” height=”‘ + 500 + ‘”></canvas>’);
    • Turns Into:
    • var canvasHtml = document.createElement(‘canvas’);
    • canvasHtml.setAttribute(“width”, “500”);
    • canvasHtml.setAttribute(“height”, “500”);
  • $(‘body’).append(canvasHtml);
    • Turns Into:
    • document.getElementsByTagName(‘body’)[0].appendChild(canvasHtml);

Starting Coffeescript

  • Installation
  • Named Functions (global) are not available, Function Expressions with:
    • coffee = (message) ->
    • last line is returned, interpolation just like ruby
    • can be called without parentheses
      • convention is to use parentheses everywhere except on outermost function calls
    • optional parameters just like python
    • anonymous functions: (argument) -> and everything else is the same (sans curly braces and semicolons)
    • instead of this
      • @name instead of this.name
  • compiling
    • once: coffee -c file.coffee
    • watch: coffee -cw file.coffee
    • bunch of coffee files: coffee -c src -o output_dir
      • -o means output into output_dir
  • Conditionals
    • parentheses are optional
    • ruby style works: do_stuff if this_is_true
    • No ternaries! :( instead: if ___ then ___ else
    • no type conversion :(
    • on/off, yes/no
    • unless exists in CoffeeScript!
    • switch statements have gotten a makeover
      • no need to use case or return
    • can use question marks which convert to check whether a variable is undefined or null
    • Ruby’s ||= exists as ?=
      • similarly, if you want to run a method on something only if it exists: in_question?.do_if_true()
        • or, call a function only if it exists: thing.function_in_q?()
        • this is, however, considered a code smell, and shouldn’t be used too much
  • Iteration
    • ruby ranges
    • new lines instead of commas for creating arrays
    • Python for loops rather than JS forEach
      • do_thing for apple in basket when apple isnt rotten
        • yes! isnt is a keyword
        • list comprehension instead of ruby map
        • parentheses are important for list comprehensions, blocks seem to work like parentheses
    • splat is a trailing ellipsis:
    • objects don’t need curly braces or commas
      • do_hash_thingy for key, value of hash
  • OO
    • can declare classes
    • constructor: (@instanceVar1, @instanceVar2) ->
      • will assign args passed in into this.instanceVar1 and 2
      • called property arguments
    • can use extends like extend in Backbone
      • class Child extends Parent
      • super works like in Ruby
    • Fat arrow =>
      • binds current this as the inner closure’s this
  • After CodeSchool

Old School vs New School lite HTML Parsing

Gawk + sed VS Nokogiri

  • Etsy’s api can be queried to fetch recent listings on their website, one of the parameters that may be used in the query is category which takes an item’s ” category path” as a value. An example is /crochet/doll  where crochet is the category and doll is the subcategory.
  • Unfortunately, I could only find this html page as a source to display the possible categories and subcategories that would be necessary say, when creating a dropdown menu for both to run a search with.
  • So, how should we get the pertinent information (category and subcategory) out of this html file, and get something like this and maybe even this?

Gawk & Sed

  • All the paths are listed in the html file, so lets use a regex to create a JSON file to use in some Javascript application
    • <a href="/listing-category/crochet/doll">Doll</a>
  • gawk 'match($0, /<a href="\/listing-category\/(.*)\/(.*)"/, ary) {print ary[1],ary[2]}'
    • why not just awk? I’ll want to match two groups (category and subcategory) and then reformat them, this is a lot easier with gawk
    • match for regex
      • using the single quotes means we don’t have to escape spaces
      • remember that we are using basic regular expressions, not modern
    • $0 means that we are searching on the whole line
    • 3rd argument in the match() function is an optional array
    • then print just makes sure that everything other than category and subcategory pairs are not left in the stream
  • sed 's/\([a-z,_]*\) \([a-z,_,0-9]*\)/\    {"\1": "\2"},/'
    • now that gawk has eliminated all the superfluous lines, we use sed to format each line of the JSON file
    • the substitute option is used here, and once again, basic regex
    • notice that there will be an extra comma on the last line of the file this way
      • sed '$ s/\(.*\),/\1/' >> etsy_cat.js
        • $ means the last line
  • All of this is then inserted into a file between two brackets

Ruby & Nokogiri

  • in irb, after installing the nokogiri gem
    • f = File.open('etsy_categories.html')
    • noko = Nokogiri::HTML(f)
    • f.close
    • looking at the page source, all the lines that we are interested in are children of a div with class="children"
      • noko.css('.children').map { |e| e.children.map {|c| c.values}.flatten }
        • this can get us started with what we want, if we wanted the same exact thing as above:
        • noko.css('.children').map do |e|
          • e.children.map do |c|
            • if c.values.first
              • key_val = c.values.first.gsub("/listing-category/", "").split("/")
              • {key_val.first => key_val.last}
            • end
          • end.compact
        • end.flatten.to_json

So Which is Better?

  • gawk and sed were a little bit more fun to use, but that’s just me
  • Some would say that regex is not the tool to parse general html (break it down into its components), but in this case, the fact that our source text is surrounded in html is almost irrelevant, since we identify the presence of an important part of text with a keyword (listing-category) in addition to the anchor tag
    • So, although nokogiri is a tool built specifically for parsing html, its specialization isn’t entirely a must-have in such a situation
  • But I would say, if I had to do any more with this source page than I have already, I would continue with using nokogiri
    • So nokogiri is better suited and fancier, buts its flexibility isn’t needed in this lite case of html parsing, so the fun of using gawk and sed make them the winners for me

Design Tips

Body Copy

  • Header 200-300% of body
  • Subhead 150% of body
  • Body copy – 16px most the time
  • Byline text – 75% of body

Leading should by 150% of body copy, i.e. line-height: 1.5; in css

50-60 characters per line is a good length