Skip to content

Instantly share code, notes, and snippets.

View rsperl's full-sized avatar

Richard rsperl

  • North Carolina, United States
View GitHub Profile
@rsperl
rsperl / create_swapfile.sh
Last active July 25, 2022 15:32
create swapfile on linux #snippet
#!/bin/bash
if [[ "$(whoami)" != "root" ]]; then
echo "script must be run as root"
exit 1
fi
block_size=1024
swapfile="$1"
@rsperl
rsperl / main.go
Last active July 25, 2022 15:30 — forked from salihzain/main.go
Go code to get the name of the function that invoked the current function #snippet
package main
import (
"fmt"
"runtime"
)
// whoCalledMe is a function that returns the name, fileName, and lineNumber of the caller that called function X
// the code doesn't check for edge cases
func whoCalledMe() (callerName, callerFileName string, callerLineNumber int) {
@rsperl
rsperl / script-template.sh
Last active July 25, 2022 13:11 — forked from m-radzikowski/script-template.sh
Bash Template #snippet
#!/usr/bin/env bash
# custom set -x output
PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
# set -x
set -Eeuo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1
@rsperl
rsperl / executed_or_sourced.sh
Last active July 25, 2022 15:28
How to determine if a shell script was sourced or executed #snippet
#!/bin/bash
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
echo "script was executed"
else
echo "script was sourced"
fi
@rsperl
rsperl / go-build.sh
Last active July 25, 2022 15:26 — forked from sivel/go-build.sh
Ansible Binary Golang Module #snippet
go build helloworld.go
GOOS=windows GOARCH=amd64 go build helloworld.go
@rsperl
rsperl / managing_dotenv_files.md
Last active July 25, 2022 15:24
managing .env files #snippet

Managing .env Files

The Problem

I use .env files to set environment variables for projects, but those values are different in local vs test vs prod. I also want support from my IDE and the commandline. VSCode and Intellij both support .env files, but if you want to point your application from local to test or prod, you have to update the .env file, which leaves me with an env file with lots of comments. Alternatively, you can update the IDE to point to another env file, but that gets a little non-standard by not using .env.

Solution

@rsperl
rsperl / is_power_of_2.py
Last active July 25, 2022 15:23
Determine if a number is a power of 2 #python #snippet
def log2(x):
if x == 0:
return False
return math.log10(x) / math.log10(2)
def is_power_of_two(n):
return math.ceil(log2(n)) == math.floor(log2(n))
@rsperl
rsperl / mac_commands.sh
Last active July 25, 2022 15:21
Mac commands #snippet
# disable verifying developer
spctl --master-disable
defaults write com.apple.dock expose-animation-duration -float 0.1
defaults write com.apple.LaunchServices LSQuarantine -bool false
defaults write com.apple.finder DisableAllAnimations -bool true
defaults write com.apple.finder ShowStatusBar -bool true
defaults write com.apple.finder _FXShowPosixPathInTitle -bool true
defaults write com.apple.finder _FXSortFoldersFirst -bool true
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
@rsperl
rsperl / panda_tricks.md
Last active July 25, 2022 12:47
panda tricks #python #panda #snippet

Python Pandas Tips and Tricks

source


Categories

@rsperl
rsperl / json_yml_converter.py
Last active July 25, 2022 15:17
converts yml to json and vice versa #snippet
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Create a link named json2yml and yml2json to this file.
If invoked as json2yml, it will convert json file to yml.
If invoked as yml2json, it will convert yml file to json.
"""
import sys
import json