Skip to content

Instantly share code, notes, and snippets.

View xiaoyunyang's full-sized avatar
🎯
Focusing

Xiaoyun Yang xiaoyunyang

🎯
Focusing
View GitHub Profile
@xiaoyunyang
xiaoyunyang / closure_with_recursion_naive.js
Last active October 2, 2021 15:40
Closure Example - Recursion
var incrementUntil = function(max) { 
if(num >= max) return num 
num++
incrementUntil(max)
}
 
var num = 0
incrementUntil(3)
num //> 3
@xiaoyunyang
xiaoyunyang / closure_oo_example.js
Last active August 6, 2019 07:43
Closure Example - Object Oriented Programming
function Person(name) {
var secret = “secret!”
this.name = name
this.setName = function(newName) { this.name = newName }
this.setNameToFoo = function() { this.name = foo }
this.getSecret = function() { return secret }
}
 
var a = new Person(“Max”)
 
@xiaoyunyang
xiaoyunyang / express-handle-error.js
Last active January 20, 2018 05:33
Error Handling in Node/Express App
import express from 'express'
import path from 'path'
import fs from 'fs'
const app = express()
app.set("port", process.env.PORT || 3001)
// Middleware that serves static file ======================================
app.use('/static', (req, res, next) => {
@xiaoyunyang
xiaoyunyang / curry_1.scala
Last active January 20, 2018 04:30
Functional Programming in Scala
//Currying is when you break down a function that takes multiple arguments into a //series of functions that take part of the arguments.
//converts a function f of two arguments into a function of one argument that partially applies f.
def curry[A,B,C](f: (A,B) => C): A => (B => C) =
(a: A) => (b: B) => f(a,b)
//> curry: [A, B, C](f: (A, B) => C)A => (B => C)