This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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]' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Accepted answer from here: https://stackoverflow.com/questions/5408156/how-to-drop-a-postgresql-database-if-there-are-active-connections-to-it | |
SELECT pg_terminate_backend(pg_stat_activity.pid) | |
FROM pg_stat_activity | |
WHERE pg_stat_activity.datname = '[your database name goes here]' | |
AND pid <> pg_backend_pid(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Set up an associative array for the error messages. The keys must be the exact name of the | |
// controls that need to have the error message displayed. | |
var errorArray = { | |
SomeProperty: "'SomeProperty' has shit the bed", | |
SomeOtherProperty: "Whoa - TWO errors? You are up the creek" | |
}; | |
// Show the errors next to their associated controls | |
$('#form-to-validate').validate().showErrors(errorArray); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
# -*- coding: utf-8 -*- | |
import io | |
""" | |
Input file might look something like this: | |
cat input.txt | |
some ñ thing | |
foo ñññ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From here: https://stackoverflow.com/questions/2706797/finding-what-branch-a-git-commit-came-from | |
# First, make sure you have everything locally: | |
$ git fetch --all --tags --prune | |
# Show the local branches a commit is on (the "b4f8b91" is the first 7 characters of the commit hash): | |
$ git branch --contains b4f8b91 | |
develop | |
* feature/ast-3975 | |
master |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Set the mongo shell prompt to display [user name]@[database name]. If the user or database name cannot | |
be captured, then display "<none>" instead. | |
*/ | |
var prompt = function() { | |
var user = db.runCommand({connectionStatus : 1}).authInfo.authenticatedUsers[0].user || "<none>"; | |
var dbLabel = db.getName() || "<none>"; | |
return user + "@" + dbLabel + ">"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Assume you have a directory structure that looks something like this: | |
ls -alh /path/to/my/directory | |
drwxr-xr-x 38 jeffjohnson staff 1.2K Jul 18 11:07 ./ | |
drwxr-xr-x 6 jeffjohnson staff 192B Jun 23 15:00 ../ | |
drwxr-xr-x 10 jeffjohnson staff 320B Aug 28 2017 foo/ | |
drwxr-xr-x 12 jeffjohnson staff 384B Dec 18 2017 bar/ | |
drwxr-xr-x 11 jeffjohnson staff 352B Feb 26 2018 baz/ | |
-rw-r--r-- 1 jeffjohnson staff 1.8M Aug 14 2017 some-update.sql | |
# list continues... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Set client encoding | |
\encoding UTF8 | |
\set QUIET 1 | |
-- print 'NULL' (instead of a blank) for any columns that have a null value | |
\pset null 'NULL' | |
-- Do not automatically commit after every statement | |
\set AUTOCOMMIT off |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a password-protected keystore. Change the -keypass value to a password that meets your password policy. LastPass (or some other password generator) can come in handy here for creating a password. | |
keytool -genkeypair -alias my-service-provider -keypass password -keyalg RSA -keysize 2048 -keystore my-sso-keystore.jks | |
# Use openssl to get the identity provider's public key as a file named sso.crt. | |
openssl s_client -connect my-sso-domain.example.com:443 > sso.crt | |
# Open the sso.crt file in any editor and remove everything around the BEGIN and END lines. If required, concatenate with any intermediate certificates. | |
vi sso.crt | |
# When done editing, the file should look similar to this: |