Skip to content

Instantly share code, notes, and snippets.

View demiters's full-sized avatar
🍕
Test status please ignore

Arturs Demiters demiters

🍕
Test status please ignore
  • CodeCraft
  • Riga, Latvia
View GitHub Profile
@demiters
demiters / getJSON.js
Last active December 13, 2017 18:31
Shortest getJSON implementation with fetch. Call: `const data = await getJSON('https://api.com')`
const getJSON = async (url) => await fetch(url)
.then(res => res.json())
.catch(err => console.error(`${err.message} (${url})`));
@demiters
demiters / index.html
Created December 13, 2017 19:03
Simple progress bar logic with materializecss.com and jQuery
<div id="progress" class="progress">
<div id="progressBar" class="determinate" style="width: 0%"></div>
</div>
@demiters
demiters / swap.sh
Created July 20, 2020 13:54
Creating swap space on Ubuntu 18.04 - 20.04
#!/bin/bash
# Creates 8GB of swap space and persists some recommended settings for servers
sudo fallocate -l 8G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
sudo sysctl vm.swappiness=10
@demiters
demiters / firewall.sh
Created July 23, 2020 12:04
ufw firewall for a microk8s server
#!/bin/bash
ufw default deny incoming
ufw default allow outgoing
ufw default allow routed
ufw allow OpenSSH
ufw allow http
ufw allow https
ufw allow in on cni0 && ufw allow out on cni0
ufw enable
@demiters
demiters / microk8s-aliases.sh
Created July 24, 2020 12:47
Shell aliases for microk8s
#!/bin/bash
# Sets up aliases for microk8s on the server
echo "alias m='microk8s'
alias k='microk8s kubectl'
alias h='microk8s helm3'" >> ~/.bash_aliases
source ~/.bash_aliases
@demiters
demiters / user.sh
Created July 24, 2020 12:56
Creates non-root user with ssh key auth on remote Ubuntu 20.04 server
#!/bin/bash
# Creates non-root user who can use ssh key auth, edit to your liking.
sudo apt install rsync
adduser arturs
usermod -aG sudo arturs
rsync --archive --chown=arturs:arturs ~/.ssh /home/arturs
@demiters
demiters / microk8s.sh
Last active July 24, 2020 13:24
Installs microk8s on a remote Ubuntu 20.04 server, with essential addons
#!/bin/bash
# Installs microk8s and enables addons:
# dns, ingress, helm3 (essential)
# dashboard (cluster monitoring)
# registry (private Docker registry)
# Installs and configures essential helm charts:
# external-dns (automating setting of dns records)
# cert-manager (automating issuing of https certificates)
@demiters
demiters / example.com.tf
Created July 24, 2020 13:30
Terraform setup for automated install of microk8s on a Ubuntu 20.04 DigitalOcean VPS. Edits required, see comments for more info.
# Edit name (example.com), region and size as you wish
resource "digitalocean_droplet" "example.com" {
image = "ubuntu-20-04-x64"
name = "example.com"
region = "fra1"
size = "s-2vcpu-4gb"
private_networking = true
ssh_keys = [
var.ssh_fingerprint
]
@demiters
demiters / windows-host-setup.ps1
Last active August 31, 2020 08:25
PowerShell script that configures WinRM for use with Ansible
$url = "https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1"
$file = "$env:temp\ConfigureRemotingForAnsible.ps1"
(New-Object -TypeName System.Net.WebClient).DownloadFile($url, $file)
powershell.exe -ExecutionPolicy ByPass -File $file
@demiters
demiters / windows-playbook.yml
Last active August 31, 2020 08:12
Ansible example playbook for installing Windows 10 software
---
- hosts: localhost
connection: local
tasks:
- name: Install Chocolatey packages
win_chocolatey:
name:
- vscode
- git
- nvm