Skip to content

Instantly share code, notes, and snippets.

View YaakovHatam's full-sized avatar
🎯
Focusing

Yaakov Hatam YaakovHatam

🎯
Focusing
View GitHub Profile
@YaakovHatam
YaakovHatam / select-to-datalist.js
Last active January 26, 2021 14:41
Convert HTML select tag to datalist tag
function selectToDatalist(theSelectElement) {
// check if datalist supported first
if ('options' in document.createElement('datalist')) {
// get all options
var options = theSelectElement.innerHTML;
// Create the new datalist elements
var theNewInputelement = document.createElement('input');
theNewInputelement.setAttribute('autocomplete', "off");
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
font-size: 16px;
@YaakovHatam
YaakovHatam / dateValidate.js
Created November 22, 2020 16:27
Validate JS date
function isValidDate(d) {
return d instanceof Date && !IsNAN(d)
}
isValidDate(new Date("2020-30-30")) // false
public class ATM {
public static void main(String[] args) {
int[] DENOM = { 50, 100, 200 }; // bill types
int[] bills = { 0, 0, 0 }; // how many bills have in ATM
addBills(bills, new int[] { 2, 5, 6 });
System.out.println(cashBalance(DENOM, bills)); // 1800
System.out.println(); // true
int amountToDispense = 1000;
import java.util.concurrent.ThreadLocalRandom;
public class HelloWorld {
public static void main(String []args){
int x = 13;
int y = 5;
// math operators
int addition = x + y; // 18
@YaakovHatam
YaakovHatam / builder.js
Last active November 29, 2019 09:48
openwaethermap-builder.js
function OpenweathermapBuilder(key) {
var queryStringParams;
var baseApiUrl;
baseApiUrl = 'http://api.openweathermap.org/data/2.5/weather';
queryStringParams = [];
init();
function init() {
@YaakovHatam
YaakovHatam / weather.js
Last active November 22, 2019 09:25
Open weather map simple code example
// const ENDPOINT = 'http://api.openweathermap.org/data/2.5/weather?q=jerusalem&units=metric&appid=1e8ffdb64b7d4d8dbdd4bf3a700bdeb0';
const ENDPOINT = 'weather.json';
fetch(ENDPOINT).then(res => res.json().then(weatherData => {
console.log(weatherData);
}))
@YaakovHatam
YaakovHatam / requireUncached.js
Created November 17, 2019 17:29
Nodejs require module without cache
const a1 = requireUncached('./mdl')('moshe')
const a2 = requireUncached('./mdl')('moshe1')
const a3 = requireUncached('./mdl')('moshe2')
function requireUncached(module){
delete require.cache[require.resolve(module)]
return require(module)
}
@YaakovHatam
YaakovHatam / index.html
Created September 8, 2019 08:26
Very simple nodejs with static html file and API
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="jquery.js"></script>
</head>
<body>
@YaakovHatam
YaakovHatam / naming.md
Created August 14, 2019 17:55
JavaScript naming rules

Variable and function names written as camelCase

Global/Constants variables written in UPPERCASE

$ in start of variable name used to hold JavaScript library objects

  • variables: