Skip to content

Instantly share code, notes, and snippets.

View Arlen22's full-sized avatar

Arlen22

View GitHub Profile
@Arlen22
Arlen22 / leftpad.js
Last active September 14, 2023 18:49
function leftpad(content, length, pad){
// make sure this is a proper string
content = String(content);
// get the pad character if set (or if zero)
pad = String(pad || pad === 0 ? pad : '')[0];
// get the extra length we need to add, but not less than zero if it's already longer
var left = Math.max(length-content.length, 0);
// voila!
return pad.repeat(left) + content;
}
@Arlen22
Arlen22 / Auto LCD configs.txt
Last active June 22, 2023 14:14
Space Engineers Vectors Script 3
Center <<Cargo>>
Cargoall {T:Large Cargo Container}
Inventoryx T:* +Ingot
Inventoryx T:* +ice
Center <<Tanks>>
Tanks T:* Hydrogen
Tanks T:* Oxygen
Powertime
Powerstored T:*
@Arlen22
Arlen22 / babel.config.js
Created December 20, 2019 18:46
Next.js config that keeps getting stale on Mac OS High Sierra 10.13.6
module.exports = {
presets: ['@expo/next-adapter/babel'],
plugins: [
[
'module-resolver',
{
alias: {
'assets': './assets',
'cache': './cache',
'src': './src'
@Arlen22
Arlen22 / webpack.config.js
Created June 1, 2019 03:43
TypeScript project files
const path = require('path');
module.exports = {
entry: './src/index.ts',
target: "node",
mode: "development",
devtool: 'inline-source-map',
watch: true,
module: {
rules: [
// Written by @Arlen22 for TiddlyServer, modified for TiddlyWiki
/*
Call loadTiddlyWiki to load the datafolder specified at the mount path specified and
return the SimpleServer instance to be used for handling requests.
Requests may be handled by calling server.requestHandler(req, res)
The event emitter is included for future use. Open an issue at Arlen22/TiddlyServer to discuss further use.
*/
exports.loadTiddlyWiki = function loadTiddlyWiki(mount, folder, callback) {
@Arlen22
Arlen22 / tuple.ts
Created June 26, 2017 23:12
Tuple nonsense
interface TupleConstructor {
new <T0>(item0: T0)
: [T0];
new <T0, T1>(item0: T0, item1: T1)
: [T0, T1];
new <T0, T1, T2>(item0: T0, item1: T1, item2: T2)
: [T0, T1, T2];
new <T0, T1, T2, T3>(item0: T0, item1: T1, item2: T2, tem3: T3)
: [T0, T1, T2, T3];
@Arlen22
Arlen22 / statFolder.ts
Created May 30, 2017 01:03
A rather obtuse RxJS operator to take a path and list all the folders in it, doing a stat on each one and checking whether it contains a certain file. It should use stat on the file instead of readdir on the folder, but I'm not using this code!
export function statFolderInBatch(subscriber, input: Observable<any>) {
const signal = new Subject<number>();
var count = 0;
//use set timeout to fire after the buffer recieves this item
const sendSignal = (item) => setTimeout(() => { count = 0; signal.next(item); });
return input.concatMap(([folder, tag]) => {
return obs_readdir({ folder, tag })(folder);
}).lift({
call: (subs: Subscriber<any>, source: Observable<any>) => {
const signalFunction = (count) => signal.mapTo(1), forwardWhenEmpty = true;
@Arlen22
Arlen22 / mydev-color.js
Created February 16, 2017 20:41
Morgan loggers
morgan.format('mydev', function developmentFormatLine(tokens, req, res) {
// get the status code if response written
var status = res._header
? res.statusCode
: 0
var path = req.path.split('/');
path = path[1] === 'col';
// get status color
var color = status >= 500 ? 31 // red
@Arlen22
Arlen22 / Console output with Debug
Created October 17, 2016 20:25
Puzzling problem with express app
express:router dispatching GET /arlen/status +1s
express:router query : /arlen/status +1ms
express:router expressInit : /arlen/status +1ms
express:router logger : /arlen/status +2ms
express:router trim prefix (/arlen/status) from url /arlen/status +3ms
express:router router /arlen/status : /arlen/status +1ms
express:router dispatching GET / +8ms
express:router jsonParser : /arlen/status +2ms
express:router <anonymous> : /arlen/status +2ms
webexp path / +1ms
@Arlen22
Arlen22 / Hosting multiple tiddlywikis on Express.md
Last active May 21, 2021 13:08 — forked from anonymous/index.js
A file to allow running multiple TiddlyWikis as seperate folders of an Express JS application. Made with 5.1.9. Amended for 5.1.14-Prerelease. My part is released into the Public Domain.
  • Download the NodeJS version of TiddlyWiki from GitHub or NPM. If you use NPM, do not use the global option (-g).
  • Put web.js beside tiddlywiki.js.
  • Require web.js from the Express application and call it on every matching request (see below).
  • For TiddlyWiki before 5.1.14-Prerelease: In core/modules/commands/server.js, seperate out the requestHandler function that is passed to http.createServer so it is on the SimpleServer prototype. Add the self variable to the first line of the requestHandler as shown.
SimpleServer.prototype.listen = function(port,host) {
	http.createServer(this.requestHandler.bind(this)).listen(port,host);
};
SimpleServer.prototype.requestHandler = function(request,response) {