Yet Another Markup Language
The YAML Cookbook
http://www.yaml.org/YAML_for_ruby.html#simple_sequence
http://stackoverflow.com/questions/3877004/how-do-i-parse-a-yaml-file
require 'yaml'
thing = YAML.load_file('some.yml')
puts thing.inspect
require 'yaml'
thing = YAML.load_file('some.yml')
puts thing.inspect
username: someuser_on_pg
host: localhost
https://fiftyexamples.readthedocs.org/en/latest/algorithms.html
Calling something an algorithm means that the following properties are all true:
- An algorithm is an unambiguous description that makes clear what has to be implemented. In a recipe, a step such as “Bake until done” is ambiguous because it doesn’t explain what “done” means. A more explicit description such as “Bake until the cheese begins to bubble” is better. In a computational algorithm, a step such as “Choose a large number” is vague: what is large? 1 million, 1 billion, or 100? Does the number have to be different each time, or can the same number be used on every run?
- An algorithm expects a defined set of inputs. For example, it might require two numbers where both numbers are greater than zero. Or it might require a word, or a list of zero or more numbers.
- An algorithm produces a defined set of outputs. It might output the larger of the two numbers, an all-uppercase version of a word, or a sorted version of the list of numbers.
- An algorithm is guaranteed to terminate and produce a result, always stopping after a finite time. If an algorithm could potentially run forever, it wouldn’t be very useful because you might never get an answer.
- Most algorithms are guaranteed to produce the correct result. It’s rarely useful if an algorithm returns the largest number 99% of the time, but 1% of the time the algorithm fails and returns the smallest number instead. [1]
- If an algorithm imposes a requirement on its inputs (called aprecondition), that requirement must be met. For example, a precondition might be that an algorithm will only accept positive numbers as an input. If preconditions aren’t met, then the algorithm is allowed to fail by producing the wrong answer or never terminating.
http://core.ecu.edu/csci/wirthj/Algorithms/introAlgo-c.html An algorithm is a series of specific steps which solve a particular problem.
series
specific
- The steps must be done in a particular order and each of the steps must be used (unless the algorithm says otherwise).
steps
- A step must NOT be replaced by a similar step.
solve
- Like a cooking recipe, an algorithm tells you to do things. Each thing you do is called a step (aka instruction, aka command)
particular problem
- An algorithm produces a final result (aka output) which is the solution to a problem.
- The algorithm for one problem will not usually solve a different problem.
- The details defining the problem must be made available at the start of the algorithm. These details are called givens. (aka parameters).
- Most algorithms have these basic parts:
- Description of Problem
- Set up
- Parameters
- Execution
- Conclusion
arp | arp | |
assign | ln | Create a file link |
assign | ln -s | On Unix, a directory may not have multiple links, so instead a symbolic link must be created with ln -s . |
assoc | file | |
at | at | |
attrib | chown | Sets ownership on files and directories |
cd | cd | On Windows, cd alone prints the current directory, but on Unix cd alone returns the user to his home directory. |
cd | pwd | On Windows, cd alone prints the current directory. |
chkdsk | fsck | Checks filesystem and repairs filesystem corruption on hard drives. |
cls | clear | Clear the terminal screen |
copy | cp | |
date | date | Date on Unix prints the current date and time. Date and time on Windows print the date and time respectively, and prompt for a new date or time. |
del | rm | |
deltree | rm -r | Recursively deletes entire directory tree |
dir | ls | "dir" also works on some versions of Unix. |
doskey /h | history | The Unix history is part of the Bash shell. |
edit | vi | edit brings up a simple text editor in Windows. On Unix, the environment variable EDITOR should be set to the user's preferred editor. |
exit | exit | On Unix, pressing the control key and D simultaneously logs the user out of the shell. |
explorer | nautilus | The command explorer brings up the file browser on Windows. |
fc | diff | |
find | grep | |
ftp | ftp | |
help | man | "help" by itself prints all the commands |
hostname | hostname | |
ipconfig /all | ifconfig -a | The /all option lets you get the MAC address of the Windows PC |
mem | top | Shows system status |
mkdir | mkdir | |
more | more | |
move | mv | |
net session | w | |
net statistics | uptime | |
nslookup | nslookup | |
ping | ping | |
print | lpr | Send a file to a printer. |
reboot | shutdown -r | |
regedit | edit /etc/* | The Unix equivalent of the Windows registry are the files under /etc and /usr/local/etc . These are edited with a text editor rather than with a special-purpose editing program. |
rmdir | rmdir | |
rmdir /s | rm -r | Windows has a y/n prompt. To get the prompt with Unix, use rm -i . The i means "interactive". |
set | env | Set on Windows prints a list of all environment variables. For individual environment variables, set <variable> is the same as echo $<variable> on Unix. |
set Path | echo $PATH | Print the value of the environment variable using set in Windows. |
shutdown | shutdown | Without an option, the Windows version produces a help message |
shutdown -s | shutdown -h | Also need -f option to Windows if logged in remotely |
sort | sort | |
start | & | On Unix, to start a job in the background, use command & . On Windows, the equivalent isstart command . See How to run a Windows command as a background job like Unix ?. |
systeminfo | uname -a | |
tasklist | ps | "tasklist" is not available on some versions of Windows. See also this article on getting a list of processes in Windows using Perl |
title | ? | In Unix, changing the title of the terminal window is possible but complicated. Search for "change title xterm". |
tracert | traceroute | |
tree | find | On Windows, use tree | find "string" |
type | cat | |
ver | uname -a | |
xcopy | cp -R | Recursively copy a directory tree |
a <=> b :=
if a < b then return -1
if a = b then return 0
if a > b then return 1
The quick and dirty
There are many configurable options that you can pass into Gravtastic. I found it quite refreshing to have a gem just work "out-of-the-box". It also has support for plain ruby if you're not using something like rails. Also, if you want to have the gravatar load on the client side, it has an option to work using javascript if your using Rails 3.1 or higher.
Gemfile
gem 'gravtastic'
Model
user.rb
include Gravtastic
has_gravatar
View
_comment.html.haml
= image_tag @comment.user.gravatar_url
From Michael Harl's Rails Tutorial Chapter 6 Box 6.3. Using let
RSpec’s let method provides a convenient way to create local variables inside tests. The syntax might look a little strange, but its effect is similar to variable assignment. The argument of let is a symbol, and it takes a block whose return value is assigned to a local variable with the symbol’s name. In other words,
let(:found_user) { User.find_by(email: @user.email) }
creates a found_user variable whose value is equal to the result of find_by. We can then use this variable in any of the before or it blocks throughout the rest of the test. One advantage of let is that it memoizes its value, which means that it remembers the value from one invocation to the next. (Note that memoize is a technical term; in particular, it’s not a misspelling of “memorize”.) In the present case, because let memoizes the found_user variable, the find_by method will only be called once whenever the User model specs are run.specify method -
controller: static_pages action: homeThis is a YAML3 representation of params, which is basically a hash, and in this case identifies the controller and action for the page.
Create = PUT with a new URI
POST to a base URI returning a newly created URI
Read = GET
Update = PUT with an existing URI
Delete = DELETE
"An Array is just a list of items in order (like mangoes, apples, and oranges). Every slot in the list acts like a variable: you can see what object a particular slot points to, and you can make it point to a different object. You can make an array by using square brackets In Ruby, the first value in an array has index 0. The size and lengthmethods return the number of elements in an array. The last element of the array is at index size-1. Negative index values count from the end of the array, so the last element of an array can also be accessed with an index of -1. If you attempt to read an element beyond the end of an array (with an index >= size) or before the beginning of an array (with an index < -size), Ruby simply returns nil and does not throw an exception. Ruby's arrays are mutable - arrays are dynamically resizable; you can append elements to them and they grow as needed."