Skip to content

Instantly share code, notes, and snippets.

Jefe Johnson jeffjohnson9046

Block or report user

Report or block jeffjohnson9046

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
@jeffjohnson9046
jeffjohnson9046 / spring-cloud-config-decrypt-curl.sh
Last active Aug 5, 2019
Use the Spring Cloud Config service to encrypt/decrypt an encrypted value
View spring-cloud-config-decrypt-curl.sh
# Encrypt
curl -sbiL -X POST http://localhost:8888/encrypt -d '[the value you want to encrypt]'
# Decrypt
curl -sbiL -X POST http://localhost:8888/decrypt -d '[the encrypted value, without the "{cipher}" prefix]'
@jeffjohnson9046
jeffjohnson9046 / get-or-default.cs
Last active Mar 14, 2018
A .NET equivalent of Java's "GetOrDefault()" method
View get-or-default.cs
/// <summary>
/// Get a value <code>V</code> for the specified key <code>K</code>. If there is no value for the specified
/// key, return a default value instead.
/// </summary>
/// <remarks>
/// This code emulates the Java <code>GetOrDefault()</code> method on a <code>Map</code>. It's also a convenient
/// way to "inline" the <code>Dictionary#TryParse</code> and have it return some value in the event the key we're
/// looking for doesn't exist.
/// </remarks>
/// <example>
@jeffjohnson9046
jeffjohnson9046 / TransactionRollbackIntegrationTestBase.cs
Last active Feb 17, 2018
A C# class for rolling back database modifications after they've happened.
View TransactionRollbackIntegrationTestBase.cs
/// <summary>
/// A class for rolling back database transactions after the test has completed.
/// </summary>
[TestClass]
public abstract class TransactionRollbackIntegrationTestBase
{
private TransactionScope transactionScope;
/// <summary>
/// Create the transaction scope to enforce creating a new transaction prior to the test executing.
@jeffjohnson9046
jeffjohnson9046 / mssql-find-foreign-key-references.sql
Created Nov 10, 2017
MS SQL Server: for a given table, find all "child" tables that reference it
View mssql-find-foreign-key-references.sql
-- Based on answer from here:
-- https://stackoverflow.com/questions/483193/how-can-i-list-all-foreign-keys-referencing-a-given-table-in-sql-server
SELECT
child.name AS child_table,
fk.constraint_column_id AS fk_part_no,
c.name AS foreign_key_column
FROM
sys.foreign_key_columns AS fk
JOIN
sys.tables child
@jeffjohnson9046
jeffjohnson9046 / find-text-in-stored-procedure.sql
Created Nov 10, 2017
MS SQL Server: find text in a stored procedure
View find-text-in-stored-procedure.sql
-- Second answer from here: https://stackoverflow.com/questions/14704105/search-text-in-stored-procedure-in-sql-server
SELECT
name,
SCHEMA_NAME(schema_id) AS [schema]
FROM
sys.procedures
WHERE
OBJECT_DEFINITION(object_id) LIKE '%whatever text you are looking for%';
@jeffjohnson9046
jeffjohnson9046 / backup-all-user-dbs.sql
Created Nov 9, 2017
MS SQL Server: Create full database backups of all "user" databases. This script overwrites the previous backup, so there's only ever one backup of the db. Fine for development, not so much for production.
View backup-all-user-dbs.sql
DECLARE
@backupMsg varchar(max),
@backupPath varchar(max),
@backupCommand varchar(max),
@dbName varchar(max);
SELECT
@backupMsg = 'Full backup',
@backupPath = 'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Backup\';
@jeffjohnson9046
jeffjohnson9046 / alter-index-rebuild-reorganize.sql
Last active May 1, 2019
Rebuild and reorganize indexes for every table in an MS SQL Server database
View alter-index-rebuild-reorganize.sql
-- from here: https://gallery.technet.microsoft.com/scriptcenter/Rebuild-and-Reorganize-7ff5624e
DECLARE
@fragPercentThreshold decimal(11,2),
@schemaName nvarchar(128);
-- Determine maximum fragmentation threshold and the schema to operate against
SET @fragPercentThreshold = 5.0;
SET @schemaName = N'dbo';
@jeffjohnson9046
jeffjohnson9046 / jquery-deferred-promise-example.js
Last active Feb 4, 2019
A quick example of how to use deferred and promise in jquery
View jquery-deferred-promise-example.js
// jsfiddle: https://jsfiddle.net/Lkxtryvp/1/
var myAwesomeLoop = function(x) {
// This is the magic sauce right here - you're creating a unit of work that will be done at some
// point in the future. We're not exactly sure when, but the deferred object will notify us when
// it's done (by calling "resolve()" or "reject()" on itself).
var deferred = $.Deferred();
// We'll create a simple loop to concatenate some values together. This simulates where the
// actual, for-real work would be done (e.g. an AJAX request, some sort of long-running calculation, etc)
@jeffjohnson9046
jeffjohnson9046 / curl-cloud-config-props.sh
Last active Jan 16, 2019
use curl to check out a Spring Boot applicaion's configuration properties from a Spring Cloud Configuration service
View curl-cloud-config-props.sh
# Occasionally I want to see the application properties that are pulled down from the Spring Cloud Config service that provides
# content to our Spring Boot apps. Since I seem to have to re-discover this every time, I figured I'd write it down to help me
# remember.
#
# Additional docs can be found here: https://cloud.spring.io/spring-cloud-config/single/spring-cloud-config.html
# To see the output in YML format
curl -u {the user name}:{the user password} http://{the domain:port}/{the application name}-{the spring profile name}.yml
# For example:
@jeffjohnson9046
jeffjohnson9046 / kops-export-config.sh
Last active May 24, 2019
How to update kubectl to see a new Kubernetes cluster
View kops-export-config.sh
# This is something that I always forget and had a surprisingly hard time finding (or better yet, understanding). Here's the
# scenario: a colleague creates a new kubernetes cluster, named" cluster-foo.example.com". You want to look at it (for
# troubleshooting, updating the deployment, whatever). To get your kubectl installation to "see" the new cluster, take the
# following steps:
# ASSUMPTION: You have pointed kops to some location where the cluster configurations are stored
# (I have this in my ~/.bash_profile):
export KOPS_STATE_STORE=s3://example-state-store
# Use kops to get the list of clusters
You can’t perform that action at this time.