Skip to content

Instantly share code, notes, and snippets.

@jonathanws
jonathanws / prompt3.js
Last active December 10, 2020 07:14
Prompt 3
const input = {
a: {
b: {
c: 12,
d: "Hello World",
},
e: [1, 2, 3],
},
hi: "there",
checks: {
const strings = ['boo', 'bar', 'biz', 'baz']
// piece everything together
console.log(strings.join()). // boo,bar,biz,baz
// or add a delimiter, like '\n'
console.log(strings.join('\n')) // boo\nbar\nbiz\baz
// find strings that match our condition
console.log(strings.filter((s) => s.includes('a'))) // [ 'bar', 'baz' ]
@jonathanws
jonathanws / mocking-with-sinon-sandbox.js
Last active October 5, 2021 19:41
Testing AWS services with Sinon mocks in Lambda
/**
* Writing tests for functions that use external dependencies is tough.
* We can get past this by using sinon sandboxes to temporarily overwrite the
* prototypes of those dependencies, just for testing
*
* Before running these tests run:
* $ npm install --save-dev aws-sdk sinon mocha
*/
/**
/**
* Document module
*
* This module serves as a basic CRUD implementation of 'document' objects.
* It is meant to be consumed by a frontend webapp and used to talk to an API.
*/
// Import the Axios instance with our backend information
import { api } from '@/constants/globals.constant'
@jonathanws
jonathanws / gist:5538378
Created May 8, 2013 05:17
Use HTTPPost to send JSON to Postresql server
package com.towson.wavyleaf;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
@jonathanws
jonathanws / gist:5228795
Created March 23, 2013 18:11
Modified from http://support.ntp.org/bin/view/Support/JavaSntpClient Modified to allow user to enter the name of the ntp server (i used north-america.pool.ntp.org), send three requests and print average roundtrip times, and print the last packet's server request time.
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.text.DecimalFormat;
import java.util.Scanner;
/**
* NtpClient - an NTP client for Java. This program connects to an NTP server
// THIS IS A BETA! I DON'T RECOMMEND USING IT IN PRODUCTION CODE JUST YET
/*
* Copyright 2012 Roman Nurik
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0