Skip to content

Instantly share code, notes, and snippets.

View DavidGoussev's full-sized avatar

David Goussev DavidGoussev

View GitHub Profile

Use these rapid keyboard shortcuts to control the GitHub Atom text editor on Mac OSX.

Key to the Keys

  • ⌘ : Command key
  • ⌃ : Control key
  • ⌫ : Delete key
  • ← : Left arrow key
  • → : Right arrow key
  • ↑ : Up arrow key
@DavidGoussev
DavidGoussev / filter.js
Last active July 27, 2016 07:09
Functional JS
/*
Filter!
Test 1
Name your function filterOutOdds
Write a function that takes a list and filters out all the odd numbers
Takes one parameter, a list of numbers
Returns a list with only the even numbers remaining
*/
@DavidGoussev
DavidGoussev / arrayList.js
Last active July 26, 2016 22:53
Data Structures
/*
ArrayList
We are going to approximate an implementation of ArrayList. In JavaScript terms, that means we are
going to implement an array using objects. You should not use arrays at all in this exercise, just
objects. Make a class (or constructor function; something you can call new on) called ArrayList.
ArrayList should have the following properties (in addition to whatever properties you create):
length - integer - How many elements in the array
push - function - accepts a value and adds to the end of the list
@DavidGoussev
DavidGoussev / bubbleSort.js
Last active July 26, 2016 22:03
Sorting Algorithms
function bubbleSort(nums){
var swapped = false;
do {
swapped = false;
for(var i = 0; i < nums.length; i++) {
if(nums[i] > nums[i+1]) {
var temp = nums[i];
nums[i] = nums[i+1];
nums[i+1] = temp;
swapped = true;
function factorial(n) {
var f = 1;
if (n < 0) {
throw "integer must be non-negative";
} else if (n === 0) {
return 1;
} for(var i=1; i<=n; i++) {
f *= n;
}
return f;
@DavidGoussev
DavidGoussev / pow.js
Last active August 10, 2016 19:28
pow
function power(n, e) {
var f = 1;
for (var i=1; i <= Math.abs(e); i++) {
f *= n
}
return f === (e < 0) ? 1/f : f
}
function fib(n) {
var a = 0, b = 1, f = 1;
for (var i = 2; i <= n; i++) {
f = a + b;
a = b;
b = f;
}
return f;
}
@DavidGoussev
DavidGoussev / init_replica.js
Last active July 6, 2016 07:47
MongoDB replication & init_replication scripts
config = { _id: "m101", members:[
{ _id : 0, host : "localhost:27017"},
{ _id : 1, host : "localhost:27018"},
{ _id : 2, host : "localhost:27019"} ]
};
rs.initiate(config);
rs.status();
@DavidGoussev
DavidGoussev / remove_git_remote
Created July 3, 2016 23:13
GITHUB - remove remote file/folder inadvertantly added
git rm -r --cached some-directory
git commit -m 'Remove the now ignored directory "some-directory"'
git push origin master
@DavidGoussev
DavidGoussev / palindrome.js
Last active June 24, 2016 06:37
Palindrome Check!
function palindromeChk(str) {
return str = str.split('').reverse().join('');
}
// add following to remove any white spaces from phrases or sentences:
// str = str.toLowerCase().replace(/\W/g, '');