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
//file ext | |
(/\.(gif|jpg|jpeg|tiff|png)$/i).test(filename) | |
//match numbers | |
var regex = new RegExp("\\+?\\(?\\d*\\)? ?\\(?\\d+\\)?\\d*([\\s./-]?\\d{2,})+", "g") | |
,string = "testing testing one 800-999-9999" | |
,arr = string.match(regex); | |
//remove numbers from string => format | |
var string = "diplomat 999-555-5555"; |
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
//01 transform | |
var data = [15, 3, 20]; | |
var reducer = function(accumulator, item) { | |
return accumulator + item; | |
}; | |
var initialValue = 0; | |
var total = data.reduce(reducer, initialValue); |
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
basic example | |
var data = [30, 5], | |
initialValue = 0; | |
reducer = function(accumulator, initialValue){ | |
return accumulator + initialValue; | |
} | |
var newData = data.reduce(reducer, initialValue); | |
console.log('new data is', newData); |
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
const fs = require('fs'); | |
const path = require('path'); | |
const http = require('http'); | |
const read = require('./read'); | |
/*1. HELLO WORLD */ | |
//console.log('HELLO WORLD'); | |
/*2. BABY STEPS process.argv */ |
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
const http = require('http'); | |
const fs = require('fs'); | |
http.get(<path_to_zip_file>, (res) => { | |
const statusCode = res.statusCode; | |
const contentType = res.headers['content-type']; | |
let error; | |
if(statusCode !== 200){ | |
console.log(`Request failed, status code ${statusCode}`); | |
} else { | |
res.pipe(fs.createWriteStream('the.zip')) |
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
const axios = require('axios'); | |
const fs = require('fs'); | |
const url = <path_to_file> | |
axios({ | |
method: 'get', | |
url: url, | |
responseType:'stream' | |
}) | |
.then(res => { | |
res.data.pipe(fs.createWriteStream('new.zip')); |
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
const request = require('superagent'); | |
const agent = request.agent(); | |
agent | |
.post(url) | |
.type('form') | |
.send( | |
{ | |
username:"", | |
password:"^,W^.6ck", | |
redirectUrl: "''", |
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
// superagent example https://github.com/request/request#streaming | |
const request = require('request'); | |
const obj = { | |
username: 'string', | |
password: 'string', | |
redirectUrl: 'string', | |
sso: 'string' | |
}; |
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
const answers = [ | |
{ | |
name: 'offense1', | |
value: 'offense1 value' | |
}, | |
{ | |
name: 'offense2', | |
value: 'offense2 value' | |
}, | |
{ |
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
const offenseAnswer = [ | |
{ | |
name: 'offense1', | |
value: 'offense1 value' | |
}, | |
{ | |
name: 'offense2', | |
value: 'offense2 value' | |
}, | |
{ |
OlderNewer