Skip to content

Instantly share code, notes, and snippets.

View bhuizi's full-sized avatar

Bryan Huizi bhuizi

View GitHub Profile
@bhuizi
bhuizi / regex.js
Last active December 13, 2018 16:19
JavaScript RegEx
//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";
@bhuizi
bhuizi / reduce.js
Created August 28, 2016 21:30
reduce data w/ array reduce
//01 transform
var data = [15, 3, 20];
var reducer = function(accumulator, item) {
return accumulator + item;
};
var initialValue = 0;
var total = data.reduce(reducer, initialValue);
@bhuizi
bhuizi / reduce.js
Created November 13, 2016 16:50
array reduce examples
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);
@bhuizi
bhuizi / learn_node.js
Last active December 21, 2018 22:46
learn_node
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 */
@bhuizi
bhuizi / get_zip_file.js
Created June 23, 2017 16:57
http_get_zip
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'))
@bhuizi
bhuizi / axios_get_pipe_zip.js
Last active October 27, 2021 14:09
axios get request w/ piping
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'));
@bhuizi
bhuizi / superagent_post.js
Created June 26, 2017 22:14
super agent example to return cookies
const request = require('superagent');
const agent = request.agent();
agent
.post(url)
.type('form')
.send(
{
username:"",
password:"^,W^.6ck",
redirectUrl: "''",
@bhuizi
bhuizi / request_post.js
Created June 27, 2017 00:01
post request: using request
// superagent example https://github.com/request/request#streaming
const request = require('request');
const obj = {
username: 'string',
password: 'string',
redirectUrl: 'string',
sso: 'string'
};
@bhuizi
bhuizi / reducer.js
Created July 8, 2017 08:06
array reducer
const answers = [
{
name: 'offense1',
value: 'offense1 value'
},
{
name: 'offense2',
value: 'offense2 value'
},
{
@bhuizi
bhuizi / spread reduce arrays
Last active July 18, 2017 13:51
spread reduce arrays
const offenseAnswer = [
{
name: 'offense1',
value: 'offense1 value'
},
{
name: 'offense2',
value: 'offense2 value'
},
{