Skip to content

Instantly share code, notes, and snippets.

View jeffjohnson9046's full-sized avatar

Jefe Johnson jeffjohnson9046

View GitHub Profile
@jeffjohnson9046
jeffjohnson9046 / percent-filter.js
Last active September 4, 2020 23:25
Format percentages in AngularJS
// In app.js or main.js or whatever:
// var myApp = angular.module('askchisne', ['ngSanitize', 'ngAnimate', 'ui.bootstrap', 'ui.bootstrap.tpls']);
// This filter makes the assumption that the input will be in decimal form (i.e. 17% is 0.17).
myApp.filter('percentage', ['$filter', function ($filter) {
return function (input, decimals) {
return $filter('number')(input * 100, decimals) + '%';
};
}]);
@jeffjohnson9046
jeffjohnson9046 / settings.json
Created June 30, 2020 23:40
My settings.json for VS Code
{
"workbench.iconTheme": "material-icon-theme",
"workbench.startupEditor": "newUntitledFile",
"workbench.colorCustomizations": {
"editorRuler.foreground": "#1a1a1a",
// Came from snazzy.json, here: https://github.com/Tyriar/vscode-snazzy/blob/master/snazzy.json
"terminalCursor.background": "#282a36",
"terminalCursor.foreground": "#97979b",
"terminal.selectionBackground": "#97979b33",
@jeffjohnson9046
jeffjohnson9046 / range-generator.js
Created June 27, 2020 17:07
A Javascript generator to generate a range of numbers
// Source:
// https://dev.to/ycmjason/how-to-create-range-in-javascript-539i
function* range(start, end) {
yield start;
if (start === end) {
return;
}
yield* range(start + 1, end);
}
@jeffjohnson9046
jeffjohnson9046 / ant-condition-test.xml
Created June 11, 2020 20:35
A quick test of condition elements in ant
<project name="condition-test" default="all">
<target name="condition">
<condition property="isTomcat">
<matches pattern="^(tomcat)" string="${webContainer}" />
</condition>
<condition property="isWebLogic">
<matches pattern="^(web)" string="${webContainer}" />
</condition>
</target>
@jeffjohnson9046
jeffjohnson9046 / sinatra-server.rb
Last active June 3, 2020 23:51
A simple sinatra server that accepts a POST with JSON content.
# To make this server publicly available on the inter-webs while running from localhost, use ngrok, which can be found here:
# https://ngrok.com/download. Follow the installation instructions for ngrok and start it up:
#
# ./ngrok 4567 # (or whatever port you want to listen on).
#
# ngrok will spit out an ugly but unique URL. After ngrok starts up, you should be able to POST to the sinatra server:
#
# http://6eee766f.ngrok.com/payload
require 'sinatra'
require 'json'
@jeffjohnson9046
jeffjohnson9046 / title-case-filter.js
Created March 26, 2014 18:22
A title-case filter for AngularJs
// Came from the comments here: https://gist.github.com/maruf-nc/5625869
app.filter('titlecase', function() {
return function (input) {
var smallWords = /^(a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|vs?\.?|via)$/i;
input = input.toLowerCase();
return input.replace(/[A-Za-z0-9\u00C0-\u00FF]+[^\s-]*/g, function(match, index, title) {
if (index > 0 && index + match.length !== title.length &&
match.search(smallWords) > -1 && title.charAt(index - 2) !== ":" &&
(title.charAt(index + match.length) !== '-' || title.charAt(index - 1) === '-') &&
@jeffjohnson9046
jeffjohnson9046 / find-foreign-keys.sql
Created May 4, 2020 21:12
Find all the foreign keys in a Postgres database.
-- from here: https://dataedo.com/kb/query/postgresql/list-foreign-keys
select kcu.table_schema || '.' ||kcu.table_name as foreign_table,
'>-' as rel,
rel_tco.table_schema || '.' || rel_tco.table_name as primary_table,
string_agg(kcu.column_name, ', ') as fk_columns,
kcu.constraint_name
from information_schema.table_constraints tco
join information_schema.key_column_usage kcu
on tco.constraint_schema = kcu.constraint_schema
and tco.constraint_name = kcu.constraint_name
@jeffjohnson9046
jeffjohnson9046 / zsh-prompt-setup.sh
Created January 14, 2020 18:41
Steps I took to set up my Z shell prompt the way I like
# NOTE: These steps assume that zsh is already installed
# Download and install iTerm2, which can be found here: https://iterm2.com/downloads/
# Install oh-my-zsh (details and alternate installation instructions can be found here: https://github.com/ohmyzsh/ohmyzsh):
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# Install the Powerlevel9k theme for zsh (details for using the oh-my-zsh installation can be found here: https://github.com/Powerlevel9k/powerlevel9k/wiki/Install-Instructions#option-2-install-for-oh-my-zsh):
git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k
@jeffjohnson9046
jeffjohnson9046 / k8s-get-docker-container-memory.sh
Created October 19, 2019 15:43
Get the currently used and maximum available memory for a Docker container running in Kubernetes
# These commands demonstrate how to determine how much memory is availble on a k8s worker node and how much memory is
# available to the k8s _container_ hosted on that node.
# Source:
# https://shuheikagawa.com/blog/2017/05/27/memory-usage/
#
# Other interesting articles:
# https://docs.docker.com/engine/docker-overview/#the-underlying-technology
# https://docs.docker.com/config/containers/resource_constraints/
#
# These values are approximations, because according to the first article, calculating/determining available memory
@jeffjohnson9046
jeffjohnson9046 / spring-cloud-config-decrypt-curl.sh
Last active August 5, 2019 23:38
Use the Spring Cloud Config service to encrypt/decrypt an encrypted value
# 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]'