Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
993239d
finished testing
toChaim Aug 1, 2017
31b4be4
fix some tests and my progress so far.
toChaim Aug 3, 2017
4fc875b
a little more done.
toChaim Aug 3, 2017
f401746
fix sort on mergeArrays and remove unesercery arguments from callback…
toChaim Aug 3, 2017
551ac19
inRange done
toChaim Aug 3, 2017
de0972b
refactor and improve inRange. Now it the non inclusive end is right f…
toChaim Aug 3, 2017
8166895
finish lodash
toChaim Aug 3, 2017
14ac495
game working, responsive working.
toChaim Aug 4, 2017
32904c3
2015 exersiexercises
toChaim Aug 5, 2017
ba3afd8
half finished.
toChaim Aug 7, 2017
633ce47
functioning is fine. styleing needs work.
toChaim Aug 8, 2017
839272f
minore improvments.
toChaim Aug 8, 2017
b65ff9d
fix favoriets filter bug
toChaim Aug 8, 2017
9db7da1
first commit on new progject
toChaim Aug 9, 2017
acf4726
working on using login
toChaim Aug 9, 2017
fe30029
got get of favoriets array working. improve login click.
toChaim Aug 9, 2017
380ef76
start on callApplyBind problems
toChaim Aug 9, 2017
fb38d6d
finished tests for guessingGame and passed tests.
toChaim Aug 10, 2017
05e9cce
finish part 1 and 2 original.
toChaim Aug 10, 2017
15056d5
Merge branch 'master' of https://github.com/rithmschool/intermediate_…
toChaim Aug 10, 2017
f4d98df
finish part 1 & 2
toChaim Aug 10, 2017
ed8a7e3
tic,tac,toe working
toChaim Aug 11, 2017
fd0df58
refactoring tic tac toe
toChaim Aug 11, 2017
c70ee42
fix message. Calling myself done.
toChaim Aug 11, 2017
854a393
refactor hacker snooze. Almost Done
toChaim Aug 15, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
18 changes: 18 additions & 0 deletions ajax_with_jquery_exercise/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.row{
margin-bottom: 30px;
}
#btn_group{
width: 100%;
display: flex;
flex-direction:
row; justify-content: space-around;
}
form button{
width: 100px;
}
.glyphicon{
margin: 5px;
}
.hideNoLogin{
visibility: hidden;
}
50 changes: 50 additions & 0 deletions ajax_with_jquery_exercise/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Linker</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://bootswatch.com/readable/bootstrap.min.css">
<link rel="stylesheet" href="index.css">
</head>
<body>
<div class="container">
<div class="row alert-warning header">
<div class="col col-xs-2">icon</div>
<div class="col col-xs-8"><ul class="list-inline">
<li class="list-inline-item"><a id="favor-link" class="" href="#">Favoriets</a></li>
</ul></div>
<div class="col col-xs-2"><ul class="list-inline">
<li class="list-inline-item"><a id="login-link" class="" href="#">Login</a></li>
</ul></div>
</div>
<div class="row hidden" id="login-form">
<form class="col-xs-offset-6 col col-xs-6 " action="">
<div class="row input-group">
<label class="input-group-addon control-label" for="inp-email">Email</label>
<input type="email" class="form-control" name="inp-title" id="inp-email" value= "lane.matthew@gmail.com" required>
</div>
<div class="row input-group">
<label class="input-group-addon" for="inp-password">Password</label>
<input type="password" name="inp-password" class="form-control" id="inp-password" value="password" required>
</div>
<div id="btn_group" class="row input-group">
<button type="submit" id="login-btn" class="btn-warning">Login</button>
<button type="submit" id="signup-btn" class="btn-info">Signup</button>
</div>
<div class="row">
<h3 id="login-fail" class="input-group-addon control-label danger hidden">Login Failed: Please Check email and password.</h3>
</div>
</form>
</div>
<div class="row">
<ol id="links">
<li>This should be removed</li>
</ol>
</div>
</div>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script type="text/javascript" src="index.js"></script>
</body>
</html>
203 changes: 203 additions & 0 deletions ajax_with_jquery_exercise/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
$(document).ready(function(){
//variables
var $login_form = $(`#login-form`);
var $email = $(`#inp-email`);
var $pword = $(`#inp-password`);
var $login_fail = $(`#login-fail`);
var $login_link = $(`#login-link`);
var $links = $(`#links`);
var $fav = $(`#favor-link`);
var fav = [];
var all = [];

//imeadiat calls
if(!!localStorage.getItem('auth_token')) getFav();
getTop().then(function(data){
console.log(data);
all = data;
displayAll(data);
});

//click functions
$fav.click(function(){
console.log('fav click');
if(!localStorage.getItem('auth_token')){
$login_form .toggleClass("hidden");
}else if($fav.text() === `Favoriets`){
$fav.text('All');
displayFav(fav);
}else{
$fav.text('Favoriets');
displayAll(all);
}
});

$login_link.click(function(){
if($login_link.text() === `Logout`){
localStorage.removeItem('auth_token');
$login_link.text('Login');
fav = [];
}else{
$login_form .toggleClass("hidden");
}
});

$(`#login-btn`).click(function(e){
e.preventDefault();

console.log($email.val(), $pword.val());
getLogin($email.val(), $pword.val())
.then(function(token){
console.log(token)
$login_fail.addClass('hidden');
$login_form.addClass('hidden');
$login_link.text('Logout');
getFav();
})
.fail(function(){
$login_fail.removeClass('hidden');
})
});

$(`#signup-btn`).click(function(e){
e.preventDefault();

console.log($email.val(), $pword.val(), true);
getLogin($email.val(), $pword.val(), true)
.then(function(token){
console.log(token)
$login_fail.addClass('hidden');
$login_form.addClass('hidden');
$login_link.text('Logout');
})
.fail(function(){
$login_fail.removeClass('hidden');
})
});

$links.on('click', '.star', function(e){
var id = $(e.target).attr('storyid');
setFav(id);
});

// regular functions
function isFav(sid){
return fav.some(function(sid,v, v.story_id, sid == v.story_id){
console.log(v);
return sid === v.story_id;
});
}

function displayAll(arr){
$links.empty();
arr.forEach(function(v) {
displayLink(v.title,
v.url,
v.id,
isFav(v.id),
!!localStorage.getItem('auth_token'));
});
}

function displayFav(arr){
$links.empty();
arr.forEach(function(v) {
displayLink(v.title,
v.url,
v.storyId,
true,
true);
});
}

function displayLink(title, link, storyId=0, favor = false, login = false){
var loginClass = 'hideNoLogin';
if(login) loginClass = 'showOnLogin';
let html = `<a storyId="${storyId}" class="glyphicon glyphicon-star-empty star ${loginClass}" href="#"></a>`;
let shortLink = '';
if(link) { shortLink = link.split('/').filter(v => v.includes('.')); }
if(favor) html = `<a storyId="${storyId}" class="glyphicon glyphicon-star star ${loginClass}" href="#"></a>`;
{ html += `<a href="${link}">${title}</a> <small>( ${shortLink[0]} )</small>`; }
let $lin = $('<li>');
$lin.html(html);
if(favor) $lin.addClass('favor');
$lin.addClass('bg-warning')
$links.append($lin);
}

function storyFromID(id){


for(let s of all){
if(s.id == id) {
return s;
}
}
}

//ajax functions
function getTop(){
return $.get('https://hacker-news.firebaseio.com/v0/'
+ 'topstories.json?print=pretty')
.then(function(topstories){
console.log(topstories);
return Promise.all(topstories.slice(0,50).map(function(v,i){
return $.get(
`https://hacker-news.firebaseio.com/v0/`
+ `item/${topstories[i]}.json?print=pretty`)
}));
})
.fail((err) => console.warn(err));
}

function getFav() {
return $.ajax({
method: "GET",
headers: {
"Authorization": localStorage.getItem('auth_token'),
},
'url': 'https://hn-favorites.herokuapp.com/stories.json',
})
.then((favorites) => {console.log(favorites); return fav = favorites;})
.fail((err) => console.warn(err));
}

function getLogin(email, password, signup = false){
var urlEnd = 'login';
if(signup) urlEnd = 'signup';

return $.ajax({
method: "POST",
headers: {
"Content-Type": "application/json"
},
url: `https://hn-favorites.herokuapp.com/${urlEnd}`,
data: JSON.stringify({
'email': email,
'password': password
})
}).then(function(data) {
localStorage.setItem('auth_token', data.auth_token);
auth_token = data.auth_token;
return(data.auth_token);
})
}

function setFav(id){
var s = storyFromID(id);

return $.ajax({
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": localStorage.getItem('auth_token'),
},
url: `https://hn-favorites.herokuapp.com/stories.json`,
data: JSON.stringify({
"hacker_news_story": s,
})
})
.then((res) => console.log(res))
}

});
50 changes: 50 additions & 0 deletions call_apply_bind_exercise/callApplyBind.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"use strict"

