Skip to content

Instantly share code, notes, and snippets.

View davemackintosh's full-sized avatar
❤️
peace

Dave Mackintosh davemackintosh

❤️
peace
View GitHub Profile
@davemackintosh
davemackintosh / LICENSE
Last active August 29, 2015 14:01
Bump the version number in your package.json with this node tool. I use it in my makefiles for production releases.
The MIT License (MIT)
Copyright (c) 2014 Dave Mackintosh
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
@davemackintosh
davemackintosh / .htaccess
Last active May 2, 2024 15:52
Working .htaccess for Single Page Apps
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.html [QSA,L]
</ifModule>
@davemackintosh
davemackintosh / long-runner-progress-nice.js
Last active August 29, 2015 14:10
Mongo database currentOp() helper. Makes it a bit nicer
db.currentOp().inprog.forEach(function(op) {
if (op.progress) {
var remaining = op.progress.total - op.progress.done;
var running_for = op.secs_running / 60 / 60;
print(op.ns, op.opid, 'running for', running_for.toPrecision(4), 'hours')
print('job "'+ op.insert.name +'" running in background?', op.insert.background ? 'yes' : 'no');
print(op.msg)
print('Remaining records', remaining, 'finished', op.progress.done, 'docs')
print('Estimated', ((running_for / op.progress.done) * remaining).toPrecision(4), 'hours remaining')
@davemackintosh
davemackintosh / mongo-replica-startup2-index-eta.js
Last active August 29, 2015 14:12
Mongo STARTUP2 index ETA
var op = db.currentOp().inprog[0];
var persec = op.progress.done / op.secs_running;
var time = ((op.progress.total - op.progress.done) / persec) / 60 / 60;
var unit = 'hours';
if (time < 1.0 && time > 0.0) {
unit = 'minutes';
time = 60 * time;
}
@davemackintosh
davemackintosh / obj-go-reader.go
Last active September 20, 2023 09:31
Really simple OBJ loader in Golang. Done this loads in C++ and thought I'd see how easy it was in Go, turns out it's really easy. No license, feel free to whatever with this.
package model
import (
"fmt"
"io"
"os"
"github.com/go-gl/mathgl/mgl32"
)
atom-text-editor {
background-color: rgb(251, 244, 239);
&::shadow {
.gutter {
background-color: rgb(251, 244, 239);
}
.gutter,
.comment,
class Person {
constructor(name) { this.name = name.toString() }
be_polite() { return `Good morning, ${this.name}.` }
be_rude() { return `Actually, Jump off of something high.` }
}
const me = new Person("Dave")
me
|> be_polite
|> be_rude
@davemackintosh
davemackintosh / blob_to_buffer.js
Created December 12, 2015 14:26
Electron blob to buffer, I made this to use with the nativeImage class.
function blob_to_buffer(blob, callback) {
// Create a file reader instance.
const file_reader = new FileReader()
// Listen to when reading is finished and
// run the callback with a buffer.
file_reader.addEventListener("loadend", event => {
if (event.error) {
callback(event.error)
}
@davemackintosh
davemackintosh / map-to-json.js
Last active August 7, 2023 15:49
Convert ES6 `Map`s to a standard JSON object without effing Babel.
/**
* Convert a `Map` to a standard
* JS object recursively.
*
* @param {Map} map to convert.
* @returns {Object} converted object.
*/
function map_to_object(map) {
const out = Object.create(null)
map.forEach((value, key) => {
@davemackintosh
davemackintosh / bench.js
Last active January 21, 2016 12:42 — forked from AdriVanHoudt/bench.js
Mini benchmark Hoek.unique vs Set
"use strict"
// used in benchmarks.
const SAMPLE = 5000000
const Hoek = require('hoek')
const array = []
for (let i = 0; i < SAMPLE; ++i) {
array.push(i * Math.floor(Math.random() * (10 - 1 + 1)) + 1)
}