This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Usually my github workflow is like this: | |
git add . | |
git status // to see what changes are going to be commited | |
git commit -m 'Some descriptive commit message' | |
git push origin master | |
Now, when I use gh-pages, there are only a few more commands that I have to use after the above: | |
git checkout gh-pages // go to the gh-pages branch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Git commands | |
Tell Git who you are | |
Configure the author name and email address to be used with your commits. | |
Note that Git strips some characters (for example trailing periods) from user.name. | |
git config --global user.name "Sam Smith" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var result = 1; | |
var counter = 0; | |
while (counter < 10) { | |
result = result * 2; | |
counter = counter + 1; | |
} | |
console.log(result); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addBlankTargetForLinks () { | |
$('a[href^="http"]').each(function(){ | |
$(this).attr('target', '_blank'); | |
}); | |
} | |
$(document).bind('DOMNodeInserted', function(event) { | |
addBlankTargetForLinks(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
How to make the smallest possible JavaScript FizzBuzz solution. Requirements: | |
Print numbers from 1 to 100 | |
If a number is dividable by 3, print “Fizz” instead | |
If a number is dividable by 5, print “Buzz” instead | |
If a number is dividable by 3 and 5, print “FizzBuzz” instead | |
Print using console.log | |
Pure JavaScript only | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Write a program that creates a string that represents an 8×8 grid, using newline characters to separate lines. At each position of the grid there is either a space or a “#” character. The characters should form a chess board.*/ | |
var size = 8; | |
var board = ""; | |
for (var y =0; y< size; y++) { | |
for(var x =0; x< size; x++){ | |
if ((x+y) %2 ===0) | |
board += " "; | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
function wrapValue(n) { | |
var localVariable = n; | |
return function() { return localVariable; }; | |
} | |
var wrap1 = wrapValue(1); | |
var wrap2 = wrapValue(2); | |
console.log(wrap1()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Recursion | |
It is perfectly okay for a function to call itself, as long as it takes care not to overflow the stack. A function that calls itself is called recursive. Recursion allows some functions to be written in a different style. */ | |
function power(base, exponent) { | |
if (exponent == 0) | |
return 1; | |
else | |
return base * power(base, exponent - 1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Write a function min that takes two arguments and returns their minimum. | |
var min = function(a,b) { | |
return (a <= b) ? a : b; | |
} | |
console.log(min(9, 101)); | |
// → 9 | |
console.log(min(55, -110)); | |
// → -110 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Define a recursive function isEven corresponding to this description. | |
The function should accept a number parameter and return a Boolean. | |
Test it on 5 and 68. See how it behaves on -1...-22... */ | |
var isEven = function(num) { | |
num = Math.abs(num); // convert to absolute value to account to negative numbers | |
// Why I used Math.abs() see here: http://devdocs.io/javascript/global_objects/math/abs | |
if (num === 0) | |
return true; | |
else if (num === 1) |
OlderNewer