Skip to content

Instantly share code, notes, and snippets.

View tcrowe's full-sized avatar
💭
Account archived | See link

Tony Crowe tcrowe

💭
Account archived | See link
View GitHub Profile
@tcrowe
tcrowe / express-cache-buster.js
Created September 18, 2019 19:15
express cache busting - disable the default caching
/*
1. by default express is using etags caching which may not be preferable
2. add nocache middleware
3. disable etags for server
4. disable etags and last modified for static files middleware
*/
const express = require("express");
@tcrowe
tcrowe / src-middleware-authenticated.js
Created September 13, 2019 20:45
express, sapper, polka authentication idea
/*
+ assuming you're using cookie-session or similar session
usage:
import authenticated from "./middleware/authenticated.js"
server.use(authenticated)
*/
@tcrowe
tcrowe / polka-express-http-proxy.js
Created August 23, 2019 01:49
polka sapper api proxy example
/*
they usually use ES Modules but i used CommonJS here
you can port it to suite your need
*/
const sirv = require("sirv");
const polka = require("polka");
const compression = require("compression");
@tcrowe
tcrowe / example.ejs
Created June 20, 2019 18:22
hexo ejs hierarchical categories display
<%
function displayCategories(parent = undefined) { // start with no parent
site.categories
.find({ parent }) // warehouse allows for complex queries
.sort("name") // sorting .sort("fieldName", 1) ascending or .sort("fieldName", -1) descending
.each(function(category) {
// count the child categories
const childCount = site.categories.find({ parent: category._id }).count();
%>
<li>
@tcrowe
tcrowe / binary-command-exists.zsh
Created June 2, 2019 16:19
Bash or ZSH: Check if a binary or command exists
# which goes into dev null
# $? is the magic that tells us if it worked 0 = exists
if [[ `which nvm &>/dev/null && $?` != 0 ]]; then
source ~/.nvm/nvm.sh
fi
@tcrowe
tcrowe / build-electron-exe.zsh
Created March 19, 2019 09:09
Build electron app for windows using osx
#!/bin/zsh
# tell electron packager's rcedit.exe to use wine64
export WINE=`which wine64`
export WINEARCH=win64
export WINE_ARCH=win64
# possibly interesting information
# https://wiki.winehq.org/Debug_Channels
# unset WINEDEBUG
@tcrowe
tcrowe / osx-snippet-delete.js
Created March 14, 2019 17:25
Delete all the snippets in Sublimetext's packages and also the user's installed packages
/*
⚠️ It does not prompt or ask permission. It just deletes all the snippets!
usage: node osx-snippet-delete.js
*/
const path = require("path");
const {exec} =require("child_process")
@tcrowe
tcrowe / ssh-host-keys.sh
Created February 6, 2019 21:36
new ssh host keys with "yes" confirmation
# v--automatic yes
yes | ssh-keygen -q -t ed25519 -N '' -f /etc/ssh/ssh_host_ed25519_key
yes | ssh-keygen -q -t rsa -b 2048 -N '' -f /etc/ssh/ssh_host_rsa_key
# what bits do you want? ---^
@tcrowe
tcrowe / nice-browser-sync.zsh
Last active December 11, 2019 00:20
a specific and quiet browser-sync
#!/bin/zsh
browser-sync start -w --ss dist --port 9924 --host 127.0.0.1 --logLevel error --no-notify --no-open --no-ui --no-online --no-ghost-mode
@tcrowe
tcrowe / telegram-bot.js
Last active November 17, 2018 23:33
start up a new telegram bot using nodejs
/*
# the basic echo bot
Instructions:
+ Pops up the docs in the browser
+ npm docs node-telegram-bot-api
+ Install the bot module
+ npm install node-telegram-bot-api
+ Dump in this code into a JS file like ./index.js