- Solve all problems using JavaScript
-
Write a function that returns an array with the first
n
powers of 2. Call ittwoPow
. -
Use
twoPow
andArray.prototype.reduce
to the sum of the first 10 powers of 2. -
Describe this call signature:
Buffer.prototype.pprint = function() { | |
var line = ""; | |
if(this.length > 0) { | |
for(var i=0; i<this.length; i++) { | |
if(i%8==0) { | |
sys.print(" "); | |
} | |
if(i%16==0) { | |
sys.print(line); | |
line = ""; |
// For each of the following code fragments: | |
// a. what does the code do? | |
// b. what did the author intend for it to do? | |
// c. how would you fix it? | |
// NOTE: all code samples work exactly the same in all browsers | |
// 1. object literals | |
var data = [ { high: 100, low: 81 }, { high: 93, low: 73 }, { high: 60, low: 32 } ]; | |
function getAverages(data) { | |
var avgs = []; |
/* | |
A simple newline delimited JSON protocol. | |
Receiving Usage: | |
protocol = require('./json-protocol'); | |
// parsing data | |
parser = protocol.StreamParser(); |
This is about getting rid of Dependency Injection Container and DI practices taken from Java. Good bye Java, viva la PHP!
We start with common example. Session.
<?php
class SessionStorage {
function __construct()
#!/bin/bash | |
# list of programs we depend on | |
progs="xdpyinfo grep head sed ffmpeg pacat parec sox" | |
# check for programs we depend on | |
result=0 | |
for prog in $progs | |
do | |
type -p $prog > /dev/null |
var foo = require('./foo') | |
, barOfFoo = moduleOfModule('./bar', './foo') | |
function moduleOfModule(module, ofModule) { | |
var c = require.cache[require.resolve(ofModule)] | |
, f = require.resolve(module, c) | |
, r | |
c.children.some(function(c) { | |
if(c.filename === f) { | |
r = c.exports |
#! /usr/bin/env bash | |
function nEnabled { | |
system_profiler -detailLevel mini SPAirPortDataType | grep -e 'Supported PHY Modes: .*n' | |
} | |
until nEnabled && sleep 2 && nEnabled; | |
do | |
echo 'resetting airport' | |
networksetup -setairportpower en1 off; networksetup -setairportpower en1 on |
JSON._dateReviver = function (k,v) { | |
if (v.length !== 24 || typeof v !== 'string') return v | |
try {return new Date(v)} | |
catch(e) {return v} | |
} | |
JSON.parseWithDates = function (obj) { | |
return JSON.parse(obj, JSON._dateReviver); | |
} |