Skip to content

Instantly share code, notes, and snippets.

View jeffjohnson9046's full-sized avatar

Jefe Johnson jeffjohnson9046

View GitHub Profile
@jeffjohnson9046
jeffjohnson9046 / heroku-db-backup-copy.sh
Created March 31, 2015 18:55
Heroku: Take Database Backup and Restore Locally
# NOTE: These steps assume the following:
# * The heroku toolbelt is installed: https://toolbelt.heroku.com/
# * A postgres server is installed and running: http://www.enterprisedb.com/products-services-training/pgdownload#osx
# STEP 1: Login to herku:
heroku login
# provide credentials
# STEP 2: Create database backup
heroku pg:backups public-url b001 --app <the name of your heroku application>
@jeffjohnson9046
jeffjohnson9046 / sp_configure-options.sql
Created May 14, 2015 18:24
A collection of some commonly-used options for sp_configure in MSSQL Server
sp_configure 'show advanced options', 1
reconfigure;
-- show advanced options
-- backup compression default -- always compress backups.
-- blocked process threshold (s) -- only capture blocking scenarios that block this threshold.
-- clr enabled -- allows CLR user-defined stored procedures and functions.
-- Database Mail XPs
-- fill factor (%) -- useful for reducing fragmentation (for frequently updated tables). Reduces page-splitting when a record has be inserted in the middle of the page
-- max degree of parallelism -- set the max number of CPUs that are available for a single query. Can be overridden by MAX DOP setting on a query
-- remote access -- grant/revoke ability to allow remote users to access the SQL Server from external connections
@jeffjohnson9046
jeffjohnson9046 / sql-server-foreign-key-references.sql
Created June 3, 2015 19:48
Find all tables that reference a table via foreign key relationship in MSSQL.
SELECT
OBJECT_NAME(f.parent_object_id) TableName,
COL_NAME(fc.parent_object_id,fc.parent_column_id) ColName
FROM
sys.foreign_keys AS f
INNER JOIN
sys.foreign_key_columns AS fc
ON f.OBJECT_ID = fc.constraint_object_id
INNER JOIN
sys.tables t
@jeffjohnson9046
jeffjohnson9046 / supervisord-sample-program.ini
Created June 30, 2015 18:16
A sample INI/configuration file for programs that should be monitored by Supervisor
[program:your_program_name_here]
command=;command to start your program
user=;user that your program should run as
autostart=true
autorestart=true
startsecs=10
startretries=3
stdout_logfile=;path to log file, e.g. /var/log/your_program_name_here-stdout.log
stdout_logfile_maxbytes=128MB
stdout_logfile_backups=32
@jeffjohnson9046
jeffjohnson9046 / index-fill-factor.sql
Created July 27, 2015 06:14
MSSQL: Inspect Indexes and their fill factor settings
SELECT OBJECT_NAME(object_id) as table_name, name, type_desc, is_primary_key, fill_factor FROM sys.indexes;
USE [whatever database]
GO
ALTER INDEX PK_GeoRoot ON GeoRoot
REBUILD WITH (FILLFACTOR = 80);
/* Check existing indexes */
SELECT
@@SERVERNAME AS [ServerName]
, DB_NAME() AS [DatabaseName]
, [SchemaName]
, [ObjectName]
, [ObjectType]
, [IndexID]
, [IndexName]
, [IndexType]
@jeffjohnson9046
jeffjohnson9046 / sql-server-generate-random-date.sql
Created July 31, 2015 23:36
MSSQL - Generate a random datetime value for a given year.
DECLARE @RandomDate datetime
SELECT @RandomDate =
DATEADD(day, ROUND(DATEDIFF(day, '2015-01-01', '2015-12-31') * RAND(CHECKSUM(NEWID())), 0),
DATEADD(second, CHECKSUM(NEWID()) % 48000, '2015-01-01'))
/* Verify */
SELECT RandomDate = @RandomDate
@jeffjohnson9046
jeffjohnson9046 / git-ignore.sh
Created August 11, 2015 21:02
Remove unwanted files from a git repo AFTER adding a .gitignore. The files will remain on disk.
## I just ran into this after initializing a Visual Studio project _before_ adding a .gitignore file (like an idiot).
## I felt real dumb commiting a bunch of files I didn't need to, so the commands below should do the trick. The first two commands
## came from the second answer on this post: http://stackoverflow.com/questions/7527982/applying-gitignore-to-committed-files
# See the unwanted files:
git ls-files -ci --exclude-standard
# Remove the unwanted files:
git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached
@jeffjohnson9046
jeffjohnson9046 / .gitignore
Created August 11, 2015 21:12
Visual Studio .gitignore used @ Fairway
Thumbs.db
*.obj
*.exe
*.pdb
*.user
*.aps
*.pch
*.vspscc
*_i.c
*_p.c
@jeffjohnson9046
jeffjohnson9046 / sql-server-product-info.sql
Created December 23, 2015 07:51
SQL Server Product Information
/* Run this query against any database on a SQL Server instance to get version details*/
SELECT
SERVERPROPERTY('productversion') AS ProductVersion,
SERVERPROPERTY('productlevel') AS ProductLevel,
SERVERPROPERTY('edition') AS Edition,
@@VERSION AS VerboseVersion;