One thing I've realized is that, no matter what the syntax and style of the code, conciseness and organization are two of the biggest factors that make good code, good. No one wants to sit there for hours reading line after line of code! We have to use things like modularity -- A module encapsulates related code into a single unit of code-- and recursion to keep our code short and easy to understand
.... just realized lower time-complexity is a factor too! The amount of memory the computer has to expend to run your code is very important.
Making good code is hard, and I am code-gay for all your good lookin' codes
I'm going to learn to clean the ugly off my code so I can make aspiring programmers like me code-gay for my beautiful code
1. Toy Problem
Function Bind
Implement the function ‘bind’, which accepts a function and a context as arguments. The context argument should override an existing context that the function is defined in. Your bind function should return the passed in function.
For example, if we have the following object:
var alice = {
name: 'alice',
shout: function () {
alert('here comes' + ' ' + this.name);
}
};
alice.shout() //=> 'here comes alice'
If you use your bind function with the context
{ name: 'bob' }
, as is shown here:boundShout = bind(alice.shout, { name: 'bob' })
Then calling
boundShout()
will alert 'here comes bob'
The following example should also work in the following way once your function is implemented:
var func = function(a, b){ return a + b };
var boundFunc = bind(func, null, 'diet');
boundFunc('coke'); //=> 'dietcoke'
Once you have finished that, implement the function ‘bind’ as a method of the Function.prototype object. This will be similar to your first solution, but should be able to be used in the following way:
var alice = {
name: 'alice',
shout: function () {
alert(this.name);
}
};
var boundShout = alice.shout.bind(alice);
boundShout(); // alerts 'alice'
boundShout = alice.shout.bind({ name: 'bob' });
boundShout(); // alerts 'bob'
DO NOT use the native bind() function in your solutions. You may use the functions call() and apply().
2. Lecture: Server side concepts
3. Video lecture: Data storage techniques
4. Pair programming on Web Historian sprint
In this sprint we were to create multiple Node services, relying on command-line server processes like Cron (a time-based background job scheduler used to schedule operating system jobs to run at fixed times) to build a duplicate of the archive.org internet archiving. Shown below is an example of what we have to make.
- A user types in a URL
- We check our storage if the archive for that URL exists
- If it does, we return that archive (a snapshot of the page when it was taken)
- If the page is not done loading, direct them to the "loading" page
- If it doesn't, we download a snapshot of that URL page and store it in our archives
- Write a script that will update the snapshots in our archives every minute (using CRON)
02.03.16
No comments:
Post a Comment