function sumEvenArguments(){
var arr = [].slice.call(arguments);
return arr.reduce(
function(t, v){
if(v % 2 === 0) { return t+v; }
else { return t;}
},0);
}

function arrayFrom(obj){
return [].slice.call(obj);
//return Array.prototype.slice.call(obj);
/*
var arr = [];

for(let i = 0; i < obj.length; i++){
arr.push(obj[i]);
}

return arr;
*/
}

function invokeMax(fn, max){
var count = 0;

return function(){
if(++count > max) return `Maxed Out!`;
var arr = [].slice.call(arguments);

return fn.apply(this, arr);
};

}

function guessingGame(amount){
var count = 0;
var answer = Math.floor(Math.random() * 11);

return function(guess){
if(count++ === amount) { return `No more guesses the answer was ${answer}`; }
else if(count > amount) { return `You are all done playing!`; }
else if(answer > guess){ return "You're too low!"; }
else if(answer < guess){ return "You're too high!"; }
else if(answer === guess){ return "You got it!"; }
}

}
59 changes: 59 additions & 0 deletions call_apply_bind_exercise/callApplyBindSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,63 @@ describe("#invokeMax", function(){
expect(addOnlyThreeTimes(1,2)).to.equal("Maxed Out!")
expect(addOnlyThreeTimes(1,2)).to.equal("Maxed Out!")
});
});

