randomness in my head

Thursday, June 3, 2010

SF vs LA

Wanted to use a trip planer and get big blue bus information bc it's so much more awesomer than the LA metro bus. So yeah, anyway the BBB website is at least 5 years out of date and running asp. it looks pretty difficult to scrape and they are going to put their data into open-format one of these days... after the city council vote to redesign the site

quote from 2009 email

Hey there, Green LA Girl (and Readers) –

Big Blue Bus has been working diligently towards bringing our information on to Google Transit for over a year. We are finally in the home stretch with the vendor who provides our scheduling software, and expect to be part of Google Transit within this calendar year.

On a related note, the proposal to redesign BBB’s website goes before City Council on July 28. With their approval, we’ll be able to rebuild the site to include online, real-time bus information and a trip planner similar to what you find at http://www.Metro.net, among many other helpful features.

I promise to keep you posted as our technology and services develop.

Thanks to you all for riding!
Linda Gamberg
Big Blue Bus
linda.gamberg@smgov.net


Bart on the otherhand has
more apps than you can shake a stick at

*sigh*

Sunday, May 16, 2010

On Ruby Lesson 4

Extra Credit:

How do I put a variable in a string?

Declare a variable called myname and put my name the string into it.

>> name = "Stayce"
=> "Stayce"

It looks like Ruby understood me, but let's double check

>> name
=> "Stayce"

But now we need to learn some funny characters to be able to make ruby understand how to tell the difference between our variable called name (which is set to Stayce) and the rest of the text in a string. The characters ruby looks for to know how to interpret a variable first, then print the string is #{}.

So the Ruby program is running along, listening to your commands, and when it sees a "quote it knows a string is coming. Ruby prints out each character including spaces, then it sees a #hash followed by a {curly-bracket! Ruby stops reading the string, instead it looks up the value of your variable, finds out it's a string, prints that and then goes back to printing the rest of your string until it reaches the close quotes". Ruby's smart, but it can't read minds, so you have to do it this way.

Anyway, here's how to use those characters so you can print variables inside your strings.

>>"My name is #{name}"
=> "My name is Stayce"

Lesson 4 - More Ruby classes

Some other interesting classes are Time and Date. Time has some methods you will use often. Let's check out the Time class and use the .now method.
>>Time.now
=> Sun May 16 23:22:27 -0700 2010
Cool, Ruby tells time. What about the Date class? The .now method doesn't work on the Date class, but the .today method does.
>> Date.today
=> #
That looks like a computer date. Let's see it in English using the .to_s method
>> Date.today.to_s
=> "2010-05-16"
So what are these Time and Date classes? They are classes of their own. Dates and Times are stored differently than Fixnums and Strings and Floats. They are important enough to have their own sets of methods, so they have their own class. But what class does their class belong to?
>> Date.class
=> Class
wtf?! Date belongs to the Class class? What does that even mean? Classes can belong to other classes so they can inherit their parent classes characteristics. That way you don't have to repeat yourself if you have similar "child classes". You can think of why this makes sense if you think of a real world example like classifying animals. Mammals inherit from the Animal class, Dogs inherit from the Mammal class, PitBulls inherit from the Dog class. So when you add Fido to the PitBull class, you don't need to specify that he has four legs, fur, warm blood, and needs to be walked. All of those characteristics would be inherited from the parent classes Mammal and Dog. Whew! That was a lot to explain, but what about the Class class? "All metaclasses are instances of the class `Class’. " That's better explained here: Class: Class.


Symbols - Symbols are another class of objects you use a lot in Ruby on Rails. Before we talk about what Ruby on Rails even is, let's make a couple of symbols to see what they look like.

Symbols are similar to strings but they do not inherit from the String class. I'm jumping ahead of myself here, but if you bother to decipher that last sentence you can maybe guess that classes can inherit properties from other classes;)

You create a symbol using the colon, then name it like this >>:dog

You can tell it's in the symbol class by appending .class and checking what irb returns.

>> :dog.class
=> Symbol

Why you would want use symbols and what they really are is coming up later. Oh, you really want to know now? Are you sure? Just skip ahead if you don't care yet. (Click to show/hide)

