Skip to content

Instantly share code, notes, and snippets.

@estysdesu
estysdesu / autoformat.vim
Last active July 21, 2019 05:52
[Vim: HTML file auto-format] #vim #autoformat #ft #vim
:filetype indent on
:set filetype=html
:set smartindent
gg=G
@estysdesu
estysdesu / ec2_connect.sh
Last active July 21, 2019 05:58
[AWS: EC2 SSH connect] #ec2 #ssh #sh
# change permissions on the key file (read)
chmod 400 <key.pem>
# ssh into the ec2 container
ssh -i "<key.pem>" uname@<ec2-address/ip-address>
# upgrade & update apt package manager (Debian/Ubuntu)
sudo apt update && apt upgrade
# check & update yum package manager (CentOS/RHEL)
@estysdesu
estysdesu / sticky_footer.css
Last active July 25, 2019 04:40
[CSS: sticky footer] footer always at bottom w/o full page content #sticky #footer #bottom #html #css
@estysdesu
estysdesu / update_size.js
Last active July 21, 2019 05:51
[JavaScript: resize all elements of a HTML tag] This sets height = width #resize #js #html #dom
function updateSize() {
var projectTile = document.querySelectorAll("#projects .tile.is-child");
projectTile.forEach( function(tile, index) {
if (window.innerWidth > 768) {
tile.style.height = getComputedStyle(tile).width;
} else {
tile.style.height = null;
}
})
}
@estysdesu
estysdesu / db_join_table.sql
Last active July 21, 2019 06:05
[SQL: create table with many-to-many relationship] #constraint #postgres #many-to-many #sql
// vim: syntax=sql
-- many-to-many relationship needs join table
CREATE TABLE IF NOT EXISTS student_course (
student_id INTEGER,
course_id INTEGER,
PRIMARY KEY (student_id, course_id),
FOREIGN KEY (student_id) REFERENCES student (id),
FOREIGN KEY (course_id) REFERENCES course (id) );
@estysdesu
estysdesu / loadPaths.sh
Last active July 21, 2019 04:45
[Bash: profile load paths] #bash #profile #source #sh
# list profile paths loading variables
sudo bash -c "echo exit|dtruss bash -li|& less|grep '^open'"
# .bash_profile is for login shell, whereas .bashrc is for non-login shell (SSH)
@estysdesu
estysdesu / tips.go
Last active March 25, 2020 20:37
[Go: Ellipsis, JSON/Unmarshalling] #go #golang #ellipsis #json #pointers
// vim: syntax=go
// ***** 3 PERIODS (ELLIPSIS) UNPACK A VARIABLE *****
primes := []int{2, 3, 5, 7}
fmt.Println(Sum(primes...)) // 17
// ***** JSON STRUCTS *****
// A field with a json: struct tag is stored with its tag name instead of its variable name.
type user struct {
@estysdesu
estysdesu / create_constraint_if_not_exists.sql
Last active September 13, 2023 00:17
[PostgreSQL: create constraint if not exists] not sure of sql compatibility with other engines #postgres #constraint #sql
// vim: syntax=sql
CREATE OR REPLACE FUNCTION create_constraint_if_not_exists (t_name text, c_name text, constraint_sql text)
RETURNS void
AS
$BODY$
BEGIN
-- Look for our constraint
IF NOT EXISTS (SELECT constraint_name
FROM information_schema.constraint_column_usage
@estysdesu
estysdesu / tempFanWatch.sh
Last active July 21, 2019 06:48
[SMC-ish: continuously watch fan and CPU temperature metrics] #smc #powermetrics #osx #macos #fan #temp
#!/usr/bin/env bash
# https://github.com/estysdesu/dotFiles/blob/master/bin/lapHeater
warning=90
bad=120
nc='\033[0m' # no color
red='\033[0;31m'
yellow='\033[0;33m'
green='\033[0;32m'
@estysdesu
estysdesu / makefile
Last active July 31, 2019 11:28
[Make: set shell and brace expansion] #gnu #make #makefile #braces #expansion #sh
# `bin/sh` may not point to bash; setting `SHELL:=$(shell which bash)` ensures brace expansion (bashism) will work
SHELL:=$(shell which bash)
DIR_:=$(shell pwd)
.PHONY: clean
clean:
@bash -c "rm -rf $(DIR_)/{.vscode,venv,__pycache__}"