Skip to content

Instantly share code, notes, and snippets.

View jeffjohnson9046's full-sized avatar

Jefe Johnson jeffjohnson9046

View GitHub Profile
@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"
@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",
/******************************************************************************************************************************
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 / .vimrc
Created July 1, 2021 14:09
My vim settings
set laststatus=2
set nu
syntax on
set statusline= " clear the statusline for when vimrc is reloaded
set statusline+=%-3.3n\ " buffer number
set statusline+=%f\ " file name
set statusline+=%h%m%r%w " flags
set statusline+=[%{strlen(&ft)?&ft:'none'}, " filetype
set statusline+=%{strlen(&fenc)?&fenc:&enc}, " encoding
CREATE USER [database owner name] WITH CREATEROLE ENCRYTPED PASSWORD '[database owner's password]';
CREATE DATABASE [database name] OWNER [database owner name];
-- connect to [database name]
REVOKE CREATE ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON DATABASE [database name] FROM PUBLIC;
REVOKE ALL ON ALL TABLES IN SCHEMA public FROM PUBLIC;
-- log in as [database owner name] to [database name] db
CREATE SCHEMA [schema name];
@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 / 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 / ssh-tunnel-to-private-rds.sh
Last active June 24, 2022 21:38
Connect to a private AWS RDS instance that is only accessible through a bastion (and not the internet)
# Assume the following scenario:
# * You have a bastion/jump server that is publicly available
# * You have an RDS instance that is _not_ publicly accessible, but the bastion can get to it
#
# We have this setup with some of our k8s clusters: the cluster was created via kops, which _also_ sets up a VPC, a
# bastion server, all that good stuff. We use a "private" network topology to minimize public access to any of the
# resources in the cluster.
#
# We _also_ create our RDS instances in the same VPC. The bastion and nodes get access to the RDS instance, but it isn't
# available to us common folk out here on the internet. That's good; we want to minimize access to the database, too.