Well, in RoR (that's ruby on rails) you often use symbols as:
keys for hashes or to pass named arguments to methods

User.find(:all, :conditions => "admin = true")

as flags for state values

user = User.new 
user.role = :admin

To represent other classes in Active Record

class User < ActiveRecord::Base   
has_and_belongs_to_many :roles   
belongs_to :group   
has_many :friends


That's a peek at some ruby on rails code.  You can't run that code in your irb yet because we haven't talked about data yet.  Programming usually involves storing data...not just typing stuff in a terminal that gets deleted when you close the window.   We'll get to data later.  Let's keep learning about Ruby.


Lesson 5 - 


Instance Variables


Earlier we made variables by typing a word then the =equals sign then a string in "quotes >> firstname = "Stayce" or a number >> age = .













On Ruby and learning what programming is

People often ask me to teach them a beginner's lesson on Ruby on Rails. I don't want to say..."well you need to learn how web pages work, then how servers work, then HTML basics, and then maybe some javascript, then maybe you could understand what ruby on rails does." Sure, that path may be good for web designers, but what about people who are just interested in what it is?

So here goes...Lesson ONE: You will need a mac, or patience and googling skills to proceed on a PC.

Open up your terminal application on your mac.

(Command then Space bar to search, then type terminal, and click it to open the app)

This is your command line. You can customize it however you want... like 1990's hacker style with green text on black...um, yeah!


Now type: irb in the terminal. That's it...just those
3 letters. Then hit return/enter.

irb stands for Interactive Ruby, i = interactive, rb = ruby.

Okay, so what you just did is start a ruby interpreter so you can speak ruby to your computer.

I know, I know, you don't speak ruby. Well, it's just like learning Spanish or Greek or whatever. It's another language, and it's easy to get started speaking a little.

How do you know it has started?

The command usually never tells you if something you tell it works. It only tells you if something has errors. But in this case we see that the cursor (prompt) changed to these little double arrow things. >>

(If it didn't, and you see an error message instead, then you don't have ruby on your mac, and you need to google how to get it...sorry.)

So, where were we. we were about to start speaking ruby to our computer.

First, let's type a number and ask the computer how it would classify what we entered.

Type: 1.class then press return.
The computer replies => Fixnum

Any guesses here? Fixnum sounds like English, almost. And so does Class. Well, you're right. Ruby is close to English. Before we figure out what a class is, let's ask the computer how it classifies a few more things we can type.

Go to town. Type whatever you want followed by .class and see how many classes you can figure out from the computer. You can see what I typed on the right. For instance, if you type another integer (1, 2, 3, 4, 5...10, 1000000, 99929292, etc) you get another Fixnum

>> 1.class
=> Fixnum
>> 2.class
=> Fixnum
>> 43.class
=> Fixnum

Maybe you typed in a price (like $1.25 or a decimal like 42.2222), and you got back Float

>> 1.25.class
=> Float
>> 42.2222.class
=> Float

What if you wanted to use .25, like 25 cents, or a quarter of something. You need to start the number with a zero like this.

>> 0.25.class
=> Float

You can't start it with a . because you will confuse the computer.

>> .25.class
SyntaxError: compile error
(irb):10: no . floating literal anymore; put 0 before dot
.25.class
^
(irb):10: syntax error, unexpected '.'
.25.class
^
from (irb):10

Remember, Your mac will tell you when it can't figure something out. In the case of .25, it tells you exactly what to do if you read the error closely enough.

Okay, most everyone probably saw an error after typing a word, followed by .class. Something like this
>> stayce.class
NameError: undefined local variable or method `stayce' for main:Object
from (irb):11
Ruby knows numbers by default. It knows what to do with them too. It's kinda like a boring calculator...until you know what to do with it. By the way if you find calculators exciting you can stop reading and paint the town red. type 1 + 1 -1000.027383 * 3.14 / 42 and you will get your answer. You can even use algebraic parentheses in there so you can divide pie by 42 then add, or whatever order you like. There's some output, but it makes ruby look kinda lame so far, so don't stop with the math refresher course.

>> 1 + 1 -1000.027383 * 3.14 / 42
=> -72.7639519671429
>> 1 + (1 -1000.027383) * (3.14 / 42)
=> -73.689190062381

Let's get back to words for a moment. How do we use names and sentences in the Ruby language if the computer can't classify them? And what is a class anyway? And what exactly is a float, or a fixnum?

Floating Point Number and Fixed Numbers are kinds of numbers, Fixed Numbers are integers like 1, 20, and 2030818383, and floats are numbers with decimals. If you took math in high school, you probably remember hearing about them;) Ruby has different kinds of Classes for numbers because it treats different numbers differently. Each class has some rules and characteristics so Ruby knows how to handle all objects in a certain class. Almost everything in Ruby is an object. Whatever you type that ruby accepts becomes an object and gets classified as some class.

Another kind of Class is a string. "Strings" is how ruby classifies text you give it. To tell Ruby that you want to use a string, you put it in quotes like this:

>> "stayce".class
=> String
>> 'stayce'.class
=> String

You can use single or double quotes to encapsulate your new string. You can even use spaces, so long as your string begins and ends with quotes.

>> "My name is Stayce".class
=> String

Are you bored yet? Wanna learn a little more? First let's do a checkin to make sure I've explained myself. You should be learning that your mac has an interpreter called IRB. You can type commands in the Ruby programming language into it and it will return what you ask it in Ruby. Ruby has built-in classes, and when you give ruby an object it classifies your object into one of these built-in classes and tells you which kind, or else it throws an error. Integers are fixnums, decimals are floats, and text objects are called strings. Ruby uses these classification to know things about the objects in a class. In the same way we know all dogs can have four legs, fur, and bark; Ruby knows all strings can have letters, numbers, punctuation, and should retain capitalization and spacing, where as members of the fixnums or floats classes can be added together or multiplied because they are kinds of numbers.

So, pause for a moment and carve out a neural pathway for the terms Class and Object. Don't stop and google these terms. Make your own definitions based on your learning experience using the terminal. Remember and understand, even if it's a loose understanding that "Objects are members of a Class". Let's go on to lesson 2.

Lesson 2 - Methods

Classes have methods to go with them. That sentence probably means nothing to you so let's examine it in the terminal.

I'm going to make an object of my name, Stayce. Stayce is not a number, right? It's a string, so I need to put it in quotes. Remember when we typed:

>> "Stayce".class
=> String

That checked to see what class "Stayce" is. We asked what class by appending .class, and Ruby said it's a string. This time we know my name is a string, so let's use a string method on it. Strings have lots of methods built into Ruby. They all have names that are close to what they do. Let's try the length string method. This method tells you how many characters are in a string.

>> "Stayce".length
=> 6

My name is 6 characters long. I wonder how many characters are in my full name? What if I type my full name in between the quotes and then call the length method? Will Ruby count the space? Yes, it will. Spaces count as characters in Ruby. There's probably a method to count letters in Ruby, but I don't know it because there are at least a hundred string methods. Luckily you can look them up here: Class: String

Can you use a string method on another class? Remember the number 2 belongs to the fixnum class, and "stayce" belongs to the string class. What happens if you try to use a String Class Method like .length on a FixNum Class object like the number 2?

>> 2.length
NoMethodError: undefined method `length' for 2:Fixnum
from (irb):21

That's an easy error message to decipher right? Undefined method length for 2, a member of the Fixnum class. You probably didn't think that would work. We need to use Fixnum methods on objects from the Fixnum class. Find the length of characters in a number doesn't sound like a common problem, so it's not enabled by default. You could write your own method, or you could choose a Fixnum method to use instead that might do something more interesting. Let's look at a couple of number methods. There's 118 methods to choose from, but most of them involve math so it's kinda boring. Let's try to find a cool one...how about one with a question?

>> 7.even?
=> false

It's probably obvious i think what you are asking here.

>> 13.odd?
=> true

When you have a method that ends in a question, you are looking for something called a boolean response. Boolean means it can have one of only 2 values, usually written in english as true or false.

Let's get back to our silly question of how do you count the characters in a number if the .length method only works on strings? Well, you use a converter method to convert your fixnum to a string, then you can use the string method to count it.

>> 42.to_s.length
=> 2

The .to_s method works on objects in number classes like Fixnum and converts them to strings. Then we can use the .length string method to find out how many characters are in the string "42".

We could also put the number 42 in quotes before we call the string method length, to force the computer to treat 42 like a string instead of a fixnum.

>> "42".length
=> 2

One last thing to do with numbers. Let's change an integer to a float class. What if we have the number 23 but we want to store it as a decimal, like 23.0 so that it can be classified with all the other floats. We can convert it to a float using the fixednum method .to_f which stands for to float.

>> 23.to_f
=> 23.0
>> 23.0.class
=> Float

That's it. Not much to recap here. Find out what kind of class your object is by typing .class. Look up methods you can use on that class. Change the class of an object. Chain methods together and see them operated in order, like you did with this one 42.to_s.length.

Lesson 3 Variables

Remember variables from math class? Finding the value of x? Well, you don't need to find the value of anything right now. We're going to be setting the value of our variables in Ruby. Why would you use a variable? Well, sometimes it's shorter to call something by an acronym. In my silly example, I'll pretend I make a website for the California Dental Hygienists' Association. I don't want to type all that out all the time. I'll make a variable called cdha. I'll make it a string so I can store all the text with the capitals and spacing. To declare a variable, regardless of what type, just type what you want to call it, followed by the equals sign. You don't need quotes around the variable or the = sign. In my case I want to store the string California Dental Hygienists' Association, so I wrap my string in double quotes so Ruby is prepared to take classify my object as a string.

In the IRB prompt in your terminal type in a variable-- make up your own like >> name = "your name"

>> cdha = "California Dental Hygienists' Association"
=> "California Dental Hygienists' Association"

Now you can refer back to your variable with the short form.

>> cdha
=> "California Dental Hygienists' Association"

>> cdha.length
=> 41

>> cdha.class
=> String

You can also do operations on your variables like:

>> name = "Stayce Kavanaugh"
=> "Stayce Kavanaugh"

>> name
=> "Stayce Kavanaugh"

Maybe I want to add the string Hello to my name. I'll remember to include a space after the hello string.

>> "Hello " + name
=> "Hello Stayce Kavanaugh"

Remember name is a variable and not a new string. Ruby already knows what class name is, so you don't need to use quotes on your variable.

>> name.class
=> String

You can make as many variables as you like and store any data in there.

Monday, December 14, 2009

carniceria


So I am in Lexington, NC today. the barbeque capital of the world Or something like that. I'm here to visit my mom and my dog. My dog Saturday was a world traveller before he settled in with my mom 5 years ago. He's lived with us in LA, SF and NYC. Usually I visit a butcher shop, often a carniceria, to get a large cow bone for him for free or 50 cents. My local metropolitan butcher is usually happy just to get rid of the cow femurs and knuckles. So today, I thought it would be a cool idea to get some bones, some rice and some veggie pulp from the juicer and make him some dog food in the crock pot.

Turns out it's not so easy to find a butcher in the USA anymore. We went to the local butcher on Main St, and he attempted to sell us the standard made in china dog treat fare...buy one get one free. No bones there. So we went to the butcher at Wal-Mart. (now I could go on and on lamenting Wal=mart but not here and not now). Anyway, i asked a friendly octogenarian behind the counter if he had any bones. The poor old man looked shocked when I told him I wanted to boil the marrow and give it to my dog. He told me "honey, we ship all this meat on trucks...there's no bones here, just sliced meat." He looked incredibly sad while saying this of course. I pressed on asking about other local shops and he said there's nowhere left in town. He mentioned a shop in another city about a half hour away, but suggested I call ahead just in case.

So now I'm searching on google for my trusty local carniceria. I sure hope I find one. What a disappointment:(

(Photo of a meat can I saw in Spitalfields London, last year)

Friday, November 27, 2009

using jquery's wrapinner to wrap contents of links with spans to provide rounded corner button graphics

of course the easiest way to make buttons is to just use the cs3 rounded corners and let the ie6 users suffer with *gasp* right angles. But occasionally you find yourself in a situation where you need a liquid width graphical button. (my client has an affinity for reflections). I thought this technique would be as well documented as using jquery for sliding doors, but i couldn't find it anywhere so here you go.

in the CSS you can display your 3 graphics of the same height. a small left background graphic to apply to the span.lt, a long middle graphic for the span.mid, and the reverse of the left graphic for the span.rt.

Jquery:



$(document).ready(function(){
$("a.button_lnk").wrapInner("< span class='mid' >< /span >");
$("span.mid").before("< span class='lt' />");
$("span.mid").after("< span class='rt' />");
});


HTML before js



< div id="usernav" >
< a href="/login" class="button_lnk">login< /a >
< a href="/signup" class="button_lnk">signup< /a >
< /div >


HTML after js



< div id="usernav" >
< a class="button_lnk" href="/login" >
< span class="lt"/ >
< span class="mid" >login< /span >
< span class="rt"/ >
< /a >
< a class="button_lnk" href="/signup" >
< span class="lt"/ >
< span class="mid" >signup< /span >
< span class="rt"/ >
< /a >
< /div >

Tuesday, November 24, 2009

A service I couldn't live without as a freelancer

Combining Simply Invoices with the tick OSX widget is awesome. I just hit F12 and start my clock, then when I'm finished the data is printed to an invoice. Okay, so there's one step inbetween, but really it's simple. and best of all, it's free! If you want to manage multiple accounts you can a bit pay for an upgrade.

http://www.simplyinvoices.com
http://tickspot.com

Jquery Testimonial Rotator Script mod based on quotator

Here's some code for anyone who wants it. It's not yet cross-browser tested, at your own risk. I'll update this post in production.

quotator.js

// JavaScript Document
(function($){
$.fn.quotator = function(options){
var container = this;
var defaults =
{
speed : 11000,
json : "untitled.js"
}

var options = $.extend(defaults, options);

var quotes_json = options.json;
var quotes;

$.getJSON(quotes_json, function(data){
var quotesobject = eval(data.quotes);
var index = 0;


setInterval(changeQuote, options.speed);



container.html("
  • 'Fyera
    " + quotesobject[index].quote + "

    -- " + quotesobject[index].author + "

  • ");


    function changeQuote(){
    container.fadeOut(function(){
    container.html("
  • 'Fyera
    " + quotesobject[index].quote + "

    -- " + quotesobject[index].author + "

  • ").fadeIn();


    });

    if(index == quotesobject.length - 1){
    index = 0;
    } else{
    index++;
    }
    }

    });
    return container;
    }
    })(jQuery);

    ----------
    untitled.js
    --
    ({"quotes":
    [
    {
    "quote" : "The trouble with being in the public eye as a person known for inspiring and empowering others is, where do you go when you need inspiration and advice? Sheva taught me how to access the wisdom of my own heart for that. When you've graduated from personal growth training and want to find the real power in yourself, go to Sheva. She was there through the most difficult relationship challenge of my life, guiding me to a place of self respect where I am now receiving the love I truly deserve. She is without a doubt a leader to leaders, a coach to coaches, and an inspiration to all! I am so grateful to have met you Sheva, and to continue to work with you and to watch your magic unfold in the world!",
    "author" : "Bonnie St. John, Olympic Medalist, Author, Speaker Named by NBC as one of the five most inspiring women in the nation",
    "picture" : "http://fyera.goodbarry.com/Images/member_photos/bonnie_stjohn.jpg"
    },

    {
    "quote" : "The morning HeartStart calls are my “daily workout” that keep my heart skills sharp by applying and re-applying them as my week unfolds. The value of the important lessons I have gotten from Fyera and HearthMath are magnified 10 times through daily application. Better than any multi-vitamin and now that I have started it, I miss it dearly even if I skip one day.",
    "author" : "Malcolm Casselle, Entrepreneur with Successful Businesses in Asia and the United States",
    "picture" : "http://fyera.goodbarry.com/Images/member_photos/malcolm_casselle.jpg"
    },
    {
    "quote" : "HeartStart offers me a reliable daily structure that boosts and supports measurable physiological synchronization of my three brains – the head, heart and enteric brains - refreshing my commitment to my deepest heart-focused intensions and goals. Sheva offers inspiring, skillful presentations through Fyera’s HeartMastery’s year-long program, a plethora of consistently well-researched cutting edge materials that never fail to be enlivened by her brilliance, her extraordinary vitality, and her heart-focused wisdom and care. ",
    "author" : "Kiara Bahn, HeartMastery Member",
    "picture" : ""
    },
    {
    "quote" : "You, my dear Sheva, are a remarkable person who I\’m so glad to know, and look forward to knowing better and better, as I get better and better. You’ve taken me from the doldrums to believing, once again, life is an exciting adventure which I can hardly wait to take a bite of.",
    "author" : "Pat, Fyera HeartMastery Member",
    "picture" : ""
    },
    {
    "quote" : "In the short time I have been working with the Heart Math tools, I can say with all honesty- I have been profoundly changed. The changes are significant and deeply satisfying. Placing attention on my heart has been an elegant adventure into the realm of potential. I have touched undreamt of possibilities. Heart Math tools and distinctions have been instrumental in helping me cut through a lifetime of self imposed limitations- blockages to the realization and manifestation of all that lay waiting in latent potentiality. There are moments when my heart yields to exquisite joy. Sheva, you have been a perfect conduit of information and inspiration. Ah Fyera, ah- Today, as a result of the Heart Start exercise, I stepped into two of my deepest aspirations- to be a lover and a healer. From the deepest core of my heart, I say thank you, and thank you again.",
    "author" : "Eileen, HeartMastery Member",
    "picture" : "http://fyera.goodbarry.com/Images/member_photos/eileen_gold.jpg"
    },
    {
    "quote" : "If you've tried everything, Fyera! is not one more thing. It is THE thing that will make everything else you've tried work. ",
    "author" : " G.G., Filmmaker and Writer, Los Angeles",
    "picture" : ""
    },
    {
    "quote" : "I myself have witnessed the magic of Sheva\'s teaching... Millions of people from all walks of life are sure to benefit from the power of their hearts thanks to Sheva and Fyera! I am honored to be one of them. ",
    "author" : "Anne Marie Howard, Actress",
    "picture" : "http://www.annemariehoward.com/graphics/Anne_Marie_Howard_6006.jpg"
    }

    ]
    })



    ---------
    index.html
    ---





    Praise for and Faces of Fyera!





    ---


    A link to a demo, instructions, and downloadable files to follow. Please leave comments with questions and i will answer.