Skip to content

Instantly share code, notes, and snippets.

View drblue's full-sized avatar
🔥
All Your Memes Are Belong To Me

Johan Nordström drblue

🔥
All Your Memes Are Belong To Me
View GitHub Profile
@drblue
drblue / recommended-vscode-extensions.md
Created September 10, 2024 14:37
Recommended VS Code extensions
@drblue
drblue / logf.sh
Created August 17, 2024 14:43
Log output of a command to both a file and the console.
#!/bin/bash
# Function to show usage
usage() {
echo "logf: A script to execute a command and log its output to both a file and the console."
echo
echo "Usage: $0 [-a] <logfile> <command> [args...]"
echo " -a Append to the logfile instead of overwriting"
exit 1
}
@drblue
drblue / clone-student-repos.sh
Created August 17, 2024 14:40
Script for cloning all student repos (including support for pagination) from a GitHub Classroom-repo.
#!/bin/bash
# Clones all student repos from GitHub Classroom using the GitHub CLI with GitHub Classroom extension
# Accepts an assignment ID as an argument
# If no argument is provided, it will show all assignments and prompt for one
# If there are more than 30 repos, it will prompt to continue and clone the next page until all repos are cloned
# Function to round up
ceil() {
num=$1
printf "%.0f\n" $(echo "$num + 0.999" | bc)
@drblue
drblue / netlify.toml
Last active May 23, 2024 12:27
Netlify Config for Vite React apps
# Netlify Config for Vite React apps
#
# See <https://docs.netlify.com/configure-builds/file-based-configuration/>
# for more info on configuring this file.
[build]
command = "tsc && vite build"
functions = "netlify/functions"
publish = "dist"
[[redirects]]
@drblue
drblue / .bashrc
Created November 15, 2022 14:32
Git-prompt for bash
function git-branch-name {
git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3
}
function git-branch-prompt {
local branch=`git-branch-name`
if [ $branch ]; then printf " [%s]" $branch; fi
}
PS1="\u@\h \[\033[0;36m\]\w\[\033[0m\]\[\033[0;32m\]\$(git-branch-prompt)\[\033[0m\] \$ "
@drblue
drblue / products.js
Created March 29, 2022 09:13
Array reduce + map
const products = [
{ name: "Product 1", price: 42 },
{ name: "Product 2", price: 20 },
{ name: "Product 3", price: 1337 },
];
const totalValue = products
.filter(product => product.price > 30)
.reduce( (sum, product) => {
return sum + product.price
@drblue
drblue / classes.js
Last active March 29, 2022 08:54
Classes in JavaScript
class Rectangle {
constructor(rooms, jacuzzi, solarPanels = true) {
if (typeof height !== "number") {
throw new Error("Height is not a number")
}
this.height = height
this.width = width
}
area() {
@drblue
drblue / class.MyWidgetSkeleton.php
Last active June 17, 2021 08:00
A skeleton of a widget.
<?php
class MyWidgetSkeleton extends WP_Widget {
/**
* Construct a new widget instance.
*/
public function __construct() {
parent::__construct(
'my-widget-skeleton', // Base ID
@drblue
drblue / http.js
Created April 6, 2020 15:28
node.js http server example
/**
* http
*/
const http = require('http');
const server = http.createServer();
server.on('request', function (req, res) {
// code here
res.writeHead(200, {
'Content-Type': 'text/html',
@drblue
drblue / events.js
Created April 6, 2020 15:12
node.js event emitter demo (es6)
/**
* events
*/
const events = require('events');
class Person extends events.EventEmitter{
constructor(name){
super();
this.name = name;
}