2016-04-09

In The Beginning...

Years ago, when I first heard that Ubuntu Touch would have apps written in QML, I decided to write a Qt based front end for MuttonChop!. My logic was, if Ubuntu is using QML then there will be support for Qt. With my favorite text editor at the ready, I began to hack together some Python code to make a Qt application using Pyside.

Since all of my MuttonChop! related projects are named after sideburn sporting figures from California history, this project was named after Commodore John F Stockton. The project name has stayed, but from the very beginning the project strayed from being a MuttonChop! controller to something completely different.

Once the basics of the main UI window for Stockton had been coded, I thought "hey, why not just add a WebKit WebView to access the Mobile UI for MuttonChop?". Being lazy and not wanting to code another MuttonChop UI, I did just that. From there, a URL input was added to give the end user a way of changing the URL displayed in the WebView.

After that, I opened a URL in Stockton, resized the window, and moves the window to a specific location on my desktop. Suddenly there was a need to always have a Stockton window open in a fixed location on my desktop when Stockon is launched with a certain url. Bang zoom, clacking the keyboard, and the main features of Stockon were done.

Fast-Forward a Bit...

There were actions that I wanted to perform using my mobile device and it was necessary to write a few "apps" to get the job done. Aside from doing what the apps were supposed to do, I wanted them to "run" on all mobile devices as well as on the desktop, and the easiest way for me to accomplish that feat was to write the apps using HTML, Javascript, and CSS, and then access the apps via a web browser on any given machine. For the most part, all of the apps ran fine in Stockton on my desktop. However...

Problems Were Encountered

  • CORS... fucking CORS!

    CORS is what makes writing an app that runs in a webbrowser such an amazing pain in the ass. When I write a python app that makes web requests, I simply write some code to make a request, and then process the result of the request. This is the same with Ruby, and Vala, and just about every other programming language... with the exception of JavaScript running in a browser. CORS is what limits apps in a browser from only making AJAX request to files on the same server hosting the app.

    Fortunately, the WebKit1 library fully allows developers to configure a WebView to load local files and let those local files make XmlHttpRequests to remote web servers. Thanks WebKit1!

    Sadly, WebKit2 doesn't seem to have this feature.

  • Debugging

    For some unknown reason, not all of my code works as expected and it is good to be able to debug stuff. By setting the "enable-developer-extras" property to True, I was able to um.... enable developer extras, and this adds "inspect element" to the contextual menu when one right-clicks on a stockton webview.

Wooooweee! After updating the code, not only did I have a fine desktop application, I also had a rudimentary HTML5 compliant browser that would run on an n900.

I prefer Gtk

It's true, aesthetically I prefer Gtk to Qt. Although I think I might prefer Qt to Gtk from a developer point of view.
Anyway, I figured it was time to port Stockton from Python2 to Python3, and this necessitated switching from Pyside to either PyQt or Gtk. In this regard, I went with Gtk. At the same time that I was porting to Gtk, I also attempted to port to WebKit2. Lamentably, it was during the port that I discovered WebKit2 lacked the ability to disable that CORS crap. Oh well, I submitted a bug for the missing WebKit2 feature, and switched to WebKit1.

While porting the code, I was fortunate to find https://lazka.github.io/pgi-docs/ which is an indispensable documentation source when using Python and Gobject Introspection to access various libraries from Python. Since the documentation is in HTML format, I downloaded the docs, and run them in Stockton... because I can. :)

Now quit reading, and go create a solution to a problem.

Oh yea, if you are interested in such things the source is available at https://gitlab.com/jezra/stockton

