Skip to content

Instantly share code, notes, and snippets.

View mikepenzin's full-sized avatar

Mike Penzin mikepenzin

  • Haifa, Israel
View GitHub Profile
@mikepenzin
mikepenzin / prototyping.js
Created March 3, 2017 10:18
Prototyping Patterns
// 1. Init method
var Person = {
init: function(firstName, lastName){
this.firstName = firstName;
this.lastName = lastName;
return this;
},
full_name: function(firstName, lastName){
return this.firstName + " " + this.lastName;
@mikepenzin
mikepenzin / calc.js
Created March 14, 2017 10:53
Calculator Library
function Calculator(num){
return {
answer : num ? num : 0,
equals : function() {
return this.answer
},
add : function(num) {
this.answer += num ? num : 1
return this
},
@mikepenzin
mikepenzin / DateTimeDiffer.js
Last active March 18, 2017 20:58
Easy calculate how much time passed since update/creation
var createdTime ="Sat Dec 12 2016 18:04:54 GMT+0000";
(function DateTimeDifference( previousTime ) {
var today = Date.now();
previousTime = Date.parse(previousTime);
var seconds = (today - previousTime) / 1000;
var hours = parseInt( seconds / 3600 );
seconds = seconds % 3600;
var minutes = parseInt( seconds / 60 );
if(minutes < 60 && hours === 0) {
@mikepenzin
mikepenzin / calculator.html
Last active December 7, 2017 20:07
simple js calculator
<html>
<title>CalculatorJS</title>
<style>
body {
color: #412a0f;
}
.calculator {
width: 20%;
margin: 0 auto;
@mikepenzin
mikepenzin / prototypal-OOP-patterns.js
Last active December 18, 2017 08:22
Pseudo classical inheritance and Prototypical OOP in JavaScript
"use strict";
var Person = {
init: function(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
return this;
},
fullName: function() {
return this.firstName + " " + this.lastName;