Tags: drupal git php regex jquery javascript vim unix css html

Q: What git commands do you use if you want to keep the last commit, but make a change to its commit message?
A: git commit --amend

Q: Write the javascript code to create a new empty object literal (called 'test').
A: var test = {};

Q: How do you undo a 'git add' for a file name 'index.html'?
A: git reset index.html

Q: True or False: When doing a git rebase -i, you can just edit the commit message on the rebasing screen, to change the commit message in the log.
A: False. You must change the command from "pick" to "reword." That will give you an opportunity to change the commit message when you get to that point in the rebasing process.

Q: What git command can be used to show a diff between staged changes and their original files?
A: git diff --cached

Q: How do you show a git diff between a recent commit and the last commit?
A: git diff hash1 hash2

Q: What does a normal git diff show you?
A: The difference between the working directory (changes not added) and the local repo.

Q: In mysql, what does --i-am-a-dummy do?
A: Otherwise known as --safe-updates, this option prevents MySQL from performing update operations unless a key constraint in the WHERE clause and / or a LIMIT clause are provided, e.g.:
mysql> DELETE FROM bigtable;
ERROR 1175: You are using safe update mode and you
tried to update a table without a WHERE that uses a
KEY column

Q: What is the git command for showing your username and email address for the repo.
A: git config --list

Q: Drupal hook for adding permissions for your module.
A: hook_permission()

Q: True or False: Hook menu will use 'access callback' => 'user access' by default, even if you don't define it.
A: True

Q: How do I return a 404 page programatically using drupal?
A: return drupal_not_found();
By the way, this is great for 'else' conditions in your module.

Q: hook_permission()
A: The hook for adding permissions for your module to the permissions page

Q: hook_node_view()
A: The hook that is fired as a node is about to be rendered on the page

Q: hook_page_alter(&$page)
A: The hook that his fired before the page renders. It passes in the &$page object so page content can be altered before it is printed.

Q: How do you create a new, empty array (called 'test') in PHP.
A: $test = array();

Q: How do I show the state of HEAD in git?
A: git describe

Q: What is shorthand for jquery's document.ready?
A: $(function() { });

Q: What is the regular expression character for beginning of the line?
A: ^

Q: What is the regular expression character for "end of the line"
A: $

Q: How do you represent a regular expression capturing group, if you are trying to capture a regular expression called regexp.
A: (regexp)

Q: What is the regular expression for a range of letters including the whole alphabet?
A: [a-z]

Q: What is the regular expression for detecting any numeral from one to eight?
A: [1-8]

Q: True or False. The regular expression range [4-7] will detect the value 4.
A: True. Ranges are inclusive and will detect both the beginning and ending value specified.

Q: What does ?: signify in a regular expression
A: It signifies a non-capturing group. If a regex group contains ?: then it will identify the group for parsing purposes, but it ignores it later in the final result. Example:
(?:Hello)(.+) will find "Hello Bryan," but the captured value will just be "Bryan."

Q: TRUE or FALSE: A php switch statement uses strict (===) comparison. (checks that both the data type and the value match)
Example:
switch($var) {
    case 0 : return 'a'; break;
    case 1 : return 'b'; break;
    default : return 'c'; break;
}
A: FALSE. It does a loose (==) comparison, which only checks the value. To do a strict comparison, use if... else if... statements.

Q: What is the command in git for renaming a branch from "oldbranch" to "newbranch"?
A: git branch -m oldbranch newbranch

Q: What is the vim command for 'redo'?
A: ctrl+r

Q: What Drupal form API attribute is used to set up a call back for a submit handler?
A: #submit
This attribute can be attached to the form in general or to a specific form button.

Q: What drupal function can be used to submit to the database message log at 'admin/reports/dblog'
A: watchdog()

Q: In Drupal 7, what database function allows you to search values in the database?
A: db_select($table, $alias, $options)

Q: In Drupal 7, what database function allows you to remove values from the database?
A: db_delete($table, $options)

Q: In Drupal 7, what database function (and default parameters) allows you to update values in the database?
A: db_update($table, $options)

Q: In Drupal 7, what database function allows you to add values to tables in the database?
A: db_insert($table, $options)

Q: In git how do you undo a commit but leave your files changed in the staging area?
A: git reset --soft HEAD~1
Technically this is more complex than an "Undo," but I don't quite understand it all yet.

Q: In git, how do you delete a local branch named "mybranch"?
A: git branch -d mybranch

Q: In git, how do you delete a branch named "mybranch" from the remote location "origin"?
A: git push origin :mybranch

Q: How do you record a macro (named "d") in vim, if you're in normal mode?
A: qd

Q: How do you stop recording a vim macro, if in normal mode?
A: q

Q: How do you play a recorded vim macro, named 'd'?
A: @d

Q: True or False: User 1 has all drupal permissions, and none of them can be revoked on the permissions page.
A: True

Q: Which Drupal function do you use to determine whether the user has a given privilege? (include parameters)
A: user_access($string, $account = NULL)

Q: Drupal:  ________ are to entities, as content types are to nodes.
A: Bundles

Q: What Unix command allows you to see the filesize of a file named "file.txt"?
A: du -sk file.txt

Q: What is the name of the PHP string delimiter that looks like this: <<<
A: heredoc

Q: True or False: Heredoc text behaves like a double-quoted string, allowing you to use the contents of PHP variables.
A: True

Q: True or False. Indenting the closing heredoc identifier will result in a parsing error.
A: True

Q: What command polls for changes in a file named "errors.log", by showing a live display of the last 20 lines in the file.
A: tail errors.log -n20 -f

Q: What jQuery function do you use to access information in html data-attributes?
A: data()

Q: What do you add in order to provide a default value of 3 for a javascript argument. Example:
var myFunction = function(arg) {
  // Add it here.
}
A: arg = arg || 3;

Q: Given a javascript object "truck" with a property "color," assign the value of that property to a new variable called test.
A: var test = truck.color;

Q: Using jquery, define a trigger (like to window.load) called "testComplete" that fires on the body element.
A: $('body').trigger('testComplete');

Q: Using jQuery, write the line of code needed to run an anonymous function when a trigger called 'testComplete' fires on the body element.
A: $('body').on('testComplete', function() {
});

Q: $.getJSON() is shorthand for which jQuery function (with appropriately preset parameters).
A: $.ajax()

Q: True or False, you can combine CSS Pseudoclasses with classes like this:
1
2
3
#content a.more:hover {
  color: blue;
}
A: True

Q: What is the bash command to download the file "http://bryanbraun.com/style.css" from the web to your current directory?
A: curl -O http://bryanbraun.com/style.css

Q: True or False: The form data on a node_form is saved to the node object as part of the default submit handlers for the form?
A: True.
The function "node_form_submit_build_node" runs this: $node = $form_state['node'];
Whenever the node is saved or preview. You can then pass the data into the db on hook_node_insert or hook_node_update.

Q: What Drupal hook is run when a new node is created and being added to the node table?
A: hook_node_insert()

Q: What Drupal hook is run when a node is updated and the changes are being made to the node table?
A: hook_node_update()

Q: What hook is run when a node is being deleted and removal operation is being made to the node table?
A: hook_node_delete()

Q: What Drupal hook do you use to add values to the node object before it is used on a page?
A: hook_node_load()

Q: Write a line of Drupal code to store the contents of a file (located at $path) in a variable called $contents (using the file API).
A: $contents = file_get_contents($path);

Q: Write a line of Drupal code finding the path to the "zen" theme in your codebase, and saving it to the variable $theme_path.
A: $theme_path = drupal_get_path('theme', 'zen');

Q: What Drupal code would you write to allow somebody to use hook_mymodule_person_alter($data)? (where $data represents the alterable array used in your "mymodule" module)
A: drupal_alter('mymodule_person', $data);

Q: How do you apply a commit (named 5ag49bd) in another branch to the branch you are currently on?
A: git cherry-pick 5ag49bd

Q: How many optional parameters does the the "break" command (for a PHP switch statement) accept? 1, 2, 3, or 4?
Bonus: what do the parameters do?
A: 1

Q: What Drupal function can you work with to build or manipulate lists of content?
A: theme_item_list()

Q: Convert the following PHP logic into the ternary syntax:
1
2
3
4
5
6
7
8
9
<?php
if ($coke == 'diet') {
  $calories = 'low';
} else {
  $calories = 'high';
}
?>
A: $calories = ($coke == 'diet' ? 'low' : 'high');

Q: 1 | <link type="text/css" [...] href="normalize.css" />
A: rel="stylesheet"
Extra: This is required.

Q: In Drupal store the node object where the nid is 11 into the php variable $node.
A: $node = node_load(11);

Q: In Drupal store a node object where nid is 11 into a php variable called $node using an entity function.
A: $node = entity_load('node', array(11));

Q: Using javascript, add a new element containing the string "foo" to an existing array named "bar".
A: bar.push('foo');

Q: Show how to delete a tag named 'mytag', with Git.
A: git tag -d mytag

Q: Move the file "file.txt" into the neighboring directory "folder" using git.
A: git mv file.txt folder

Q: Use git to show a list of both local and remote branches.
A: git branch -a

Q: Output the time required to run myfunction() to the browser console, labeled as 'Elapsed';
A: console.time('Elapsed');myfunction();
console.timeEnd('Elapsed');

Q: Use git to list all local branches containing the commit "1qw2asz" in their history.
A: git branch --contains 1qw2asz