Skip to content

Instantly share code, notes, and snippets.

M mikebarnhardt

Block or report user

Report or block mikebarnhardt

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View move-itunes-corner.txt
osascript <<EOF
tell application "System Events" to tell process "iTunes"
set position of window 1 to {64, 896}
set size of window 1 to {410, 480}
end tell
EOF
@mikebarnhardt
mikebarnhardt / add-key-to-server.md
Created Feb 7, 2018
Generate and Add SSH Key to a Server
View add-key-to-server.md

macOS

Generate a key if needed:

ssh-keygen -t rsa

It should now be located in: ~/.ssh/ as id_rsa and id_rsa.pub.

@mikebarnhardt
mikebarnhardt / render.js
Created Jan 16, 2018
PDF.js with text selection
View render.js
// Taken from https://stackoverflow.com/questions/33063213/pdf-js-with-text-selection
PDFJS.getDocument('file.pdf').then(function(pdf){
var page_num = 1;
pdf.getPage(page_num).then(function(page){
var scale = 1.5;
var viewport = page.getViewport(scale);
var canvas = $('#the-canvas')[0];
var context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;
@mikebarnhardt
mikebarnhardt / treeify.js
Created Jan 16, 2018
Hierarchy tree from flat list
View treeify.js
// Taken from https://stackoverflow.com/questions/22367711/construct-hierarchy-tree-from-flat-list-with-parent-field
function treeify(list, idAttr, parentAttr, childrenAttr) {
if (!idAttr) idAttr = 'id';
if (!parentAttr) parentAttr = 'parent';
if (!childrenAttr) childrenAttr = 'children';
var treeList = [];
var lookup = {};
list.forEach(function(obj) {
lookup[obj[idAttr]] = obj;
@mikebarnhardt
mikebarnhardt / shuffle.js
Created Jan 16, 2018
Fisher-Yates Shuffle
View shuffle.js
// Taken from https://bost.ocks.org/mike/shuffle/
function shuffle(array) {
var m = array.length, t, i;
// While there remain elements to shuffle…
while (m) {
// Pick a remaining element…
i = Math.floor(Math.random() * m--);
@mikebarnhardt
mikebarnhardt / www-permissions.md
Created Jan 2, 2018
Give www folder to group permissions.
View www-permissions.md

Add your Node user. If Apache or something else this could be www-data.

sudo adduser nodejs

Add users to that group to allow access to the www directory.

sudo usermod -aG nodejs <username>
@mikebarnhardt
mikebarnhardt / rename-github-branch.md
Created Jan 2, 2018
Rename local and remote Github branch
View rename-github-branch.md
  1. Rename your local branch. If you are on the branch you want to rename:
git branch -m new-name

If you are on a different branch:

@mikebarnhardt
mikebarnhardt / node-startup.service
Last active Sep 20, 2016
Systemd NodeJS startup
View node-startup.service
[Unit]
Description=NodeJS Startup
After=network.target
[Service]
ExecStart=/usr/bin/nodejs /var/www/repo/build/server
Environment=NODE_ENV=production
User=nodejs
Restart=on-failure
View default.conf
server {
listen 80;
# Your server's IP
server_name 11.222.33.44;
# Uncomment to enable:
# access_log /var/log/nginx/log/host.access.log main;
location / {
@mikebarnhardt
mikebarnhardt / site.conf
Created Jan 22, 2016
Service Script for Node Apps
View site.conf
description "Site Name"
author "Your Name"
# Start service after everything loaded
start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown
# Automatically restart service
respawn
respawn limit 3 15
You can’t perform that action at this time.