describe("#guessingGame", function(){

it("shuould return the right type", function(){
var game = guessingGame(0);
expect(typeof game).to.equal('function')
expect(typeof game(0)).to.equal('string')
});

it("inner function should return the correct results", function(){
var game = guessingGame(0);
expect(game(0).substring(0,31)).to.equal('No more guesses the answer was ')
expect(game(0)).to.equal('You are all done playing!')
expect(game(-1)).to.equal('You are all done playing!')
game = guessingGame(10);
for(let t = 0; t < 10; t++){
expect(game(-1)).to.equal("You're too low!")
}
expect(game(-1).substring(0,31)).to.equal('No more guesses the answer was ')
expect(game(-1)).to.equal('You are all done playing!')
expect(game(-1)).to.equal('You are all done playing!')
game = guessingGame(12);
for(let t = 0; t < 12; t++){
expect(game(11)).to.equal("You're too high!")
}
expect(game(11).substring(0,31)).to.equal('No more guesses the answer was ')
expect(game(11)).to.equal('You are all done playing!')
expect(game(-1)).to.equal('You are all done playing!')
game = guessingGame(11)
var gotWin = false;
for(let t = 0; t < 11; t++){
if(game(t) === "You got it!"){
gotWin = true;
break;
}
}
expect(gotWin).to.equal(true)
});

it("should have choose every possiblity and change", function(){
var cntObj = {0:0, 1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0, 10:0,};
for(let t = 0; t < 1000000; t++){
let game = guessingGame(11);
for(let n = 0; n < 11; n++){
if(game(n) === "You got it!"){
cntObj[n]++;
break;
}
}

// return false or expect(flase).to.equal(true)

}
for(let n = 0; n < 11; n++){
expect(cntObj[n] > 10).to.equal(true)
}
});

});
Loading