Skip to content

Instantly share code, notes, and snippets.

View Arieg419's full-sized avatar

Omer Goldberg Arieg419

View GitHub Profile
function waysToReturnChange(denominations, numOfCoins, amount) {
if(amount === 0) return 1; // Perfect!
if(amount < 0) return 0; // No solution exists for negative amount
if(numOfCoins < 0 && amount > 0) return 0; // We don't have coins left!
console.log('checking ways to make ' + amount + ' with ' + denominations.slice(numOfCoins));
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react-dom.js"></script>
</head>
<!DOCTYPE html>
<html>
<head>
<title>Omer's Workshop</title>
<script src="https://unpkg.com/redux@latest/dist/redux.min.js"></script>
</head>
<body>
<div>
<p>
Counter: <span id="value">0</span> times
<!DOCTYPE html>
<html>
<head>
<title>Omer's Workshop</title>
<script src="https://unpkg.com/redux@latest/dist/redux.min.js"></script>
</head>
<body>
<div>
<p>
Counter: <span id="value">0</span> times
@Arieg419
Arieg419 / index.html
Last active September 17, 2017 07:21
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Cookies!</h1>
<button>Show cookies</button>
</body>
</html>
@Arieg419
Arieg419 / index.js
Created September 17, 2017 07:24
Simple node server
const express = require('express')
const app = express()
app.get('/', (req,res) => {
res.sendFile(__dirname + "/index.html");
})
app.listen('8081')
console.log('Magic happens on port 8081')
exports = module.exports = app
@Arieg419
Arieg419 / index.html
Created September 17, 2017 07:38
index.html v2
<!DOCTYPE html>
<html>
<head>
<script>
document.cookie = "monster=cookie";
document.cookie = "favorite_food=chocolate_chip";
alert(document.cookie);
</script>
</head>
<body>
@Arieg419
Arieg419 / fetchCookie.js
Created September 17, 2017 19:21
fetch a cookie with a key of "username"
const fetchCookie = () => {
const name = "username" + "=";
const cookie_array = document.cookie.split(';');
for(let i = 0; i < cookie_array.length; i++) {
let c = cookie_array[i];
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
@Arieg419
Arieg419 / getUserData.js
Created September 17, 2017 19:24
A method that checks for a cookie with a key of "username".
const getUserData = () => {
let username = fetchCookie();
if (username != "") {
alert("Welcome again " + username);
} else {
username = prompt("Please enter your name:","");
setCookie("username", username, 30);
}
}
@Arieg419
Arieg419 / setCookie.js
Created September 17, 2017 19:31
A method for setting cookies in the browser.
const setCookie = (key,val,days_till_expiration) => {
let d = new Date();
d.setTime(d.getTime() + (days_till_expiration*24*60*60*1000));
const expires = "expires=" + d.toGMTString();
document.cookie = key + "=" + val + ";" + expires + ";";
}