Skip to content

Instantly share code, notes, and snippets.

View WORMSS's full-sized avatar

WORMSS WORMSS

View GitHub Profile
@WORMSS
WORMSS / battery-highest-value.ic10
Last active May 17, 2024 07:07
Stationeers Quick Little Patterns
alias Counter r0
alias CurrentValue r1
alias KnownHighest r2
alias KnownHighestValue r3
alias Housing db
s Housing Setting -1
reset:
move Counter 0
@WORMSS
WORMSS / ws.js
Last active June 26, 2023 08:59 — forked from tabjy/ws.js
WebSocket from scratch. In Node.js
const http = require('http')
const crypto = require('crypto')
const server = http.createServer((req, res) => {
console.log('got request', req.url)
res.writeHead(200, { 'Content-Type': 'text/plain' })
res.end('okay')
})
server.on('upgrade', function (req, socket) {
@WORMSS
WORMSS / ApiBuilder.ts
Last active March 15, 2022 12:50
Mini Api Builder
type URLSearchParamsInit = ConstructorParameters<typeof URLSearchParams>[0];
type ApiFormatMap = {
arrayBuffer: ArrayBuffer;
text: string;
json: object;
formData: FormData;
blob: Blob;
stream: ReadableStream<Uint8Array>;
response: Response;
};
@WORMSS
WORMSS / gitcommands.md
Last active October 20, 2021 10:18
Git Commands I usually forget but need maybe once every 2 years

Git Get Remote Sha:

$ git fetch origin <sha>

Git Octopus merge staging:

Make sure the staging area is how you want the commit to be

$ git write-tree
@WORMSS
WORMSS / types.d.ts
Last active December 1, 2020 13:26
Typescript: My advanced types I don't want to lose
type Optional<T, K extends keyof T = keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
type AllOrNothing<T> = T | Partial<Record<keyof T, never>>;
type OnlyOne<T> = {
[K in keyof T]: (
Required<Pick<T, K>> & Partial<Record<Exclude<keyof T, K>, never>>
)
}[keyof T];
type Test = {
@WORMSS
WORMSS / express-upload-multer-example
Created July 7, 2017 12:32
Example code for uploading a file with express and multer
const express = require("express");
const multer = require("multer");
const upload = multer({"dest": "./mult"});
const app = express();
app.get("/", indexHandler);
app.post("/save", upload.single("fileField"), saveHandler);
@WORMSS
WORMSS / MongoUtils.js
Last active July 5, 2017 13:50
Mongo Connection Sharing
var _db;
module.exports = {
connect: function ({host = "localhost", port = 27017, dbname = "exampleDb"} = {}) {
return require("mongodb").MongoClient.connect(`mongodb://${host}:${port}/${dbname}`)
.then(db => _db = db);
},
collection: function (col_name) {
if ( !_db ) {
return null;
@WORMSS
WORMSS / micro-rest-api-server.js
Last active April 18, 2017 13:27
micro-rest-api-server
// imports
const Express = require("express");
const bodyParser = require("body-parser");
// Some datastore to play with.
const bookDb = initDb();
// Set up express app.
const app = new Express();
@WORMSS
WORMSS / index.js
Last active April 28, 2017 08:20
Express MethodOverride
const Express = require("express");
const methodOverride = require("method-override");
const app = new Express();
const router = new Express.Router();
//app.use(methodOverride("_method", {"methods": ["POST", "GET"]})); // Works too.
router.use(methodOverride("_method", {"methods": ["POST", "GET"]})); // on route so only the following use the method override.
router.get("/:id", all("get"));
@WORMSS
WORMSS / flitetest.js
Created February 17, 2017 14:43
View parts of Express.Route
const Router = require("express").Router;
///........
const ensuredLoggedIn = require('connect-ensure-login').ensureLoggedIn();
var app = new Router();
app.get("/", ensuredLoggedIn, (req, res) => {
// .............
});