Skip to content

Instantly share code, notes, and snippets.

(function {
window.addEventListener('online', doSomething);
window.addEventListener('offline', doSomething);
})()
// @returns: String { "online", "offline" }
function doSomething() {
returns navigator.onLine;
}

Its likely more natural for you to type at the bottom of the file so with normal Go we move the cursor to the bottom before reading from the date command.

# bash_profile.sh
alias did="vim +'normal Go' +'r!date' ~/did.txt"
@theptrk
theptrk / npm-start.md
Created July 14, 2018 21:34
hello world: npm start script

package.json

{
  "name": "theptrk",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node index.js"
const express = require('express')
const app = express()
const PORT = process.env.PORT || 3000
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(PORT, () => console.log(`Example app listening on port ${PORT}!`))
# find
find -name '* SOME_SPECIFIER.SOME_EXTENSION'
# find and delete
find -name '* SOME_SPECIFIER.SOME_EXTENSION' -delete
# example 1: delete all files to end in `"space"1.JPG`
find -name '* 1.JPG' -delete
@theptrk
theptrk / bcrypt-nodejs.md
Last active October 4, 2020 09:14
bcrypt-nodejs bug - Invalid salt revision

Bug - Invalid salt revision

Whenever I ran compareSync(password, passwordHash) I would see the error

Invalid salt revision

What did it mean? Where did it come from?

This is the code in the library bcrypt-nodejs

minor = salt.charAt(2);
@theptrk
theptrk / index.js
Last active January 19, 2019 23:42
const chalk = require('chalk')
const inquirer = require('inquirer')
const promptSignup = () => {
const questions = [
{
message: 'Whats hannenin\'??',
name: 'action',
type: 'list',
choices: ['did', 'task']
const fs = require('fs')
const path = require('path')
const saveToFile = (entry) => {
const target = path.join(__dirname, 'did.txt')
console.log(chalk.green(`... saving to did.txt`))
if (fs.existsSync(target)) {
@theptrk
theptrk / readme.md
Last active January 21, 2019 22:54
Migrate a postgres database with sequelize.js

Migrate postgres database with sequelize.js

Part I: Set up postgres and sequelize

  • Start the postgresql server using brew and ensure relaunch on login more
$ brew services start postgresql
@theptrk
theptrk / app.js
Last active January 22, 2019 01:43
local authentication
app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));
app.use(session({ secret: "ilovetodidlist" }));
// authman init needs to be invoked AFTER app.use(session)
authman.init(app);