munificent / journal Goto Github PK
View Code? Open in Web Editor NEWMy blog, in all its statically-generated glory.
Home Page: http://journal.stuffwithstuff.com/
My blog, in all its statically-generated glory.
Home Page: http://journal.stuffwithstuff.com/
Using decorator pattern instead of super feels more js. :)
R = require 'ramda'
log = console.log
# ## orignal impl
makeCounter = ( count = 0 ) ->
get = -> count
inc = -> count = count + 1
set = (x) -> count = x
{get, inc, set}
# # decorate pattern
#
# Wrap a function inside another to allow you to
# make adjustments to the parameters,
# or do other processing either before the internal function
# is called or with its results.
logIt = (msg, f) ->
R.wrap f, (func, arg) ->
log msg
func(arg)
# ## V1
makeLoggingCounter = ( count = 0 ) ->
set = logIt 'set!', (x) -> count = x
get = logIt 'get!', -> count
inc = logIt 'inc!', -> count = count + 1
{get, inc, set}
# ## V2
mkLoggedCounter = () ->
c = makeCounter()
get = logIt 'get!', c.get
inc = logIt 'inc!', c.inc
set = logIt 'set!'. c.set
{get, inc, set}
The “
and ”
entities are undefined in firefox, rss2email (a python based reader) and the w3 feed validator https://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Fjournal.stuffwithstuff.com%2Fatom.xml.
function makeSundaeOriginal(callback) {
scoopIceCream(function (iceCream) {
warmUpCaramel(function (caramel) {
callback(pourOnIceCream(iceCream, caramel));
});
});
}
scoopIceCream and warmUpCaramel are used only for side-effect?
pourOnIceCream is used though.
let me assume the intention is this
function makeSundae(callback) {
return function (iceCream) {
return function (caramel) {
return callback(pourOnIceCream(iceCream, caramel));
};
};
}
// try to simplify that
var _ = require('ramda'),
add = _.curry(function (a, b) { return a + b }),
pourOnIceCream = add
log = console.log;
//step 1
var makeSundaeSimpl = function (callback) {
return _.compose(callback, pourOnIceCream)
};
// step 2
var makeSundaeSimpl = function (callback, pourOnIceCream) {
_.compose(callback, pourOnIceCream)
};
// step 3
var makeSundaeSimpl = _.compose;
makeSundaeSimpl(log, add)(1, 2)
YES! makeSundae is the good old compose.
Or composeP if callback and pourOnIceCream are promises.
http://ramdajs.com/0.15/docs/#composeP
We don't need to defined it ourselves.
But we need to pass in the argument iceCream and caramel together.
// get fancy?
var g = _.curry(function (cb, f, a, b) {
cb(f(a,b))
});
g(log, add)(1, 2)
g(log, add)(1)(2)
g(log)(add)(1, 2)
g(log)(add)(1)(2)
// => all log 3 to screen
callbcak, warmUpCaramel and scoopIceCream will be called in the order of the orignal function. They can be promise functions or regular functions. pipeP can handle both. Use async.seq if you like.
var R = require('ramda'),
v1,
add,
warmUpCaramel,
scoopIceCream,
log = console.log;
v1 = R.curry(function (callback, iceCream, caramel) {
var f = function () {
return callback(iceCream, caramel);
};
R.pipeP(f, warmUpCaramel, scoopIceCream)();
});
add = function (a, b) {
log('add', a + b);
return a + b;
};
warmUpCaramel = function (x) {
log('warmUpCaramel', x);
return x;
};
scoopIceCream = function (x) {
log('warmUpCaramel', x);
return x;
};
v1(add, 1,2)
v1(add)(1,2)
v1(add)(1)(2)
// all log to console
// add 3
// warmUpCaramel 3
// warmUpCaramel 3
That's because in the original funciton, all helper functions are defined somewhere else. Taking that approch, the function most likely mimic the orignal one would be:
var R = require('ramda'),
v1;
v1 = R.curry(function (callback, iceCream, caramel) {
var f = function () {
return callback(iceCream, caramel);
};
R.pipeP(f, warmUpCaramel, scoopIceCream)();
});
Hey
looks like your README file says 2008-2011. I know it must be so glorious at Google that you forget time entirely, but pls update. ๐
I've been playing with the idea of starting a blog and yours was one of the templates I tried out. I had some problems building your blog with Jekyll. Jekyll was producing empty HTML files. I tracked the error to here.
I discovered that to build your blog, I had to have the following versions of software due to incompatibility with pygments:
I had to uninstall Python 3 and install 2.7.6, and uninstall Pygments 0.5.4 and install 0.5.0. It also complained about missing the magpie lexer. These problems can of course be fixed by deleting the posts that contain code. I was starting from scratch so deleting all posts makes sense for me. Nevertheless, I thought I'd just create an issue in case some other chap tries to build the blog.
On mobile browsers the embedded video on http://journal.stuffwithstuff.com/2020/04/05/crafting-crafting-interpreters/ is, too wide causing the layout to break.
Tested on a Nokia 6.1 with Android 10 and Firefox, Firefox Preview and Chrome
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.