Monday, October 21, 2019

OptionParser Command-Line Options the Ruby Way

OptionParser Command-Line Options the Ruby Way Ruby comes equipped with a powerful and flexible tool to parse command-line options, OptionParser. Once you learn how to use this, youll never go back to looking through ARGV manually. OptionParser has a number of features that make it quite appealing to Ruby programmers. If youve ever parsed options by hand in Ruby or C, or with the getoptlong C function, youll see how welcome some of these changes are. OptionParser is DRY. You only have to write the command-line switch, its arguments, the code to run when its encountered, and the command-line switch description once in your script. OptionParser will automatically generate help screens for you from this description, as well as infer everything about the argument from its description. For example, it will know the file [FILE] option is optional and takes a single argument. Also, it will know that [-no]-verbose is really two options and will accept both forms.OptionParser will automatically convert options to a specific class. If the option takes an integer, it can convert any string passed on the command-line to an integer. This cuts down on some of the tedium involved in parsing command-line options.Everything is very contained. All of the options are in the same place, and the effect of the option is right along-side the definition for the option. If options have to be added, changed or someone simply wants to see what they do, the re is only one place to look. Once the command-line is parsed, a single Hash or OpenStruct will hold the results. Enough Already, Show Me Some Code So heres a simple example of how to use OptionParser. It doesnt use any of the advanced features, just the basics. There are three options, and one of them takes a parameter. All of the options are mandatory. There are the -v/verbose and -q/quick options, as well as the -l/logfile FILE option. Additionally, the script takes a list of files independent of the options. #!/usr/bin/env ruby # A script that will pretend to resize a number of images require optparse # This hash will hold all of the options # parsed from the command-line by # OptionParser. options {} optparse OptionParser.new do|opts|   Ã‚  # Set a banner, displayed at the top   Ã‚  # of the help screen.   Ã‚  opts.banner Usage: optparse1.rb [options] file1 file2 ...   Ã‚  # Define the options, and what they do   Ã‚  options[:verbose] false   Ã‚  opts.on( -v, verbose, Output more information ) do   Ã‚  Ã‚  Ã‚  options[:verbose] true   Ã‚  end   Ã‚  options[:quick] false   Ã‚  opts.on( -q, quick, Perform the task quickly ) do   Ã‚  Ã‚  Ã‚  options[:quick] true   Ã‚  end   Ã‚  options[:logfile] nil   Ã‚  opts.on( -l, logfile FILE, Write log to FILE ) do|file|   Ã‚  Ã‚  Ã‚  options[:logfile] file   Ã‚  end   Ã‚  # This displays the help screen, all programs are   Ã‚  # assumed to have this option.   Ã‚  opts.on( -h, help, Display this s creen ) do   Ã‚  Ã‚  Ã‚  puts opts   Ã‚  Ã‚  Ã‚  exit   Ã‚  end end # Parse the command-line. Remember there are two forms # of the parse method. The parse method simply parses # ARGV, while the parse! method parses ARGV and removes # any options found there, as well as any parameters for # the options. Whats left is the list of files to resize. optparse.parse! puts Being verbose if options[:verbose] puts Being quick if options[:quick] puts Logging to file #{options[:logfile]} if options[:logfile] ARGV.each do|f|   Ã‚  puts Resizing image #{f}...   Ã‚  sleep 0.5 end Examining the Code To start off with, the optparse library is required. Remember, this isnt a gem. It comes with Ruby, so theres no need to install a gem or require rubygems before optparse. There are two interesting objects in this script. The first is options, declared at the top-most scope. Its a simple empty hash. When options are defined, they write their default values to this hash. For example, the default behavior is for this script to not be verbose, so options[:verbose] is set to false. When options are encountered on the command-line, theyll change the values in options to reflect their effect. For example, when -v/verbose is encountered, it will assign true to options[:verbose]. The second interesting object is optparse. This is the OptionParser object itself. When you construct this object, you pass it a block. This block is run during construction and will build a list of options in internal data structures, and get ready to parse everything. Its in this block that all the magic happens. You define all the options here. Defining Options Each option follows the same pattern. You first write the default value into the hash. This will happen as soon as the OptionParser is constructed. Next, you call the on method, which defines the option itself. There are several forms of this method, but only one is used here. The other forms allow you to define automatic type conversions and sets of values an option is restricted to. The three arguments used here are the short form, long form, and description of the option. The on method will infer a number of things from the long form. One thing is will infer is the presence of any parameters. If there are any parameters present on the option, it will pass them as parameters to the block. If the option is encountered on the command-line, the block passed to the on method is run. Here, the blocks dont do much, they just set values in the options hash. More could be done, such as checking that a file referred to exists, etc. If there are any errors, exceptions can be thrown from these blocks. Finally, the command-line is parsed. This happens by calling the parse! method on an OptionParser object. There are actually two forms of this method, parse and parse!. As the version with the exclamation point implies, it is destructive. Not only does it parse the command-line, but it will remove any options found from ARGV. This is an important thing, it will leave only the list of files supplied after the options in ARGV.

