Skip to content

Instantly share code, notes, and snippets.

View bartread's full-sized avatar
💭
Busy

Bart Read bartread

💭
Busy
View GitHub Profile
@bartread
bartread / gist:d169a4416cefc306a666e2fec2f62eb3
Last active August 14, 2024 13:10
Bash script for installing systemd service on Ubuntu
#! /bin/sh
# Other deployment actions here. Want to install (or bounce) service last.
if [ -f /etc/systemd/system/arcadely.service ]; then
sudo systemctl stop arcadely.service
sudo systemctl disable arcadely.service
else
sudo \cp -f ./arcadely.service /etc/systemd/system/arcadely.service
fi
@bartread
bartread / arcadely.service
Created January 21, 2017 22:14
systemd service descriptor for arcade.ly
[Unit]
Description=Arcade.ly Node.js Server
#Requires=After=mysql.service # Requires the mysql service to run first
[Service]
ExecStart=/usr/bin/node /home/ubuntu/arcade/build/production/index.js
Restart=always
RestartSec=10 # Restart service after 10 seconds if node service crashes
StandardOutput=syslog # Output to syslog
StandardError=syslog # Output to syslog
@bartread
bartread / arcadely.conf
Created January 21, 2017 22:07
Sample upstart configuration for arcade.ly
description "Arcade.ly node.js server"
author "Bart Read"
# used to be: start on startup
# until we found some mounts weren't ready yet while booting
start on started mountall
stop on shutdown
# automatically respawn
@bartread
bartread / findnodeprocesses.sh
Created January 21, 2017 13:01
Ubuntu 16 - reliably find node processes and take conditional action
#!/bin/sh
NODEPROCESSES=$(ps -aux | grep '[s]udo nohup node index.js' | awk '{print $2}')
if [ -n "$NODEPROCESSES" ]; then
echo "Found node processes $NODEPROCESSES"
else
echo "No node processes found"
fi
@bartread
bartread / gist:5d8c09310156b3a37c968b2f6d3a1e79
Last active September 15, 2017 09:43 — forked from tonymtz/gist:d75101d9bdf764c890ef
Fully uninstall nodejs from OSX Yosemite 10.10.5
# first:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.node.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
# To recap, the best way (I've found) to completely uninstall node + npm is to do the following:
# go to /usr/local/lib and delete any node and node_modules
cd /usr/local/lib
sudo rm -rf node*
@bartread
bartread / mostexpensivesprocs.sql
Last active June 14, 2018 02:11
Get most expensive stored procedures in SQL Server
USE [YOUR_DATABASE_NAME]; -- Substitute for your database name
GO
SELECT TOP 10 -- Change as appropriate
t.text ,
s.sql_handle ,
s.plan_handle ,
s.total_worker_time / 1000 AS total_cpu_time_millis ,
s.total_worker_time / s.execution_count / 1000 AS avg_cpu_time_millis ,
s.total_logical_reads,
@bartread
bartread / basicsqlserverosinformation.sql
Created January 10, 2017 20:29
Get basic SQL Server and OS information
SELECT [cpu_ticks] ,
[ms_ticks] ,
[cpu_count] ,
[hyperthread_ratio] ,
[physical_memory_kb] ,
[virtual_memory_kb] ,
[committed_kb] ,
[committed_target_kb] ,
[visible_target_kb] ,
[stack_size_in_bytes] ,
@bartread
bartread / mapallobjectidstoschemaandobjectnames.sql
Created January 10, 2017 20:21
Map all object IDs to schema and object names in database
SELECT o.[object_id] AS [ObjectID],
s.[name] AS [SchemaName],
o.[name] AS [ObjectName],
s.[name] + '.' + o.[name] AS [QualifiedName],
o.[type]
FROM sys.objects AS o
INNER JOIN sys.schemas AS s ON o.schema_id = s.schema_id
ORDER BY [QualifiedName];
@bartread
bartread / sqlprofileeventsrelatingtotempdbactivity.sql
Created January 10, 2017 17:36
Maps activity in tempdb over a given time period to events in SQL Profiler trace by Transaction ID to allow you to relate tempdb activity to activity in other databases.
/*
This query allows you to relate activity in tempdb to activity in other databases
where that activity has been recorded in a SQL Profiler trace table.
This can come in useful when, for example, diagnosing the source of I/O activity
and possible bottlenecking in tempdb.
*/
@bartread
bartread / getalleventtypesrecorded.sql
Created January 10, 2017 14:00
Gets a list of all the distinct event types recorded in a SQL Profiler trace table.
SELECT DISTINCT te.name
FROM [YOUR_TRACE_SCHEMA_NAME].[YOUR_TRACE_TABLE_NAME] AS d
INNER JOIN sys.trace_events AS te
ON te.trace_event_id = d.EventClass;