Skip to content

Instantly share code, notes, and snippets.

View circa10a's full-sized avatar

Caleb Lemoine circa10a

View GitHub Profile
@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',
@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 / 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 / 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 / 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 / joi-usage.js
Last active September 27, 2019 01:02
example usage of joi object schema validation
const Joi = require('joi');
const schema = Joi.object().keys({
birthyear: Joi.number().integer().min(1900).max(2013),
test: Joi.string(),
}).without('birthyear', 'test');
let result = Joi.validate({ birthyear: 2013 }, schema);
// No error
result.error ? console.log(result.error) : console.log('schema valid\n');
@circa10a
circa10a / request_futures.py
Last active August 20, 2018 17:34
request_futures sample usage
from requests_futures.sessions import FuturesSession
import os
urls = []
num_workers = os.cpu_count()
session = FuturesSession(max_workers=num_workers)
while urls:
futures = []
for i in range(num_workers):
if not urls:
break
@circa10a
circa10a / kill_docker_containers.py
Created September 15, 2018 03:13
Kill all running docker containers via python
#!/usr/bin/env python3
import docker
client = docker.from_env()
for container in client.containers.list():
print(container.image.tags[0])
container.kill()
client.containers.list()
@circa10a
circa10a / get_running_containers_info.py
Created September 16, 2018 19:35
get running docker container info
#!/usr/bin/env python3
import docker
client = docker.from_env()
kwargs = {
"image":'alpine:3.8',
"name": 'test',
"command": 'tail -f /dev/null',
"detach": True,
@circa10a
circa10a / run_ouroboros.sh
Last active January 19, 2019 04:29
run_ouroboros_medium
docker run -d --name ouroboros \
-v /var/run/docker.sock:/var/run/docker.sock \
pyouroboros/ouroboros