Skip to content

Instantly share code, notes, and snippets.

View gkhays's full-sized avatar

Garve Hays gkhays

View GitHub Profile
@gkhays
gkhays / Download File with Node.md
Created February 27, 2020 17:26
Download a file from a URL using Node.js

Download File from URL

Proof-of-concept to download a file from a URL and save it locally. For example, I may wish to retrieve a JAR file from Nexus.

Uses the http package, which does the basics with raw HTTP protocol support.

Possible update: use request, it is like the Python's requests library. There is a companion package called node-request-progress that tracks download progress. See request-progress on GitHub.

Note: The request package has been deprecated.

@gkhays
gkhays / DrawSineWave.html
Last active March 9, 2024 19:05
Oscillating sine wave, including the steps to figuring out how to plot a sine wave
<!DOCTYPE html>
<html>
<head>
<title>Sine Wave</title>
<script type="text/javascript">
function showAxes(ctx,axes) {
var width = ctx.canvas.width;
var height = ctx.canvas.height;
var xMin = 0;
@gkhays
gkhays / Apache Commons and Log4J Logging.md
Last active January 19, 2024 13:52
Logging with Log4j and Apache Commons

Apache Commons and Log4J Logging

This article illustrates a quick start to using Log4J and commons logging. Obtaining a log factory and logging to various levels is fairly straight-forward. What can be tricky is getting the properties files correct. The code snippet below depends on:

  • commons-logging-1.1.jar
  • log4j-1.2.16.jar
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@gkhays
gkhays / Javadoc-Markdown.md
Last active November 21, 2023 14:26
Using Markdown in Javadoc

Background: A Google search led me to the source code (on GitHub) for ng_model.ts#L124 wherein it looked like the documentation was Javadoc, but with Markdown syntax.

...
* ### Setting the ngModel name attribute through options
*
* The following example shows you an alternate way to set the name attribute. The name attribute is used
* within a custom form component, and the name `@Input` property serves a different purpose.
*
* ```html
@gkhays
gkhays / ListResources.java
Last active October 16, 2023 12:55
How to load resources and files in Java
package org.gkh;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.Scanner;
@gkhays
gkhays / build.sh
Created November 1, 2022 19:13
Golang Build Script
#!/bin/bash
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
go build \
-a \
-v \
-trimpath='true' \
-buildmode='exe' \
-buildvcs='true' \
-compiler='gc' \
@gkhays
gkhays / ButtonPush.md
Last active September 21, 2022 22:22
What does it take to push this button?

Are We Going to Push the Button?

tenor-2697319374

@gkhays
gkhays / ReadFile.md
Last active July 7, 2022 20:03
Some methods to read a file from disk into a string.

Read a File from Disk into a String

Various methods for reading the contents of a file from disk into a string.

Using NIO

One-liner bonus! 😄

String contents = new String(Files.readAllBytes(Paths.get(fileName)));

GitHub README Statistics

image

Alternatives

I like pie!