Skip to content

Instantly share code, notes, and snippets.

View blogscot's full-sized avatar

Iain Diamond blogscot

View GitHub Profile
@blogscot
blogscot / main.rs
Created May 12, 2025 13:22
Snake Game using Bevy v0.16.0
// Original Snake Tutorial: Creating a Snake Clone in Rust, with Bevy [0.7.0]
// https://mbuffett.com/posts/bevy-snake-tutorial/
use bevy::{prelude::*, time::common_conditions::on_timer, window::PrimaryWindow};
use rand::random;
use std::time::Duration;
const SNAKE_HEAD_COLOR: Color = Color::srgb(0.7, 0.7, 0.7);
const SNAKE_SEGMENT_COLOR: Color = Color::srgb(0.3, 0.3, 0.3);
const FOOD_COLOR: Color = Color::srgb(1.0, 0.0, 1.0);
@blogscot
blogscot / main.zig
Created March 17, 2025 11:12
Building Zig structs at Compile Time by mht.wtf
/// Building Zig structs at Compile Time by mht.wtf
/// https://mht.wtf/post/comptime-struct/#user-content-fnref-typeinfo
///
/// Reading through the blog post originally written on 11 June 2022 with
/// Zig version 0.9.1, I got the examples working for 0.14.0
///
const std = @import("std");
const print = std.debug.print;
fn Range(comptime T: type) type {
@blogscot
blogscot / eviscerate-sequence_test.clj
Created April 20, 2022 21:31
Discord Server: Clojure Study Group Solution #1
(ns eviscerate-sequence-test
(:require [clojure.test :refer [deftest is run-tests]]))
(defn eviscerate-sequence
([xs n] (eviscerate-sequence xs n n))
([xs n m]
(let [v (vec xs)]
(concat (subvec v 0 n) (subvec v (inc m))))))
(deftest eviscerate-sequence-test
@blogscot
blogscot / data.csv
Created August 5, 2019 12:26
Creating a HTML table from CSV data using D3
car name miles/gallon cylinders displacement horsepower weight acceleration model year origin
chevrolet chevelle malibu 18 8 307 130 3504 12 70 1
buick skylark 320 15 8 350 165 3693 11.5 70 1
plymouth satellite 18 8 318 150 3436 11 70 1
@blogscot
blogscot / index.html
Created May 15, 2019 12:00
An example of how to use Vue Slot Props
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>VueJS</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
@blogscot
blogscot / basicBlockChain.kt
Created December 1, 2018 16:17
An basic Blockchain example in Kotlin
import com.google.gson.GsonBuilder
import java.security.MessageDigest
import java.util.Date
// This example is a port of the Java version described by:
// https://medium.com/programmers-blockchain/create-simple-blockchain-java-tutorial-from-scratch-6eeed3cb03fa
typealias BlockChain = ArrayList<Block>
@blogscot
blogscot / shipBuilding.kt
Created November 26, 2018 23:08
Example of the Builder pattern using Kotlin
class Ship {
var name: String = ""
var crewSize: Int = 0
var numMasts: Int = 0
override fun toString(): String {
return "Ship { Name: $name, Num masts: $numMasts Crew Size: $crewSize}"
}
}
@blogscot
blogscot / huffmanEncoding.kt
Created November 22, 2018 13:57
A Kotlin implementation of Huffman Encoding
import java.util.PriorityQueue
// node class is the basic structure
// of each node present in the huffman - tree.
class HuffmanNode : Comparable<HuffmanNode> {
var freq = 0
var chr = ' '
var left: HuffmanNode? = null
var right: HuffmanNode? = null
@blogscot
blogscot / visitor.rs
Last active April 27, 2018 18:01
Visitor Pattern Example in Rust
///
/// Each car element accepts a visitor.
///
trait CarElement {
fn accept(&self, visitor: &CarElementVisitor);
}
///
/// Each visitor must deal with each element of a car.
///
trait CarElementVisitor {
@blogscot
blogscot / enum.js
Created August 31, 2017 12:11
A basic JavaScript Enum constructor function
// A basic Enum constructor function
const Enum = (...values) => {
let newEnum = {}
for (const value of values) {
Object.assign(newEnum, {
[value]: value
})
}
return newEnum
}