Skip to content

Instantly share code, notes, and snippets.

View malted's full-sized avatar
🦧
ヾ(*ФωФ)βyё βyё☆彡

Ben malted

🦧
ヾ(*ФωФ)βyё βyё☆彡
View GitHub Profile
#!/bin/bash
# Exit on any error
set -e
echo "Starting Hackatime setup..."
# Step 1: Check if config directory exists and create if needed
WAKATIME_CONFIG_DIR="$HOME"
WAKATIME_CONFIG_FILE="$WAKATIME_CONFIG_DIR/.wakatime.cfg"
@malted
malted / serversetup.sh
Last active November 20, 2023 20:27
Server setup
#!/usr/bin/env bash
# USAGE: serversetup.sh <NEW_USERNAME> <IP>
DESIRED_REMOTE_USERNAME=$1
EXISTING_REMOTE_USER=root # Assumes you already have a key for for root on your machine.
REMOTE_IP=$2
KEY_NAME=id_ed25519_$(echo $REMOTE_IP | tr . -)
LOCAL_KEY_LOCATION=$HOME/.ssh/$KEY_NAME
@malted
malted / analyser.c
Created October 24, 2022 19:42
Shapefile header analyser
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
unsigned char headerBuffer[100];
FILE *ptr;
ptr = fopen(argv[1], "rb");
@malted
malted / main.rs
Created September 26, 2022 16:14
Rust Run-Length Encoding
fn main() {
println!("Original text:\t");
let mut line = String::new();
std::io::stdin().read_line(&mut line).unwrap();
line = line.trim().to_string();
let mut last_character = line.chars().next().unwrap();
let mut character_count = 0;
let mut final_string = String::new();
@malted
malted / minify.py
Last active August 13, 2022 21:48
A minifier for Brainfuck scripts.
import sys
def main():
min_file_name = sys.argv[1].split('.')
min_file_name.insert(len(sys.argv) - 1, "min")
min_file_name = '.'.join(min_file_name)
with open(min_file_name, "w+") as min_file:
final = ""
with open(sys.argv[1]) as src_file:
@malted
malted / hotspot.sh
Created December 20, 2021 20:52
Creates a wifi hotspot
#!/bin/bash
sudo rm /tmp/create_ap.all.lock
sudo lnxrouter --ap wlp1s0 <SSID> -p <PASSWORD>
function finish {
sudo ip link set wlp1s0 state UP
}
trap finish EXIT
@malted
malted / Graph.svelte
Created November 23, 2021 20:41
Fully Dynamic Svelte Graph Component
<script>
import { onMount } from 'svelte';
import { fly } from "svelte/transition";
let ready = false;
onMount(() => ready = true);
const dataset = [
{ name: "Apple", price: 6 },
{ name: "Orange", price: 5 },
function endian() {
const uInt16 = new Uint16Array([0x1122]);
const uInt8 = new Uint8Array(uInt16.buffer);
// If the first byte is 0x11, then we are on a big endian system, as they place the most significant byte first.
// (The most significant byte is the byte that has the greatest value.)
if (uInt8[0] === 0x11) console.log("Big endian system");
// On a big endian system, the most significant byte is first.
// So the first byte is 0x11 (0001 0001) (17)
@malted
malted / sveltekit-init
Last active April 3, 2022 09:10
Initialise a Sveltekit project & push to a new repository.
#!/bin/bash
if [ -d "$1" ]; then # If the directory exists
if [ "$(ls -A $1)" ]; then
# The directory exists & contains files
echo "$1 is not empty. Exiting."
exit 0
else
# The directory exists & is empty
rmdir $1
fi
@malted
malted / README.md
Last active September 15, 2021 18:05
Autolocker

Autolocker

My screen auto lock implementation

Required packages

sudo pacman -S xautolock slock dunst

Explanation

xautolock runs slock - a simple screen locker - after no input has been detected for 5 minutes.