This file contains hidden or 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
| const cls = require('cls-hooked'); | |
| const generate = require('nanoid/generate'); | |
| const alphaNumeric = '0123456789abcdefghijklmnopqrstuvwxyz'; | |
| const requestTracingNamespace = cls.createNamespace('request-tracing'); | |
| //.. middleware: https://gist.github.com/endeepak/4b8a07abfdf07964ea85d9cde44e02b9 | |
| const trace = async (tracingId, method) => { | |
| requestTracingNamespace.run(async () => { |
This file contains hidden or 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
| const requestTracing = require('request-tracing'); // Wrapper library to read the tracing information from CLS context | |
| class SNSEventPublisher { | |
| constructor(sns, topicNameToArnMap) { | |
| this.sns = sns; | |
| this.topicNameToArnMap = topicNameToArnMap; | |
| } | |
| async publish(topicName, message) { | |
| const messageAttributes = {}; |
This file contains hidden or 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
| const request = require('request-promise'); | |
| const requestTracing = require('request-tracing'); // Wrapper library to read the tracing information from CLS context | |
| const requestPromiseWrapper = async (body) => { | |
| const requestBody = Object.assign({}, body); | |
| requestBody.headers['X-Tracing-Id'] = requestTracing.getTracingId(); // Same as requestTracingNamespace.get('tracingId'); | |
| return request(requestBody); | |
| }; |
This file contains hidden or 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
| const { createLogger, transports, format } = require('winston'); | |
| const {combine, printf} = format; | |
| const requestTracing = require('request-tracing'); // Wrapper library to read the tracing information from CLS context | |
| const loggerFormat = printf((info) => { | |
| const tracingId = requestTracing.getTracingId(); // Same as requestTracingNamespace.get(tracingIdContextKeyName); | |
| let formatObject = `${info.level || '-'} ${info.timestamp || '-'} ${tracingId || '-'} ${info.message}`; | |
| // ... | |
| return formatObject; | |
| }); |
This file contains hidden or 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
| const cls = require('cls-hooked'); | |
| const generate = require('nanoid/generate'); | |
| const alphaNumeric = '0123456789abcdefghijklmnopqrstuvwxyz'; | |
| const requestTracingNamespace = cls.createNamespace('request-tracing'); | |
| const middleware = () => { | |
| return (req, res, next) => { | |
| requestTracingNamespace.bindEmitter(req); | |
| requestTracingNamespace.bindEmitter(res); |
This file contains hidden or 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
| var schedule = require('node-schedule'); | |
| schedule.scheduleJob('30 * * * *', function(){ | |
| doTheJob(); | |
| }); |
This file contains hidden or 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
| document.querySelectorAll('h1,h2,h3,h4,strong').forEach(function(header) { | |
| console.log(' '.repeat(header.tagName.replace('STRONG', 'H5').replace('H', '')) + header.textContent) | |
| }); |
This file contains hidden or 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
| #!/usr/bin/env bash | |
| if [ "$#" -ne 1 ] | |
| then | |
| echo "Usage: $0 <db_name>" | |
| exit 1 | |
| fi | |
| db_name=$1 |
This file contains hidden or 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
| HttpGet httpGet = new HttpGet("https://en.wikipedia.org/wiki/List_of_least_concern_birds"); | |
| HttpResponse httpResponse = client.execute(httpGet); | |
| String responseHtml = IOUtils.toString(httpResponse.getEntity().getContent()); | |
| assertThat(responseHtml.length(), greaterThan(16348)); |
This file contains hidden or 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
| // Motor Code Adopted From: http://www.instructables.com/id/Control-your-motors-with-L293D-and-Arduino/?ALLSTEPS | |
| // Ping Code Adopted From: https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home#!single-pin-sketch | |
| #include <NewPing.h> | |
| #define PING_PIN 12 // Arduino pin tied to both trigger and echo pins on the ultrasonic sensor. | |
| #define PING_MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm. | |
| NewPing sonar(PING_PIN, PING_PIN, PING_MAX_DISTANCE); // NewPing setup of pin and maximum distance. |
NewerOlder