Skip to content

Instantly share code, notes, and snippets.

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
atom-text-editor {
background-color: rgb(251, 244, 239);
&::shadow {
.gutter {
background-color: rgb(251, 244, 239);
}
.gutter,
.comment,
@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"
)
@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 / 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 / .htaccess
Last active September 6, 2024 18:36
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 / 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 / gol.lua
Last active December 30, 2015 20:29
Conway's Game of Life in Lua for the Codea iOS app
Gol = class()
function Gol:init(W, H)
-- Set the size
self.columns = W
self.rows = H
-- The varying states of cells
self._alive = 1
self._dead = 0
@davemackintosh
davemackintosh / pre-commit
Created November 13, 2013 17:55
Block master branch
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".
if [ $(git rev-parse --abbrev-ref HEAD) == "master" ]; then
@davemackintosh
davemackintosh / colourFade.js
Created June 24, 2013 09:14
Creates array of colours cross faded from start to end via the number of steps required.
function colourFade (start, end, steps) {
var steps = steps || 10;
var start = start ? start.replace('#', '') : '000000'
var end = end ? end.replace('#', '') : 'FFFFFF'
var out = {"r":[],"g":[],"b":[]};
var floor = Math.abs;
console.log(start,end,end.substr(2,4));