The Work of an Awesome Coder

by Steven Crighton on December 18, 2014 3 comments

Did you join the LiveCode Hour of Code? I did. Ok sure I was still on company time, so I was getting paid for it, but let me tell you – I am impressed with how awesome a coder I am.

Awesome coder – too much? I built the messages app and the user interface for the calculator app in 1 hour, that sounds to me like the work of an awesome coder.

Here’s the proof of my success with the Create it with LiveCode Hour of Code. Note – the below is not a screenshot directly from the iphone, it’s actually what I made in 1 hour! Seriously!

Here is the best thing about this demo and the Create it with LiveCode course – Everyone Can Do it. Everyone Can Be An Awesome Coder, Everyone Can Create Apps.

If you didn’t get a chance to catch the demo – it has been recorded and all the materials have been stored on the LiveCode hour of code page.

It’s a short blog post, but trust me, go check out the video, build these apps, get ahead of the game and if you can – get signed up to the Create it with LiveCode Course, it’s gonna be fun.

Happy Holidays Everyone

Steven Crighton

Digital Marketing Manager

Awesome Coder

read more
Steven CrightonThe Work of an Awesome Coder

Using git bisect to find a buggy commit

by Panagiotis Merakos on December 16, 2014 3 comments

During the last month I have been switching between translating the IDE to Greek, and refining LC 6.7 and 7.0 releases, in terms of fixing bugs. Some bugs are quite easy to fix. Some others though, can be quite tricky. The first thing to do is locate where the bug comes from, and the next step is to actually fix it. In some cases, tracking down the cause of the bug is not that obvious. However, if you can find a previous version of the code where the bug was not present, then you can use some Git tools to find the specific commit in the history which introduced the bug. You could try to check out each commit, build it, and check if the bug is present or not. Usually there are a large number of commits, so this can take a really long time. This is a linear search. Hopefully, we can do much better by doing a binary search.  This is where the git bisect command comes in.

What is git bisect?

Git bisect is an extremely useful command in the Git version control system. The bisect command does a binary search through your commit history to help you identify which commit introduced an issue. It is quite quick. Imagine that between a working version of the code and a buggy one, there are a few hundreds commits, say N. Using git bisect requires only log(N) steps!

How to use it?

1. You start by specifying two states, a bad and a good one. A state can be a commit hash, a branch name, or a tag name:


code1panos

In this example, HEAD is the current revision (ie the bad one), and 6.7.0-dp-6 is a tag of a good revision.

2. We then test it for the presence of the bug. We inform Git if the bug is there by running git bisect good, or git bisect bad:

code2panos

3. Repeating the same process bring us closer to the faulty commit:

codepanos3

4. If we ever arrive at a commit that won’t build for a known or irrelevant reason, or if we just don’t know if the specific revision is good or bad, then we simply run git bisect skip. It doesn’t define it as good or bad, picks a neighbor commit and moves on:

codepanos4

5. Voilà! We fould the commit that introduced the bug!

codepanos5

After finding the problematic commit, we can see the diffs in github, and find out the cause of the bug.

6. We then move back to the HEAD (git bisect reset) and fix the bug!

codepanos6

 

read more
Panagiotis MerakosUsing git bisect to find a buggy commit

A LiveCode Shell

by David Williams on December 10, 2014 5 comments

For some time, I have been wishing that I could have some kind of command-line oriented functionality to LiveCode, beyond writing scripts with LiveCode Server. What if I could pipe things directly to it, or run it as an interactive shell? Being able to very quickly make use of the text handling in LiveCode would be extremely handy for certain command line oriented types of tasks. Alas, this is not possible with LiveCode or LiveCode Server as it currently stands. However, after some thought, I concluded that it should be possible to put together a script to provide this functionality.

2014-12-10 11_55_44-MTPuTTY (Multi-Tabbed PuTTY)

Click to Zoom

After some time, I had produced a script which operates as a simple shell type interface. But how does it work? It’s actually fairly simple. The script is a LiveCode Server script, designed to be invoked via command line. When it starts up, it reads in the options passed to it on the command line to determine how it should behave. The options passed to it are in the $x variables, starting at $0. $# tells us how many were passed.

#!/usr/local/bin/livecode-server
## substitute this with the path to your livecode server executable

## array for storing the options passed to this program
local sOpts

