Skip to content

Instantly share code, notes, and snippets.

View krfong916's full-sized avatar
🦁
Organizing for a brighter future

Kyle Fong krfong916

🦁
Organizing for a brighter future
  • University of California, Santa Cruz
View GitHub Profile
@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');
@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 / heap.js
Last active March 10, 2019 01:57
Implementation of a min-heap and heapsort
var MinHeap = {
_rootLevel: 1,
init: function() {
this.arr = []
this.level = this._rootLevel
},
insert: function(value) {
this.arr[this.level] = value
this._bubbleUp(this.level)
},
@krfong916
krfong916 / component-creation-react.js
Created May 31, 2019 21:08
A document detailing the tradeoffs we make in each of the ways that we can create components in React
// Component class
class Car extends Component {
constructor ( props ) {
super();
this.propertyA = this.propertyA.bind( this );
this.propertyB = this.propertyB.bind( this );
}
}
class ShoppingItem extends Component {
@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())

Scope and closure

What is scope?

Scope is the set of rules that determines how to locate a variable identifier and assign it a value

Compiler theory

How is code compiled? There are a few phases

  • Tokenizing: characters are broken into chunks - tokens
  • Lexing: when the tokenizer invokes the stateful parser rules to figure out whether a chunk is a distinct token or part of another token
  • Parsing: we build an Abstract Syntax Tree (AST) from a stream of tokens. The AST represents a structure of a program. For instance: the top-level node called a program and the children nodes could be a variable declarations and function declarations. The variable declarations have children nodes that describe properties of the variable.
import java.util.Scanner;
class Fibonacci {
/**
* We can represent the fibonacci sequence as an array
*/
int fibIterative (int n) {
// we define the size of array as n+2 to accomodate the base cases, f[0] & f[1]

This, objects, and es6 classes

Summary

In this document, we will cover the this keyword, object prototypes, uses of .call() and .apply(), lexical this, arrow functions, es6 classes, object behavior delegation, some class theory, and objects-linking-other-objects. Our motivation is to learn these concepts is that we must know the finer points of object creation, assignment of values, and behavior delegation in order to better understand Javascript.

This

The this keyword is a special mechanism in Javascript - it allows us to implicitly pass reference values to other objects. It is a source of frustration for many developer's, but it's not as complicated as they make it out to be. In this section, we'll cover the this keyword, how it functions, why it's useful, and how it can help us write more expressive code.
     this has nothing to do with where a function is declared, but everything to do with how a function is called. When a function is invoked, an act

var dfs = {
result: function(){
return {
test: []
}
},
setup: function() {
var test1 = this.result()
test1.test.push('a');
this.modify(test1)
@krfong916
krfong916 / git-commands.md
Last active January 12, 2020 12:09
Git commands

Change remote url

git remote set-url origin new.git.url/here

Migrating code to new repo

  • Create github repo
  • git remote set-url origin new.git.url/here
  • git init in repo to migrate
  • Prune/Cleanup the local references to remote branch
    • show branches to prune: git remote prune origin --dry-run
  • prune all branches: git remote prune origin