Skip to content

Instantly share code, notes, and snippets.

View circa10a's full-sized avatar

Caleb Lemoine circa10a

View GitHub Profile
@circa10a
circa10a / tinydb.py
Last active February 18, 2019 20:41
tinydb python usage
from tinydb import TinyDB, Query
db = TinyDB('./test.db')
query = Query()
usersObj = [
{
'name':'jim',
'age': 24
},
{
@circa10a
circa10a / minimizeJs.sh
Last active July 3, 2018 19:45
One line to safely minimize js files using sed(there will be single spaces left to not break variable assignment)
# Requires appropriate semi-colons
FILE_PATH=$(pwd); for i in $(ls $FILE_PATH/*.js); do sed -i 's|//.*||g; /\/\*/,/*\//d; /^\s*$/d;' $i && sed -i ':a;N;$!ba;s/\n/ /g; s/ //g' $i; done
# Before
# const os = require('os');
# function num(num){
# return 5 + num
# }
# // Sample Comment
@circa10a
circa10a / matchObjects.js
Last active June 30, 2018 21:19
Filter an array of objects with key/value pairs
const _ = require('underscore');
arr = [
{
car: "toyota",
color: "blue",
year: 2010,
trans: "auto",
warrantyEnd: "2013"
},
{
@circa10a
circa10a / reverse-array.js
Last active March 25, 2019 02:17
javascript reverse array (no helper methods)
const arr = [1, 2, 3, 4, 5];
const newArr = [];
for(i = arr.length; i >=arr[0]; i--) {
newArr.push(i);
}
console.log(newArr); // [ 5, 4, 3, 2, 1 ]
/* with helper method (recommended)
@circa10a
circa10a / easy-soap-request-test.js
Last active January 24, 2020 11:41
medium mocha and chai test example
const fs = require('fs');
const { expect } = require('chai');
const soapRequest = require('../index');
const url = 'https://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php';
const urlFail = 'https://graphical.weather.gov:80/xml/SOAP_server/ndfdXMLserver.php';
const headers = {
'user-agent': 'easy-soap-request-test',
'Content-Type': 'text/xml;charset=UTF-8',
SOAPAction: 'https://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl#LatLonListZipCode',
const soapRequest = require('easy-soap-request');
const fs = require('fs');
// example data
const url = 'https://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php';
const sampleHeaders = {
'user-agent': 'sampleTest',
'Content-Type': 'text/xml;charset=UTF-8',
'soapAction': 'https://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl#LatLonListZipCode',
};
@circa10a
circa10a / easy-soap-request-index.js
Last active May 24, 2021 23:02
easy-soap-request-index.js
const axios = require('axios-https-proxy-fix');
/**
* @author Caleb Lemoine
* @param {object} opts easy-soap-request options
* @param {string} opts.url endpoint URL
* @param {object} opts.headers HTTP headers, can be string or object
* @param {string} opts.xml SOAP envelope, can be read from file or passed as string
* @param {int} opts.timeout Milliseconds before timing out request
* @param {object} opts.proxy Object with proxy configuration
@circa10a
circa10a / curl_noaa.sh
Last active April 2, 2018 00:19
medium curl command
curl -H "soapAction: \"https://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl#LatLonListCityNames\"" -H "Content-Type: text/xml;charset=UTF-8" --data @test.xml https://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php
@circa10a
circa10a / response.xml
Created April 1, 2018 20:31
medium WSDL response
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:LatLonListZipCodeResponse xmlns:ns1="https://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl">
<listLatLonOut xsi:type="xsd:string">&lt;?xml version='1.0'?&gt;&lt;dwml version='1.0' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='https://graphical.weather.gov/xml/DWMLgen/schema/DWML.xsd'&gt;&lt;latLonList&gt;32.9612,-96.8372&lt;/latLonList&gt;&lt;/dwml&gt;</listLatLonOut>
</ns1:LatLonListZipCodeResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
@circa10a
circa10a / regex.sh
Created December 18, 2017 20:51
bash regex
[[ $input=~ [A-Za-z0-9-]+\/[A-Za-z0-9-]+\:[A-Za-z0-9-]+ ]]; then