Comments
Name:
not required
Email:
not required (will not be displayed)
Website:
not required (will link your name to your site)
Comment:
required
Please do not post HTML code or bbcode unless you want it to show up as code in your post. (or if you are a blog spammer, in which case, you probably aren't reading this anyway).
Prove you are human by solving a math problem! I'm sorry, but due to an increase of blog spam, I've had to implement a CAPTCHA.
Problem:
2 plus 9
Answer:
required
2016-03-12

While looking for treasure at my local ReStore, I happened upon a stained glass lamp that "needs some love". $19 later, I was heading home with a lamp that most certainly needed some love.

The Lamp

The lamp had been dropped and was broken in a few places. Fortunately I have a box full of adhesives and at least one of them should do the trick.

Unfortunately, the previous lamp owner tried to fix the lamp, and my first order of business was to remove the packaging tape that was holding the lamp together, as well as remove the bits of adhesive the previous owner had tried to use to fix the lamp. rookie.

Break #1

Fixing break number 1 was a fairly simple process of bending some metal, applying a healthy dose of J-B Weld, and holding everything in place with some masking tape.

Break #2

The second broken part of the lamp was a bit more serious. Shattered glass was involved, and lamentably, half of one of the red flower pieces was shattered to such an extent that I didn't want to put all of the pieces back together. It took a while, but eventually all of the pieces were put together with J-B Weld and tape.

Amazingly, I didn't cut myself on any of the broken glass. :)

Just Like My Truck

Creating a replacement for the missing flower piece was fairly easy. Having recently repaired a broken tail light on my truck, I had some "cut and peel" repair tape sitting around that would be perfect for this lamp.

Good as New!

After the J-B Weld had cured over night, I removed the masking tape and applied the "cut and peel" tail light repair tape.

Hot damn, that is looking good!

Let There Be Light

The final test of any lamp is "plug it in". Not only do I have a wonderful stained glass lamp, I can now put "Stained Glass Lamp" on my ever growing list of broken things that I have repaired. Now I just need to actually make a list. :)

In total, it probably took a little under an hour to fix this lamp. Now quite reading, and go fix something.

Comments
Name:
not required
Email:
not required (will not be displayed)
Website:
not required (will link your name to your site)
Comment:
required
Please do not post HTML code or bbcode unless you want it to show up as code in your post. (or if you are a blog spammer, in which case, you probably aren't reading this anyway).
Prove you are human by solving a math problem! I'm sorry, but due to an increase of blog spam, I've had to implement a CAPTCHA.
Problem:
5 minus 1
Answer:
required
2016-03-06

A state of semi-focused relaxation, with a smidgeon of oomph, and a smattering of zing, is just the thing to help me unwind. For some reason, the tones of The Mermen always seem to direct me towards that state. Live recordings of Instrumental Surfadelic music puts my mind in a wonderful place for coding, crafting, sleeping, driving, creating, and simply breathing.

For the most part, music listening to me means "put everything on random". While this is fine for most things, there are times when I want to listen to more than one track at a time by any given artist. Since the majority of my music listening involves using MuttonChop! for playback, and most of that playback happens on Wind (damn, that old machine needs updating), a bit of code with HTTP requests should do what I need.

the Need

What I really wanted was a script that would:

  1. take a number as an argument
  2. get a list of all Mermen tunes from Wind
  3. pick a random index in the tune list
  4. starting at the index, have Wind queue X number in a row from the list

Enter the ruby

#!/usr/bin/env ruby
require 'open-uri'
require 'json'

#how many tracks are going to be played?
num ARGV[0].to_i
num if num == 0

#what is the URL for all mermen tracks on wind?
url "http://wind:2876/audio/search/mermen"

#get the text from the url
text openurl ).read()
#parse the text to JSON data
data JSON.parse(text)
files data['files']

#base zero offset
bzo num-1

#get a random number between 1 and the number of mermen tracks - the num we want to play
queue_index rand(files.count-(num))

#loop from our random number to random number + our base zero offset
(queue_index..queue_index+bzo).each do |i|
  # get the file at this index
  file files[i]
  #get the id of the file at this index
  id file["id"]
  #create a queue url for this file
  new_url "http://wind:2876/queue/add/audio/#{id}"
  puts "#{i}#{new_url}"
  #call the url to add the file to the queue
  opennew_url )
  #don't go to fast
  sleep 0.1
end

For easier copy/paste, the code is available at http://hoof.jezra.net/snip/os

So there you have it, a nice script to do exactly what I want. Now, when I need to get into that certain place, a quick 'wind_queue_mermen.rb 5' does the trick. Why stop there? A bit of blather config editing, and queuing five Mermen tunes is as easy as picking up the Cronos microphone and saying "queue five mermen". BOOYAH!

Now quite reading, and go to https://archive.org/details/Mermen for some wonderful live recordings.

Comments
Name:
not required
Email:
not required (will not be displayed)
Website:
not required (will link your name to your site)
Comment:
required
Please do not post HTML code or bbcode unless you want it to show up as code in your post. (or if you are a blog spammer, in which case, you probably aren't reading this anyway).
Prove you are human by solving a math problem! I'm sorry, but due to an increase of blog spam, I've had to implement a CAPTCHA.
Problem:
3 plus 9
Answer:
required
subscribe
 
2016
2015
2014
2013
2012
2011
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008