Skip to content

Instantly share code, notes, and snippets.

@artcommacode
artcommacode / auto_switch_theme.py
Last active August 10, 2021 10:47 — forked from plivox/auto_switch_theme.py
Automatic iTerm2 preset switching on MacOS
#!/usr/bin/env python3
import asyncio
import iterm2
THEME_LIGHT = "serendipity-light-iTerm2"
THEME_DARK = "serendipity-dark-iTerm2"
class AutoSwitchTheme:
@artcommacode
artcommacode / certbot
Created August 16, 2019 11:59 — forked from li0nel/certbot
Execute Certbot
# Use Let's Encrypt certbot to order a free certificate
certbot certonly --non-interactive --manual \
--manual-auth-hook "./auth-hook.sh UPSERT your_domain.com" \
--manual-cleanup-hook "./auth-hook.sh DELETE your_domain.com" \
--preferred-challenge dns \
--config-dir "./letsencrypt" \
--work-dir "./letsencrypt" \
--logs-dir "./letsencrypt" \
--agree-tos \
--manual-public-ip-logging-ok \
// here i'm thinking i needed to use `reduce` twice for some reason
const perms = (str) => {
const words = str.split(' ')
return words.reduce((p, _, i) => {
return p.concat([words.reduce((s, word, j) => {
return j >= i ? s + ` ${word}` : s
}, '').trim()])
}, [])
}
// @flow
import express from 'express'
import myRoute from './myroute'
const app = express()
app.use('/my-route', myRoute())
var views = require('co-views')
var merge = require('deepmerge')
var path = require('path')
module.exports = function () {
return function *(next) {
var render = views(path.join(__dirname, './../'), {default: 'jade'})
this.render = function *(file, locals) {
var seg = file.split('/')
return yield render(path.join('/modules', seg[0], '/views', seg[1]), merge(locals || {}, this.locals))
var mongoose = require('mongoose')
, Schema = mongoose.Schema
, async = require('async')
, _ = require('underscore')
, bcrypt = require('bcrypt');
var UserSchema = new Schema(require('./schema'));
UserSchema.pre('save', function (next) {
var user = this;
### Keybase proof
I hereby claim:
* I am artcommacode on github.
* I am artcommacode (https://keybase.io/artcommacode) on keybase.
* I have a public key whose fingerprint is F8BA 239B 18CB DB19 F8EC 3BF0 E267 820A EDC7 4FA8
To claim this, I am signing this object:
var express = require('express')
, admin = require('./admin/app')
, client = require('./client/app')
, app = module.exports = express();
app.use('/admin', admin);
app.use(client);
app.listen(3009);
sUser.pre('save', co(function *(next) {
if (!this.isModified('password')) return next();
this.password = yield this.encryptPassword(this.password)
return next()
}))
sUser.methods.encryptPassword = function *(password) {
var salt = yield thunkify(bcrypt.genSalt)(10)
return yield thunkify(bcrypt.hash)(password, salt, null)
}
// first
// render is set on this in app.use(), vPath (view path) is set at top of file
// locals sit in `this.locals` and can be easily merged
this.body = yield this.render(vPath + 'index', {users: users})
// second
// render is required at the top of the file with the view path,
// need to pass in `this` to merge `this.locals`
this.body = yield render.call(this, 'index', {users: users})