Skip to content

Instantly share code, notes, and snippets.

@mitchallen
mitchallen / publish.yml
Last active September 16, 2023 19:47
Example GitHub Action workflow to publish a docker container image
name: publish
on:
push:
tags:
- 'v*'
jobs:
publish-docker-image:
runs-on: ubuntu-22.04
timeout-minutes: 10
@mitchallen
mitchallen / Dockerfile
Created March 2, 2023 03:19
A simple Docker file for turning a NodeJS Web project into a container
# Use an official Node.js runtime as a parent image
FROM node:14
# Set the working directory to /app
WORKDIR /app
# Copy package.json and package-lock.json to the container
COPY package*.json ./
# Install dependencies
@mitchallen
mitchallen / server.js
Last active March 13, 2023 02:41
A very simple Node.js Web Server
/**
* Author: Mitch Allen
* https://scriptable.com
* https://mitchallen.com
*/
const express = require('express');
const app = express();
const port = 3000;
@mitchallen
mitchallen / popup.html
Created February 26, 2023 20:06
Example popup.html for a Chrome Extension
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="button.css">
</head>
<body>
<button id="changeColor"></button>
<script src="popup.js"></script>
</body>
</html>
@mitchallen
mitchallen / options.html
Created February 26, 2023 11:21
Example options.html file for a Chrome Extension (Manifest V3)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Options Page</title>
</head>
<body>
<h1>Options Page</h1>
<form>
<label for="color-input">Page Background Color:</label>
@mitchallen
mitchallen / background.js
Created February 26, 2023 11:05
Example background.js file for a Chrome Extension
console.log("Background script loaded!");
chrome.browserAction.onClicked.addListener(function(tab) {
// Do something when the extension button is clicked
});
@mitchallen
mitchallen / content.js
Last active February 26, 2023 20:07
Example content.js file for a Chrome Extension
console.log("Hello, world!");
chrome.storage.sync.get("color", function(data) {
var color = data.color || "#ffffff";
document.body.style.backgroundColor = color;
});
@mitchallen
mitchallen / manifest.json
Last active February 26, 2023 20:08
Example Manifest V3 Chrome Extension File
{
"name": "My Extension",
"version": "1.0",
"manifest_version": 3,
"description": "Description of my extension",
"permissions": [
"tabs",
"activeTab"
],
"content_scripts": [
@mitchallen
mitchallen / server-post.go
Created February 21, 2023 10:32
Example of how to create a Gin POST url
r.POST("/users", func(c *gin.Context) {
var user struct {
Name string `json:"name"`
Email string `json:"email"`
}
if err := c.BindJSON(&user); err != nil {
c.JSON(400, gin.H{"error": err.Error()})
return
}
// TODO: create user in database
@mitchallen
mitchallen / server-get.go
Created February 21, 2023 10:30
Example of how to add a Gin GET url
r.GET("/users", func(c *gin.Context) {
users := []string{"Alice", "Bob", "Charlie"}
c.JSON(200, gin.H{
"users": users,
})
})