## load options
repeat with x = 0 to ($# – 1)
       do “put $” & x && “into tReadOpt”
       if char 1 of tReadOpt is “-” then
              repeat with y = 2 to the number of chars in tReadOpt
                       put char y of tReadOpt into sOpts[(the number of lines in the keys of sOpts + 1)]
               end repeat
       else
            put tReadOpt into sOpts[(the number of lines in the keys of sOpts + 1)]
      end if
end repeat

 There are currently two modes: interactive and execute. We can also pass the -p option to tell it to expect data to be piped to it, and read it into a variable called ‘input’. If we pass it the -e option it starts up in execute mode, and expects you to have specified a command for it to run. It then exits after running the command. Usage for this would be like “lcsh -e ‘put hello world’”. Otherwise, it starts up in interactive mode.

## read from pipe
if optEnabled(“p”) then
       read from stdin until EOF
       put it into input
end if

## get command from last command line option and execute it, then quit
if optEnabled(“e”) then
       do sOpts[(the number of lines in the keys of sOpts)]
       put return
       quit
end if

## interactive mode
repeat
       put “lcsh[” & the folder & “]# “
       read from stdin for 1 line
       put it into tCommand
      if isCommand(tCommand) then
               put shell(tCommand)
      else
              try
                       do tCommand
               catch pError
                      put “Error:” & return
                      put pError
               end try
       end if
     put return
end repeat 

Execute mode simply takes the last command line option and uses do on it, then quits. Interactive mode reads 1 line from stdin at a time (i.e. it reads 1 typed line by the user at a time) and then determines what should be done with it. It uses the isCommand function to check the $PATH environment variable (which contains all of the directories which should be looked in for executable programs) to see if what was entered was a utility that is already installed, such as the standard Linux utilities. If it was, it uses shell() to execute the entered command. Otherwise, it uses the do command to execute it as normal LiveCode code, catching any generated errors so that they can be displayed without causing the program to exit:

## checks to see if the first word is a command in $PATH
function isCommand pCommand
       set the itemDel to “:”
       put the folder into tFolder
       put false into tIsCommand
       repeat for each item tDir in $PATH
               set the folder to tDir
               if word 1 of pCommand is among the lines of the files then put true into tIsCommand
       end repeat
       set the folder to tFolder
       return tIsCommand
end isCommand

There is also the optEnabled function that was referenced above. This checks to see if the program was loaded with a specific option enabled:

function optEnabled pOpt
       repeat for each key tKey in sOpts
               if sOpts[tKey] is pOpt then return true
       end repeat
       return false
end optEnabled

 This is quite clunky and has many, many problems – for example, there’s no ability to pipe the output of some LiveCode to another program in interactive mode, and you can’t open another program that requires interaction. However, I think that with a lot more work, this could become quite a robust and useful tool. It already provides some very handy functionality in it’s current state, namely that I can pipe to it for text parsing:

2014-12-10 12_44_57-MTPuTTY (Multi-Tabbed PuTTY)

Click to Zoom

I will probably keep chipping away at this until I can use it as my primary command line interface. You can get the full code here: http://jasminedavid.on-rev.com/lcsh.txt

 

read more
David WilliamsA LiveCode Shell

Have Your Eureka Moment with LiveCode

by Kevin Miller on December 5, 2014 4 comments

Editors note: Kevin sent a personal letter to the community today, and after reading it I asked permission to reprint it here. He agreed 🙂

As the CEO and custodian of LiveCode I believe passionately in a world where everyone can create apps. We’ve worked hard on finding ways to empower more of you to be able to build the app of your dreams. We’ve enjoyed a great deal of success over the years, doubling the interest and uptake of computer science courses wherever we’ve been adopted, and helping to transform many budding new coders into entrepreneurs running businesses small and large. I’d like to express a heartfelt thank you for your support over the years, not least with our hugely successful crowd funding campaigns and open source initiative. We couldn’t have done it without you.

We know LiveCode is the easiest, most productive way to build an app. But if I’m honest, we’ve always found it challenging to get a new user over the initial learning curve. After all, even the English-based LiveCode language still has vocabulary and concepts that need to be understood. And as easy as it is, like learning anything worthwhile – whether a language, an instrument or a sport, it requires some effort.

As CEO I’ve come to be very familiar with a pattern. A new user starts using our platform. For the first few days they orientate themselves. Ask a lot of questions. Scratch their heads. A few more days in and something clicks. The lightbulb moment occurs. We know, from all sorts of feedback from tens of thousands of users, that once you “get it”, once you get over that initial hump and have your “aha” moment, you never look back. You love LiveCode. You discover new horizons and are able to create things you never thought you could. The problem we’ve encountered has been that far too many people don’t make it through those first few days. Until now.

We’ve been searching for the right path for you, our audience, to get quickly and easily into coding with LiveCode and creating apps. We’ve tried a number of different approaches, with varying success. We’ve created academies, we’ve run summer schools, we’ve got involved with the Hour of Code initiative. Each has been successful to an extent, but we’ve been searching for ways to make it even easier.

That’s why I’m so very excited about our new Create it with LiveCode Course. 

Why is this course so different? Well firstly, it’s results based. You don’t learn theory, you learn to do a specific thing, and then start to gain understanding on how and why it worked like that. Secondly, it’s focused on modern mobile apps. You’ll learn transferable skills (that you can apply to the desktop and server too) but the focus is squarely on mobile. Thirdly, you’re learning to build apps that you already know. We’ll show you how to create perfect replicas of the apps that already ship on your phone. That way you’ll know when you’ve got it right. You’ll know how to do everything you need to do to create a successful app, such as access all the sensors on a device. If you can build these apps – the same ones the pro’s build – you’ll be able to build anything. Fourthly, we reveal one of the best kept secrets of the LiveCode environment – how to use it to seamlessly integrate cloud with your apps in a way no other language can approach. Next, we focus on not just the process of building an app but also everything else you need to know about the apps business, doing market research, promotion and marketing.

But most importantly of all, the thing that really convinced me, that made me go wow, yes, I have to get this course into the hands of potential coders everywhere, is the proven results. I saw the figures. 93% of students who took this course, were able to build their app at the end of it. And these were students with absolutely no past experience whatsoever. Impressive validation. If you go through this course, and put in the work and the hours, you will be able to build your app. We’re so confident of that we guarantee it. If you follow the course and can’t build the app you want at the end we’ll give you your money back. It’s as simple as that.

If you want to read more about the story of how this course came about, check out my blog post here.

Ways to Get Involved

This is far more than just a new course, its a massive opportunity to take the next step in delivering on our vision that everyone can create apps. If you believe in that vision then I’d like to ask for your support. Whether you’re just starting out or you’re an existing power user, there are so many ways to get involved. Here are some of the top ones.

Hour of Code

As you may be aware, the 8th to the 14th of December is CS Education Week. There’s been a lot of talk over the last year or so about the “Hour of Code” initiative. The world has woken up to what we’ve known all along – that coding is the new literacy, that everyone should be able to do it. We’ll be participating in the hour of code by making available the very first week of our Create it Course for free.

You can take part in the live webinar on the 11th of December at 10AM PST. 

Bring your relatives, bring your friends, bring your neighbors, bring your taxi driver, bring anyone else you can!

We’re excited about the Hour of Code but we know that while an hour is a great starting point, it isn’t enough by itself. The Create it Course is a great next step. We bridge the gap between that initial hour and becoming a professional coder. Learn more about the course here

Affiliate Program – Spread the Word!

If you’re an existing LiveCoder who would like to help spread the word, we’ve set up an affiliate program so you can support our vision and get rewarded. We invite you to evangelize LiveCode and the Create it Course. You can earn 25% of every sale you make to a  new LiveCoder. Feature the platform you know and love on your website, get posters you can put in shop windows, get a QR code to pass out, and earn credit every time someone signs up as a result. Email us at support@livecode.com to get started!

The Perfect Gift

For the first time ever, we invite you to give the gift of a new skill that will last a lifetime this Christmas. The Create it Course is battle tested on people with only basic computer skills, and no coding at all. This course is suitable for anyone aged 13+. This is a real opportunity to spread the deep digital literacy you’ve grown to know and love with LiveCode to someone else, a son or daughter, a grandparent or friend, anyone you think would appreciate it.

Not only do we cover everything you need to build apps but we’re bringing in business experts to walk you through the process of building a successful business around an app. Plus we have a great contest with prizes that include exposure for your app and a trip to the LiveCode World Conference in 2015. 

As a reward back to you we invite you to take the course yourself for free. This means you have a fantastic opportunity to mentor your nominee, and help them through their LiveCode journey. To give Create it with LiveCode as a gift, check the “this is a gift” box next to the purchase button, hereWe’ll send you a gift certificate you can print and instructions for full access to the course.

We hope you’ll get involved. Sign up now to get the first lesson in this course free and participate in Hour of Code next week. Give the course as a gift. Sign up as an affiliate. Or get the course if you haven’t already. Remember places are limited.

Thanks so much for all your support. 

Kind Regards,

Kevin Miller

LiveCode CEO  

read more
Kevin MillerHave Your Eureka Moment with LiveCode

From Fibonacci to Dr Seuss

by Hanson Schmidt-Cornelius on December 4, 2014 1 comment


blog-text

If you were a Kool-Aid kid then chance has it you are familiar with Dr Seuss and the bizarre, illogical language he uses in his books. What a wonderful mind that can think outside of the box in such a beautifully unconventional, educational and humorous fashion. How could one possibly dream up sentences like: “One fish two fish red fish blue fish…”? Especially as this is not your typical every day level of conversation. 

In this blog I demonstrate how computers can assist us in constructing sentences with similarly bizarre meanings. 

 As hardware has become more powerful and the algorithms explored have become more advanced, computers have been shown to mimic limited reasoning abilities that are most often associated with intelligent beings. I know I am touching on a controversial area here, and I am steering clear of suggestions of artificial intelligence or artificial self-awareness. I make a short reference to the Turing Test here, for the interested reader. This test assesses if a computer can convincingly mimic or simulate the communicative responses of a human being. 

It would takes a bit more effort to implement an algorithm that is worthy of being entered into a Turing Test than we can cover here, but we will be looking at one computational aspect that may well be part of a larger solution. 

If you read our blogs on a regular basis you will know that we have touched on different ways of implementing number sequence generators in blog “Recursion for Runaways“. We are building on the concepts outlined there to create a Natural Language Sentence Generator. 

Before we can get our hands dirty with a bit of LiveCode, we need to take a step back and understand some of the basics that underlie the English language. 

If you are starting to get a déjà vu experience of some long forgotten classes at school, do not worry. We are only scratching the surface of the topics involved, leaving you to explore the relevant fields in more depth at your leisure.  

According to the global language monitor, the English language passed the 1 Million Word mark on June 10, 2009 with 14.7 new words being added every day. Our application is not going to utilize all of these words, in fact we are only going to use a very small subset of these words to build our Natural Language Generator. But in order to utilize any number of words we need to understand how groups of words are arranged in the English language. 

There are eight “Parts of Speech” in the English language that are used to group kinds of words together. These parts are: articles, nouns, adjectives, verbs, adverbs, prepositions, pronouns, conjunctions and interjections. The order by which these “Parts of Speech” are arranged in sentences is determined by rules. For example, a very basic sentence can consist of an article, a noun and a verb, arranged in that order: 

   “A man walks.” 

or 

   “The cat sleeps.” 

 By interchanging the articles, nouns and verbs you can create a large arrangement of sentences with different meanings. From a coding point of view we may store the words in some kind of storage mechanism, for example variables: 

    article = “A,The” 

   noun = “man,cat” 

   verb = “walks,sleeps”  

This could form part of a word database that may allow us to create the two sentences shown, but it would also allow you to create further new sentences, for example: 

   “The man sleeps.” 

   “The cat walks.” 

   “A cat walks.” 

In order to build the English Language Generator we use a database of words, similar to the ones used in the examples shown here. Randomly picking words from the “Part of Speech” entries and placing them in the “article, noun, verb” order is then a perfectly workable approach, but this arrangement would limit our expressive creativity somewhat and probably be quite boring after a while. What we need is some formalism or grammar that allows us to present and order the words in a more flexible fashion. This would allow us to only make changes to the grammar in order to control how the words are ordered. 

We use an array as a database for both the words and the grammar rules and call this database “DCG”:  

    local DCG 

We then add the rule to the database that we used to create the aforementioned sentences:  

   put “-art -n -v” into DCG[“-s”] 

 The tokens are “-art” (article), “-n” (noun) and “-v” (verb) for a sentence “-s”.  

Next we populate the database with words. This time we add a few more words, giving us a bit more freedom to create sentences: 

 

put “the,a” into DCG[“-art”]

 put “man,woman,child,cat,dog,pie” into DCG[“-n”]

 put “walks,eats,combs,cooks” into DCG[“-v”]

Using our rule and understanding of how basic sentences are constructed in the English language, we can now create sentences like the ones we have already discussed. With the word database shown here, and the basic sentence rule, we can create a total of 48 unique sentences. 

Now let us look at how LiveCode can take this kind of database and convert the content into sentences: 

   function evaluateSegment pSegment 

      repeat for each word tItem in pSegment 

         if tItem begins with “-” then 

            put evaluateSegment (item random(the number of items in DCG[tItem]) of DCG[tItem]) after tResult 

         else 

            put tItem & space after tResult 

        end if 

     end repeat 

     return tResult 

   end evaluateSegment 

 Yes, that is it. These ten lines of code are our English Language Generator. It processes the database and randomly selects words to create sentences that are grammatically correct, based on the grammar rules we presented. If you look closely you can see that this function is recursive. The recursive design allows us to create this compact implementation. It also gives us powerful means by which a more complex grammar can be interpreted and processed. 

 You can put this generator together by creating a button and adding the following code to the button script: 

local DCG  

on mouseUp 

   // Grammar Rules 

   put “-art -n -v” into DCG[“-s”] 

   // Word Database 

   put “the,a” into DCG[“-art”] 

   put “man,woman,child,cat,dog,pie” into DCG[“-n”] 

   put “walks,eats,combs,cooks” into DCG[“-v”] 

   // Create Sentence 

   put evaluateSegment (“-s”) 

end mouseUp 

function evaluateSegment pSegment 

   repeat for each word tItem in pSegment 

      if tItem begins with “-” then 

         put evaluateSegment (item random(the number of items in DCG[tItem]) of DCG[tItem]) after tResult 

      else 

         put tItem & space after tResult 

      end if 

   end repeat 

   return tResult 

end evaluateSegment 

This script creates the database each time you hit the button, allowing you to update the entries and apply them for each run. This code opens the message box and displays a sentence. 

Okay nice, we can randomly create sentences, but as you can see, this blog has not quite reached the end yet. Let us now move on to creating sentences with a bit more complexity and start to utilize the recursive nature of the “evaluateSegment” function. 

In order to update your code and implement the following changes you only have to replace the code in the // Grammar Rules and // Word Database sections of your “mouseUp” handler.  

First we update the // Grammar Rules and add the concept of a “noun phrase” (-np):  

   put “-np -v” into DCG[“-s”] 

   put “-art -n” into DCG[“-np”] 

 Fundamentally, this logic generates exactly the same sentences as with the rule we used earlier. The “-art -n” part of the sentence rule has been replace with a “noun phrase” part that itself defines “-art -n”. This means that “evaluateSegment” has to complete the “-np” rule before it can complete the “-s” rule. 

Now why are we creating something more complicated when the simple sentence rule was sufficient? 

Well, this new representation allows us to expand the grammar even further. We can now also add a “verb phrase” (-vp) to our grammar replacing the // Grammar Rules with the following syntax: 

   put “-np -vp” into DCG[“-s”] 

   put “-art -n” into DCG[“-np”] 

   put “-v -np,-v” into DCG[“-vp”] 

 A “verb phrase” can be a verb, as with our original grammar, but it can now also be a verb and a “noun phrase”, which in turn is an article, followed by noun. So what kind of sentences does this new grammar give us? It produces the same sentences as before but can also generate more complex sentences, such as:  

   “A man walks a dog.” 

or 

    “The child eats a pie.” 

We are now getting to a point where the grammar can use different numbers of words to construct English sentences. That is where recursion is in its element. 

This is progress, but let us look at even more complex constructs that can create sentences with thousands of words. – Meet “conjunctions”. Conjunctions are words that bind sentences together.  

For the next step we update the grammar rules again and also add some more words to our word database. Let us start with the // Grammar Rules first and replace them with: 

   put “-np -vp,-s -conj -s” into DCG[“-s”] 

   put “-art -n” into DCG[“-np”] 

   put “-v -np,-v” into DCG[“-vp”] 

Essentially we are now allowing sentences to be constructed as before, but we are also creating sentences that are joined by a conjunction.  

The // Word Database is updated by adding the following words as conjunctions: 

    put “and,or,but,so,because,although” into DCG[“-conj”] 

We now have a grammar that has the potential to generate massive sentences. This is because the grammar can join an arbitrary number of sentences through conjunctions. 

So what can we expect to be generated after this update? 

We can expect sentences like the following: 

   “A man eats the pie because the dog cooks.” 

   “A cat cooks so the woman eats.” 

Now these make sense to a degree but may not reflect everyday situations. We can also expect a lot of very different sentences with varying lengths that are total gibberish. In fact I have generated sentences that are several times longer than this blog post and at times even hit the recursion limit. It is natural that we sometimes hit that limit as we do not set any restriction on the length of sentence that can be generated. 

You will probably find that only a very few of the sentence generated make any sense at all. So have we created an English Language Generator or is this maybe more a “Dr Seuss quote generator”? 

Seeing how easy it is to string words together in a grammatically concise way is nice, but adding meaning to what they represent is maybe a skill best left to those with a unique awareness and understanding of themselves and the environment they live in, or as René Descartes may have put it: “Cogito ergo sum”. 

The English grammar is certainly more complex than I let on in this blog, but you now have a basic LiveCode framework to build a language generator with a lot more complex grammatical constructs. Try expanding the word database and the grammar rules to update and create your own language generator. If you are a linguist or know other languages, why not see if you can get some meaning out of this code in a different language.

read more
Hanson Schmidt-CorneliusFrom Fibonacci to Dr Seuss