Skip to content

Instantly share code, notes, and snippets.

View krfong916's full-sized avatar
Do your job

Big Dog Lil Dog krfong916

Do your job
  • University of California, Santa Cruz
View GitHub Profile
@krfong916
krfong916 / ddd_and_boundaries.java
Created February 28, 2019 07:01
Two topics covered here, DDD and domain model boundary
public void SubmitOrder(OrderData data) {
var customer = GetCustomer(data.CustomerId);
var sendEmail = delegate { /* send email */ };
// call the domain model for the rest of the regular order submit logic customer.BecamePreferred -= sendEmail;
// to avoid leaking memory
customer.BecamePreferred += sendEmail;
}
public class CustomerBecamePreferredHandler : Handles<CustomerBecamePreferred> {
@krfong916
krfong916 / class_and_static_keyword.js
Last active May 31, 2019 21:17
es6 classes, prototypical inheritance, static keyword
class Food {
static isHealthy() {
return true
}
static isEdible() { // references it's own class
return this.isHealthy()
}
}
console.log(Food.isEdible())
@krfong916
krfong916 / gist:ef92adbcba573372735fc117d110c69b
Created January 8, 2019 05:54
event loop example, tasks, queueing
// what is the order of the statements logged to the console?
console.log('script start');
setTimeout(function() {
console.log('setTimeout');
}, 0);
Promise.resolve().then(function() {
console.log('promise1');
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.3.1/redux.js"></script>
<script src="https://fb.me/react-with-addons-0.14.7.js"></script>
<script src="https://fb.me/react-dom-0.14.7.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-redux/4.4.0/react-redux.js"></script>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:600,700' rel='stylesheet' type='text/css'>
@krfong916
krfong916 / prototypal_object_creation_1.js
Created November 30, 2018 06:41
prototypal object creation with change of property
function sideEffects() {
console.log("this will have a side effect because thats how the object prototype mechanism just works");
}
var User = function({first_name, last_name, language, num_friends, num_reports, college, active}) {
var obj = Object.create(User.prototype)
obj.first_name = first_name
obj.last_name = last_name
obj.language = language
@krfong916
krfong916 / object_prototype_constructor_call.js
Created November 30, 2018 05:39
Ways not to instantiate an object
function sideEffects() {
console.log("this will have a side effect because thats how the object prototype mechanism just works");
}
function Bar () {
console.log(`hey no side effects, we're all good!`);
}
Bar.prototype = new sideEffects();
@krfong916
krfong916 / gist:2a4a0a7429612a3b64b01bd1e64e8012
Created November 13, 2018 23:59
lexical this and this properties
// lexical this and this properties
function test() {
setTimeout(() => {
console.log(this.a)
}, 1000);
}
let a = 2;
test();
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">