Sunday, October 20, 2019

How to Be Imprecise or Use Vague Expressions for ESL

How to Be Imprecise or Use Vague Expressions for ESL There are a number of ways to give imprecise information in English. Here are some of the most common: There are about 600 people working in this company.There are approximately 600 people working in this company.There are a large number of students interested in taking his course.Its  almost  impossible to get tickets for the concert.Management predicts up to 50% growth for the coming year.Its kind of a bottle opener which can also be used to peel vegetables.Its the type of place you can go to relax for a week or so.Theyre the sort of people that like going bowling on Saturday evenings.Its difficult to say, but Id guess that its used for cleaning house.Im not really sure, but I think they enjoy hiking in the mountains. Construction Formula Form There are about 600 people working in this company.I have almost 200 friends in New York. Use about + a numbered expression.Use almost + a numbered expression There are approximately 600 people working in this company. Use approximately + a numbered expression. There are a large number of students interested in taking his course. Use a large number of + a noun. Management predicts up to 50% growth for the coming year. Use up to + a noun. Its kind of a bottle opener which can also be used to peel vegetables. Use kind of + a noun. Its the type of place you can go to relax for a week or so. Use type of + a noun. Use or so at the end of a sentence to express the meaning approximately. Theyre the sort of people that like going bowling on Saturday evenings. Use sort of + a noun. Its difficult to say, but Id guess that its used for cleaning house. Use the phrase + Its difficult to say, but Id guess an independent clause. Being Imprecise Dialogue Mark: Hi, Anna. Can I ask you a few questions for a survey Im doing in class?Anna: Sure, what would you like to know? Mark: Thanks, to begin with how many students are at your university?Anna: Well, I cant be exact. Id say there are about 5,000 students. Mark: Thats close enough for me. What about classes? How large is the average class?Anna: Thats really hard to say. Some courses have a large number of students, others not so many. Mark: Could you give me an estimate?Anna: Id there are approximately 60 students in most classes. Mark: Great. How would you describe your university?Anna: Once again, theres no clear cut answer. Its the kind of place students choose if they want to study non-traditional subjects.   Mark: So, youd say students are not what youd find at other schools.Anna: It has the sort of students that arent exactly sure what they want to do in the future.   Mark: Why did you choose to attend your university?Anna: Its difficult to say, but Id guess it was because I wanted to stay close to home.   Mark: Thanks for asking my questions!Anna: My pleasure. Im sorry I couldnt give you more exact answers.

Saturday, October 19, 2019

Internship Plan Journal Entry Assignment Example | Topics and Well Written Essays - 250 words

Internship Plan Journal Entry - Assignment Example The first goal is to analyze sales and report the findings. Specifically, I was to understand the market trends. The two actions that I did are visiting other companies to collect data. I also did research on other companies sales. This goal was accomplished by the end of the week, 30th January 2015. The purpose of this goal was to understand how analysis of sales data is utilized to comprehend market trends. I measured my progress by first analyzing the sales data that has been collected. The second goal that I purposed to accomplish is to gather and interpret customer feedback.Specifically,I was to understand the customer trends. The two actions that I did were collection of the customer’s feedback on suggestion box and also did a research on the customers. The purpose of this goal is to contribute to consumer insight initiative within the organization. This goal will enable me to develop my skills in gathering and interpreting customer feedback. I look forward to taking this next step as I finish up with my training in sales data analysis. The set time frame for achieving this goal is the second week of February that is from 4/2/2015. My third goal entails conducting primary research for the organization’s products. Specifically, I did analyzed the effectiveness and usability of the company’s product. The two actions that I did involved researching on products sales and also questioning the customers. The purpose of accomplishing this goal is to enhance my comprehension and skills involving product research. I can easily measure this goal because I will be able to perform the specific task by the end of my training. This goal is attainable as I have already had exposure in conducting market research for the company. This is a realistic goal because I have the support and expertise of my co-workers coupled with the support of my supervisor. The timeframe of achieving

Friday, October 18, 2019

The war Essay Example | Topics and Well Written Essays - 750 words

The war - Essay Example The period between the first gulf war in 1990s and the second in early 2000 has witnessed many changes in the military. The changes include application of more advanced technology and overhaul of tactical approaches, transformations that have achieved mixed results. This paper discusses the benefits and drawbacks of applying United States’ advanced military technology in Iraq and Afghanistan. The war in Afghanistan is one of the major United States military offensives aimed at destroying the terrorists’ hideouts that had inflicted heavy damages on American interest around the globe. Iraq war was launched to overthrow the regime of Saddam Hussein accused by the government of possessing weapons of mass destruction with intention of using them to spread terror. Both wars were executed with highly sophisticated weapons that allowed the United States forces to demolish the enemy defenses with high precision aerial weaponry and at unprecedented rate. The quick demolition and annihilation of strategic enemy areas enabled subsequent entrance of the ground forces into the countries to finish off the remaining resistance (DOD, 2007). According to Anne(2004,p15), the execution of both wars heralded a new era of military tactics, which heavily relied on technologically enhanced devices in carrying out of both aerial and ground combat. This strategy was more precise, faster, and resulted to lower number of military and civilian casualties. DOD (2007) noted that the war strategy in both wars was culmination of coordination high technology military hardware with enhanced communication devices that enabled them to strike with pinpoint precision. The war in Afghanistan witnessed the first application of robots that were used to carry out surveillance, clearance of mines, identification of targets and rescuing soldiers. The robots included Unmanned Aerial Vehicles (UAV) that undertook the aforementioned tasks without carrying human operator in them (David, 2005, p2 7). These robots helped in protecting soldiers from enemy attacks. According to David (2005, p 28), advanced technology has produced better robots that are equipped with high precision equipment and artillery to strike detected target. The 2003 war in Iraq saw a combination of precision weapons, exemplary surveillance of the targeted enemy grounds, and swift ground combatants aided by highly advanced communication network that enabled monitoring of distant operations from a remote region (DOD, 2007). Though the application of advanced military technology enabled quicker executions of the mission, the war has dragged on for many years, resulting to heavy economic and human loss. According to DOD (2007), the number of United States troops killed in both Iraq and Afghanistan exceeds those killed in actual combat at the beginning of the war. Anne (2004, p31) notes that threat of improvised explosive devices or roadside bombs continue inflicting damage on American forces. According to DO D (2007), the explosive devices have killed over 2000 American soldiers in Iraq, while more than 21,000 have suffered debilitating injuries that have effectively compromised their physical and psychological performance for life. In Afghanistan, the improvised explosive devices have claimed lives of over 250 American soldiers, with over 1,700 suffering serious injuries (DOD, 2007). Anne (2004, p21) notes that the explosive devices are the highest killer of the Allied forces in both countries and they have greatly undermined the efforts achieved the application of the advanced military technology. However, continuous innovation in the American military has produced mine- resistant ambush –protected all terrain vehicle(M-ATV) that offers better protection from roadside bombs than the heavier mine- resistant- ambush-

