Skip to content

Instantly share code, notes, and snippets.

Avatar

WORMSS WORMSS

View GitHub Profile
@WORMSS
WORMSS / SinglePicker.vue
Created Mar 18, 2020
Pushing data into notes doesn't seem to be enough to trigger an update
View SinglePicker.vue
<template>
<div>
<Note v-for="note of noteProperties" :key="note.text" :properties="note" />
</div>
</template>
<script>
import { Component, Mixins } from 'vue-property-decorator';
@Component({ components: { Note } })
@WORMSS
WORMSS / types.d.ts
Last active Dec 1, 2020
Typescript: My advanced types I don't want to lose
View types.d.ts
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 Jul 7, 2017
Example code for uploading a file with express and multer
View express-upload-multer-example
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 Jul 5, 2017
Mongo Connection Sharing
View MongoUtils.js
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 Apr 18, 2017
micro-rest-api-server
View micro-rest-api-server.js
// 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 Apr 28, 2017
Express MethodOverride
View index.js
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"));
View micro-route-test.js
const Express = require("Express");
const app = new Express();
app.route("/path")
.get((req, res) => {
res.send("get yay");
})
.post((req, res) => {
res.send("post yay");
});
@WORMSS
WORMSS / flitetest.js
Created Feb 17, 2017
View parts of Express.Route
View flitetest.js
const Router = require("express").Router;
///........
const ensuredLoggedIn = require('connect-ensure-login').ensureLoggedIn();
var app = new Router();
app.get("/", ensuredLoggedIn, (req, res) => {
// .............
});
@WORMSS
WORMSS / index.js
Created Feb 17, 2017
A snippet of my Express.Route for OAuth
View index.js
/*
Some extra stuff for setting up the server
*/
// Setting up bare passport. No Auth Strategy.
const passport = require("./middlewear/my-passport-init");
app.use(passport.initialize());
app.use(passport.session());
// Setting up passport Strategies and Routes
@WORMSS
WORMSS / pi startup
Last active Mar 29, 2016
First things to do when setting up the RaspberryPi
View pi startup
## Installing Chrome on Rasbian ##
# https://www.raspberrypi.org/forums/viewtopic.php?t=121195 #
wget https://dl.dropboxusercontent.com/u/87113035/chromium-browser-l10n_48.0.2564.82-0ubuntu0.15.04.1.1193_all.deb -P ~/Downloads/
wget https://dl.dropboxusercontent.com/u/87113035/chromium-browser_48.0.2564.82-0ubuntu0.15.04.1.1193_armhf.deb -P ~/Downloads/
wget https://dl.dropboxusercontent.com/u/87113035/chromium-codecs-ffmpeg-extra_48.0.2564.82-0ubuntu0.15.04.1.1193_armhf.deb -P ~/Downloads/
sudo dpkg -i ~/Downloads/chromium-codecs-ffmpeg-extra_48.0.2564.82-0ubuntu0.15.04.1.1193_armhf.deb
sudo dpkg -i ~/Downloads/chromium-browser-l10n_48.0.2564.82-0ubuntu0.15.04.1.1193_all.deb ~/Downloads/chromium-browser_48.0.2564.82-0ubuntu0.15.04.1.1193_armhf.deb
## So Chrome shows up in the Application Launch Bar ##