Skip to content

Instantly share code, notes, and snippets.

View ambakshi's full-sized avatar

Amit Bakshi ambakshi

View GitHub Profile
#!/bin/bash
#
# Create a variable `$key` for use in powershell as a AES encyrption key
# constant with (ConvertFrom-SecureString)[https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/convertfrom-securestring?view=powershell-7.2)]
#
# param: $1 secret key (optional, default: secret)
# param: $2 cipher (optional, default: aes-256-cbc)
# output: An byte array (in decimals), the size of the encryption key (AES256 = 32 bytes)
genkey() {
@ambakshi
ambakshi / parse-opts.sh
Last active January 10, 2021 10:31
parse-opts.sh
#!/usr/bin/env bash
#
# MIT Licensensed
# Amit Bakshi Jan 2021
# Generic option parser.
# Usage:
# parse_opts --valid-args 'foo bar link' -- --with-foo=yes --bar=fizz --no-link
#
# Yields:
@ambakshi
ambakshi / ssh-keygen.service
Last active August 6, 2020 00:52 — forked from TimJDFletcher/ssh-keygen.service
Systemd unit to generate missing ssh keys on boot
[Unit]
Description=Generate sshd keys
Before=ssh.service
ConditionPathExists=!/etc/ssh/ssh_host_rsa_key
[Service]
Type=oneshot
ExecStart=/usr/bin/ssh-keygen -A
RemainAfterExit=true
StandardOutput=journal
@ambakshi
ambakshi / gcccpuopt.sh
Last active April 28, 2023 07:18
Determine set of best gcc optimization flags for the current host.
#!/bin/sh
# Print the gcc cpu specific options tailored for the current CPU
# Author:
# http://www.pixelbeat.org/
# Notes:
# This script currently supports Linux,FreeBSD,Cygwin
# This script is x86 (32 bit) specific
# It should work on any gcc >= 2.95 at least
@ambakshi
ambakshi / osx-fix-home-and-end-keys.sh
Created February 20, 2018 13:51
Fixes the osx home/end keys so they work the way they do on Linux/Windows.
#!/bin/sh
mkdir -p ~/Library/KeyBindings
cd ~/Library/KeyBindings
if test -e DefaultKeyBinding.dict; then
echo >&2 "WARNING: Skipping customizing key bindings. $(pwd)/DefaultKeyBinding.dict already exists"
exit 0
fi
cat > DefaultKeyBinding.dict <<'EOF'
{
@ambakshi
ambakshi / storeid_rpmdeb.go
Last active May 9, 2018 14:16
Simple store_id_program for squid. Build it, put it into /usr/lib64/squid/, and add "store_id_program /usr/lib64/squid/storeid_rpmdeb" to your squid.conf
package main
import (
"bufio"
"fmt"
"os"
"regexp"
"strings"
)
@ambakshi
ambakshi / letsencrypt.sh
Last active May 15, 2017 21:39
Obtain LE certs for multiple SANs
#!/bin/bash
#
# Get LetsEncrypt SSL certs
#
# Usage:
# letsencrypt.sh host1.domain.com host2.domain.com ...
#
# You must have your git config user.email set correctly
#
# The way this script works is that you register a wildcard DNS
@ambakshi
ambakshi / g++-5.sh
Created April 1, 2016 11:57
Install g++ 5.x on Ubuntu Trusty (14.04)
#!/bin/bash
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common
add-apt-repository ppa:ubuntu-toolchain-r/test
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y g++-5 gcc-5
@ambakshi
ambakshi / xcabakshimbp.pub
Created April 1, 2016 05:30
abakshi@xcabakshimbp.local
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDeFQ/NE6ZgqhUaj+lyc5jbEJkkwWjDxSddXOhFDs5e4Mni06m+vrI4rNoZ4mdP3l2p2rECBgPjE59SYbswUlzJWKhdBWLK0BH+rKn5fXjH/2VbE4YrVJaHONjhsLqLNKfvD7C5CC6T7hcwafwNwDjVblmXr/VydIhETnLnwnRZTXA0fTvd/W15gwpMQ+XY/cpTLaAH00oX26nfZRJCdKcVnPIa+OwBD3t2R3tzGdsevvprVCg80Tmyy6LYqLF4dLZVYz/o8G1QNgyjmvhIxyEYFQscT9LL70qfKz/UAUQTdiYr8Z73OXAzDXqNN46PvHSm35W3kQzizsd4KQWEom8J abakshi@xcabakshimbp.local
@ambakshi
ambakshi / debian-jdk8-install.sh
Last active May 27, 2016 18:01
Install Oracle JDK 8 on a Debian based system.
#!/bin/bash
export DEBIAN_FRONTEND=noninteractive
apt-get update && apt-get install -yq software-properties-common apt-utils
add-apt-repository ppa:webupd8team/java -y && apt-get update && \
echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \
echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C2518248EEA14886 && \
apt-get install -y --no-install-recommends oracle-java8-installer