Features Of The Ancient African Art Research Paper - 2

Features Of The Ancient African Art - Research Paper Example The book talks about the cultural belief behind the costume. The locals or indigenous members of the Kuba community believe that in order for life to be balanced you have to connect with the ancestors, therefore; the costume assists them in the connection. The book emphases that like in many African cultures death is a natural event and is characterized as a rite of passage, therefore, these costumes are designed for such events and rites of passage in the society. The Bwoom is a very iconic and symbolic artifact from the Kuba community. It represents a sign of royalty from the society. The mask assists the masquerade element to act out in its design and appearance. This aspect gives us an overview of the origin of the Kuba Kingdom, therefore; it will act as an archive for the history of this unique community in this globe1. This particular mask is named Bwoom because it is like a cornerstone of the community. This is a special mask in the community and it is different from any other mask ever used in the community. It is the only mask not used in funerals or any other sorrowful event in the community. During joyful occasions such as harvests and weddings, the males would be the mask on the forehead and see-through, the holes under the nose of the mask while dancing the. When people whore the mask in any occasion they would cover all parts of their bodies to give a real representation of the spirit. The picture below shows a Bwoom Helmet. The mask the will act as an exhibit dedicated to the tourist and researchers who are interested in the African culture. Including the artwork in the museum is also reflective of the shift of the ethnologists in western culture to view African cultures as diverse and complementary to other cultures.

Create an Organizational Assessment and Development Plan Assignment

Create an Organizational Assessment and Development Plan - Assignment Example ing unit that the organization is operating is on a medium scale and the entire workforce comprises of approximately 150 people, one third of who are full-time employees, one third working on contracts and the rest of the one third workforce is employed on a part time basis. The business has a shamrock model formation and it allows the organization to enjoy a greater fluidity of talent. (Clawson, 2001). The employees are mainly involved in the following three activities: either they work on the manufacturing plant, the planning, procurements & marketing departments or they are involved with the deliveries and logistics of the finished goods. Most of the full time employees and those working on contracts come under these three categories, and all of the office staff, the secretaries, office helpers and other staff are mostly hired on a part time basis. Currently, the business is running at a good profit margin and being in the industry for all these years has helped these manufacturers make a name for themselves in the market targeted mainly towards the consumers who want to buy freshly baked goods such as bread, breakfast rolls etc which are priced strategically so that they fall in between the mass manufactured baked goods offered by larger brands and the expensively exclusive products offered by specialty delis. These younger people have also been working in the same business for most of their lives and are very much familiar with the ropes of their organization. Their ultimate aim in trying to employ an organizational development plan is to increase the productivity of their operations. However, another big concern for the owners is the fact that there is a seeming lack of organizational values among the staff. Although the people who are working full-time and part-time have been with the organization for a long time, there is a lack of organizational affinity among the people working part time for the business. Another cause for concern is the fact that

Thursday, October 17, 2019

Eating Habits of College Students Research Paper

Eating Habits of College Students - Research Paper Example Also, it demonstrates how adequate understanding of consequences of poor eating habits can improve the health of the students and the entire nation. 1. Research question(s), rationale and qualifications, This study aims to answer various issues relating to eating habit of the college students. For example, how does food quality of campus cafe affect eating habits of the college student? What factors influence the eating habit of the college students? Is there a relationship between campus life and eating students eating habit? Does poor eating habit among the college students have any effect on their health? What is the link between the level of health dietary awareness and students eating habit? 2. Outcomes and impact The rate of overweight and obesity in the United States has been rising at an alarming rate as well as the prevalence of lifestyle diseases such as cardiovascular, diabetes and so on. Various studies have shown that the most affected population are those between the age of 18 and 29 years, and an unfortunate majority of these are the college, students. Also, about 36% of the college students are either overweight or obese (Farrell, 2010). The menace of overweight or obesity among the college students has been contributed by unhealthy eating habits. The college environment has also made a significant influence on the eating habits of the students because of the availability of large portions of high calorie and fat foods as well as buffet style cafeteria (Deshpande et al., 2009).