Skip to content

Instantly share code, notes, and snippets.

View jeffjohnson9046's full-sized avatar

Jefe Johnson jeffjohnson9046

View GitHub Profile
@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 / alter-index-rebuild-reorganize.sql
Last active March 25, 2024 19:05
Rebuild and reorganize indexes for every table in an MS SQL Server database
-- 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 / kill-all-connections-to-db.sql
Created June 18, 2018 18:10
How to kill all connections to a Postgres database
-- 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();
@jeffjohnson9046
jeffjohnson9046 / ruby-ldap-sample.rb
Last active January 5, 2024 07:11
Some VERY basic LDAP interaction in Ruby using Net::LDAP.
#######################################################################################################################
# This Gist is some crib notes/tests/practice/whatever for talking to Active Directory via LDAP. The (surprisingly
# helpful) documentation for Net::LDAP can be found here: http://net-ldap.rubyforge.org/Net/LDAP.html
#######################################################################################################################
require 'rubygems'
require 'net/ldap'
#######################################################################################################################
# HELPER/UTILITY METHOD
@jeffjohnson9046
jeffjohnson9046 / UuidHelper.java
Last active December 11, 2023 11:06
Convert UUID to byte array and vice versa. Useful for when UUIDs are stored in MySQL tables as VARBINARY(16)
import java.nio.ByteBuffer;
import java.util.UUID;
public class UuidAdapter {
public static byte[] getBytesFromUUID(UUID uuid) {
ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
bb.putLong(uuid.getMostSignificantBits());
bb.putLong(uuid.getLeastSignificantBits());
return bb.array();
@jeffjohnson9046
jeffjohnson9046 / fizzbuzz.js
Created September 28, 2023 14:01
The classic Fizz Buzz but without using the if...else if... else solution
const fizzBuzzMap = {
3: 'Fizz',
5: 'Buzz',
15: 'FizzBuzz'
};
/**
* The classic "Fizz Buzz" game: Print a list of numbers from 1 to the upper limit, using the following rules:
* * If the number is divisible by 3 print "Fizz"
* * If the number is divisible by 5 print "Buzz"
/******************************************************************************************************************************
I was watching a video of a guy reading an article (man... what fucking strange times we live in...) about developers missing
basic programming skills because they rely on npm packages to do the work for them. There are packages like left-pad, is-array,
is-positive-integer, etc. Apparently some change in the left-pad package broke a bunch of big-time repos (including React).
This is a link to said video: https://www.youtube.com/watch?v=NmHUjxKpD90
My main take-aways from the article/video were:
* just because it's a package that gets downloaded a bunch of times doesn't mean it's good, quality code
* don't introduce a dependency if you don't need to
* an over-reliance on external dependencies:
@jeffjohnson9046
jeffjohnson9046 / tasks.json
Created September 25, 2023 16:13
A tasks.json file for compiling a simple C++ application in VS Code
/* Been going through the Learn C++ tutorial (https://www.learncpp.com/), and so far this seems to be a pretty good setup for
tasks.json in VS Code. This tasks.json file is specific for clang++ (I'm on macOS 13.x), so you may need to update the `args`
to suit your own environment. In particular, you will want to replace with {your application name here} with whatever you want
your build artifact to be named.
*/
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ build active file",
@jeffjohnson9046
jeffjohnson9046 / set-aws-env.zsh
Last active November 3, 2022 12:47
A zsh script for setting the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY as environment variables
# I have several AWS profiles in my ~/.aws/config thus there are several access keys and secret keys in my
# ~/.aws/credentials file. Sometimes (e.g. when using kops or kubectl) I need to have the AWS_ACCESS_KEY_ID
# and AWS_SECRET_ACCESS_KEY environment variables set. There doesn't seem to be a way to use the aws cli to set these
# environment variables for me, so... well... here we are.
#
# This script will:
# * Look at the ~/.aws/credentials file for the specified profile
# * Get the next two lines beneath the profile name, which are the access_key_id and secret_key respectively
# * Export those two values as environment variables
#
@jeffjohnson9046
jeffjohnson9046 / ec2-instance-query.zsh
Last active October 10, 2022 13:57
Look up an EC2 Instance by public IP across more than one region
# This is the function I created that's a wee bit less shitty than the file above. I created a file called (oddly enough)
# ec2-instance-query.zsh and put it in my ~/.oh-my-zsh/custom directory. After sourcing my ~/zshrc, I have a fancy-pants
# function for querying EC2 instances and ElasticIP addresses for a given IP:
function ec2-instance-query() {
echo "Finding EC2 information for IP $1:"
for r in `aws ec2 describe-regions --output text | cut -f4 | grep "us-"`
do
aws ec2 describe-instances \
--region $r \
--filter "Name=network-interface.addresses.association.public-ip, Values=$1" \