Showing posts with label computer programming. Show all posts
Showing posts with label computer programming. Show all posts

Thursday, September 18, 2014

Functional Programming and Math, What you need to know

Functional programming can be better understood if one understands functional composition concepts that are often taught in precalculus and college algebra. A mathematical functional composition problem requires at least two functions. In a two function problem, the result obtained from evaluating one function is substituted into the dependent variable of another function to obtain the final output. 

For example,  given the two functions

f(x) = x + 2 

g(x) = 3x 

find the composition of g(f(2)) means to first evaluate f(2) and then substitute that value into x of g(x) to obtain the final result. 

Since f(2) = 2 + 2 = 4

Substituting 4 into x in the g(x) equation yields

g(4) = 3*4 = 12 

so g(f(2)) = 12 

Functional composition can be extended to 3 or as many functions as you like. Simply take the output of the function and feed it into the independent variable of another function. Then take that output and feed it into another function. 

Functional programming works along the same math based mindset. Functional programming takes an output of a function, such as a JavaScript function and feeds it  into another function You can chain together as many JavaScript functions as you like.  

Other concepts such as recursion also come into play in functional programming. Recursion, is slightly different than functional composition. Instead of feeding the output of the function into the independent variable of another function, you feed the output of one function back into the independent variable of  the same function. 

Posted By: Mark Stansberry, www.bookmarktutorin.com on Sept 18 2014

BookMarkTutoring.com offers onSite, onCall, onLine and inPerson tutoring in math, science, computer programming and graphic design.  





Sunday, March 30, 2014

Extracting Links with Ruby String Methods: index, rindex

Extracting links from web pages (often known as data harvesting or web scraping)  is an easy task with Ruby's string methods. With the index and rindex string methods, the position of the first delimiter and the last delimiter in a line of html code can be found with just two lines of code. Many links within html source code begin and end with a double quote character(").  This makes the double quote character the ideal delimiter to locate when attempting to extract a link. Using the index method to find the position of the first double quote character and the rindex method to find the position of the  last double quote character, one can then use the range method to extract the complete link.


Identifying the Link to Extract 

In this code example, the goal is to extract the link from the following string within an html file:

for background information visit <a href="http://www.linkedin.com/pub/mark- stansberry/60/828/826">linkedin page</a><br />

The link we want, http://www.linkedin.com/pub/mark- stansberry/60/828/826, is delimited with two double quotes.

The code used to find the positions of the first double quote character and the last double quote character is given below. Note, that we assign the string from which the link is extracted to the string variable, a.


The Code: File name: strings_lesson.rb

a = 'for background information visit <a href="http://www.linkedin.com/pub/mark- stansberry/60/828/826">linkedin page</a><br />'


#finding the position of the first occurrence of a quote symbol

puts "The first quote in the string variable, a, is at postion #{a.index('"')}"

#But what about the last quote(") position. for that we use the rindex string method

puts "The last quote in the string variable, a,  is at postion #{a.rindex('"')}"        


Output from the Code

The first quote in the string variable, a, is at position 41
The last quote in the string variable, a, is at position 97

The Next Step 

Now that the positions of the first and last double quote characters is known, that information can be used with Ruby's In the next lesson, the code to actually extract and store the link is given. This code uses Ruby's powerful  substring extraction methods. Ruby's substring extraction methods. These methods require as parameters the starting position and the ending position of the substring delimiters in order to extract the substring.

Error Messages 

Running the code, requires that you cut and paste the above code into a file with the Ruby extension, .rb and then run the program. If for some reason you are obtaining errors, feel free to comment on this blog. The code has been tested (actually cut and pasted from the blog) and runs correctly.


References

String: http://www.ruby-doc.org/core-2.1.0/String.html

Tuesday, November 19, 2013

Ruby on Rails, Web Application Project Development Tutorial

Ruby on Rails Tutorial - Part 1, Setting Up a Rails Web Application Project

Written By: Mark Stansberry, BookMark Tutoring
Email: mark.c.stansberry@gmail.com
Cell/Text: (707)235-4095


After you have installed rails, the next step is to create a Rails project directory and generate the files needed to generate the framework of your web database application.  You must first decide on a name for your Rails project and the project directory that it is located in.

For this Rails web database application the project name, "myapp" was chosen and the directory for the Rails project was chosen to be C:\Users\mark.c.stansberry

After opening up the "Start Command Prompt" window on your windows desktop, you must execute the command "rails new myapp" at the file directory location. For this example, the command below was entered in at the command line prompt to generate the Rails web database framework for the myapp application

C:\Users\mark.c.stansberry>rails new myapp

After pressing enter on the keyboard, the command line editor displays the commands it executes in order to construct the myapp web database application framework.


      create
      create  README.rdoc
      create  Rakefile
      create  config.ru
      create  .gitignore
      create  Gemfile
      create  app
      create  app/assets/javascripts/application.
      create  app/assets/stylesheets/application.
      create  app/controllers/application_control
      create  app/helpers/application_helper.rb
      create  app/views/layouts/application.html.
      create  app/assets/images/.keep
      create  app/mailers/.keep
      create  app/models/.keep
      create  app/controllers/concerns/.keep
      create  app/models/concerns/.keep
      create  bin
      create  bin/bundle
      create  bin/rails
      create  bin/rake
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/backtrace_silen
      create  config/initializers/filter_paramete
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/secret_token.rb
      create  config/initializers/session_store.r
      create  config/initializers/wrap_parameters
      create  config/locales
      create  config/locales/en.yml
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  lib
      create  lib/tasks
      create  lib/tasks/.keep
      create  lib/assets
      create  lib/assets/.keep
      create  log
      create  log/.keep
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/favicon.ico
      create  public/robots.txt
      create  test/fixtures
      create  test/fixtures/.keep
      create  test/controllers
      create  test/controllers/.keep
      create  test/mailers
      create  test/mailers/.keep
      create  test/models
      create  test/models/.keep
      create  test/helpers
      create  test/helpers/.keep
      create  test/integration
      create  test/integration/.keep
      create  test/test_helper.rb
      create  tmp/cache
      create  tmp/cache/assets
      create  vendor/assets/javascripts
      create  vendor/assets/javascripts/.keep
      create  vendor/assets/stylesheets
      create  vendor/assets/stylesheets/.keep
         run  bundle install

Most of the commands that are executed when the rails new myapp command is entered are used to create files and associated directory locations to store those files for the framework. These include configuration files, test, library, and database files.

The last command that is executed is the "run bundle install" command. The bundle command is used continually for the build and rebuilding of your web framework application.

About the author: Mark Stansberry teaches Ruby and Ruby-on-Rails for BookMarkTutoring.com. He has over 15 years in technology training, technical writing and code development. Besides teaching at BookMark, Mark is responsible for the development of BookMark's online learning productivity tools. Mark's current application programming interests include  parametric and fractal based graphic design automation, cloud computing and biological system simulation.

Email: mark.c.stansberry@gmail.com

Thursday, September 5, 2013

Flash ActionScript Code Reference Page, Library Learning Links

Mark Stansberry's

Flash ActionScript Code Reference Page

A Reference Guide to Publications and Code Written by Mark Stansberry for Demand Studios (Ehow)

Sponsored By

The Very Best Algebra Notes

The Very Best Algebra Notes for the Very Best Flash Games

For online Flash tutoring contact mark.c.stansberry@gmail.com

You are at
http://www.3d-perspective-software-development.com/Ehow AS3 Article Links.html