Skip to content

Instantly share code, notes, and snippets.

View ddeveloperr's full-sized avatar
👨‍💻
Doist

Kemal C. ddeveloperr

👨‍💻
Doist
View GitHub Profile
@ddeveloperr
ddeveloperr / gist:2a0234d4e350eec6ea7f
Created March 17, 2015 14:55
Keep gh-pages in sync with master
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
@ddeveloperr
ddeveloperr / GitCommands
Last active August 29, 2015 14:17
Basic Common Git commands
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"
var result = 1;
var counter = 0;
while (counter < 10) {
result = result * 2;
counter = counter + 1;
}
console.log(result);
@ddeveloperr
ddeveloperr / open-in-blank.js
Created March 25, 2015 13:34
open-links in-blank using .js
function addBlankTargetForLinks () {
$('a[href^="http"]').each(function(){
$(this).attr('target', '_blank');
});
}
$(document).bind('DOMNodeInserted', function(event) {
addBlankTargetForLinks();
});
@ddeveloperr
ddeveloperr / smallest-FizzBuzz.js
Last active August 29, 2015 14:17
How to make the smallest possible JavaScript FizzBuzz solution
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
@ddeveloperr
ddeveloperr / Chessboard.js
Created March 29, 2015 09:18
Write a program that creates a string that represents an 8×8 grid
/*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
@ddeveloperr
ddeveloperr / closure.js
Created March 30, 2015 07:14
Closure in JS examples
//
function wrapValue(n) {
var localVariable = n;
return function() { return localVariable; };
}
var wrap1 = wrapValue(1);
var wrap2 = wrapValue(2);
console.log(wrap1());
@ddeveloperr
ddeveloperr / recursion.js
Last active August 29, 2015 14:18
Recursion in JS examples
/*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);
}
@ddeveloperr
ddeveloperr / min.js
Created April 1, 2015 09:30
// Write a function min that takes two arguments and returns their minimum.
// 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
@ddeveloperr
ddeveloperr / isEven.js
Created April 1, 2015 09:55
Define a recursive function isEven in JS
/*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)