A Pen by Surinder pal Singh on CodePen.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs = require 'fs' | |
exports.countryIpCounter = (countryCode, cb) -> | |
return cb() unless countryCode | |
fs.readFile "#{__dirname}/../data/geo.txt", 'utf8', (err, data) -> | |
if err then return cb err | |
counter = 0 | |
data = data.toString() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
through2 = require 'through2' | |
module.exports = -> | |
words = 0 | |
lines = 1 | |
transform = (chunk, encoding, cb) -> | |
# Count lines | |
if chunk.match(/\n/mg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Replaces any parameter placeholders in a query with the value of that | |
* parameter. Useful for debugging. Assumes anonymous parameters from | |
* $params are are in the same order as specified in $query | |
* | |
* @param string $query The sql query with parameter placeholders | |
* @param array $params The array of substitution parameters | |
* @return string The interpolated query | |
* | |
* @link https://stackoverflow.com/questions/210564/getting-raw-sql-query-string-from-pdo-prepared-statements |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Return current date object according to given timezone. Date will be return based on system's timezone an error occured while parsing | |
* | |
* @param timezone Timezone string e.g. `America/Los_Angeles` | |
* @returns {Date} | |
*/ | |
function currentDate(timezone) { | |
try { | |
return new Date(new Date().toLocaleString("en-US", {timeZone: timezone})); | |
} catch (error) { |
Picking the right architecture = Picking the right battles + Managing trade-offs
- Clarify and agree on the scope of the system
- User cases (description of sequences of events that, taken together, lead to a system doing something useful)
- Who is going to use it?
- How are they going to use it?