Skip to content

Instantly share code, notes, and snippets.

View fivemoreminix's full-sized avatar

Luke Wilson fivemoreminix

View GitHub Profile
use std::rc::Rc;
use std::cell::RefCell;
pub struct Character {
pub display_name: String,
// TODO: ability to store arbitrary properties
}
impl Character {
pub fn new(name: impl Into<String>) -> Character {
@fivemoreminix
fivemoreminix / main.zig
Created February 23, 2021 23:50
Scale integers from of larger size to integers of a smaller size
const std = @import("std");
const maxInt = std.math.maxInt;
fn scaleInt(comptime DestType: type, val: anytype) DestType {
if (@bitSizeOf(@TypeOf(val)) > 16) {
@compileError("Function unsafe for values of bitsize greater than 16.");
}
const fv = @intToFloat(f32, val) / @intToFloat(f32, maxInt(@TypeOf(val))); // make ratio
return @floatToInt(DestType, fv * maxInt(DestType) + 0.5);
}
@fivemoreminix
fivemoreminix / copy.zig
Last active September 15, 2020 16:59
Copying files from a directory recursively with Zig...
/// Copy a source directory's files and its subdirectories' files to a destination. Will only copy directories and files.
fn copyRecursiveDir(src_dir: fs.Dir, dest_dir: fs.Dir, src_path: []const u8, dest_path: []const u8) anyerror!void {
var iter = src_dir.iterate();
while (true) {
const entry = try iter.next();
if (entry == null) {
break;
} else {
switch (entry.?.kind) {
.File => try src_dir.copyFile(entry.?.name, dest_dir, entry.?.name, fs.CopyFileOptions{}),
@fivemoreminix
fivemoreminix / friendly_coding_communities.md
Created May 25, 2020 02:37
A list of friendly programming communities.

Friendly Programming Communities

It's important that you connect with a community for something you want to learn, because it will help ease the learning process.

Discord

Discord is my preferred method of chatting. It's a good app, a lot of people use it. It's like the new Skype.

  1. The Handmade Network - Very talented people... let 'em know you're a newbie and you want guidance.
  2. Game Dev League - A community of hobbyist game developers.
  3. The Shebang - A smaller community of software developers. I used to co-own it. Drop me an @ ... I'm Code Messiah.
@fivemoreminix
fivemoreminix / build.zig
Last active November 13, 2019 14:22
Bounce a ball horizontally in your terminal window. This uses the `@cInclude` Zig feature and creates a very weak wrapper over the required ncurses features. You will need ncurses installed, and for Ubuntu-based systems it's as easy as `sudo apt install libncurses-dev`.
const Builder = @import("std").build.Builder;
pub fn build(b: *Builder) void {
const mode = b.standardReleaseOptions();
const exe = b.addExecutable("qubit", "src/main.zig");
exe.setBuildMode(mode);
exe.linkSystemLibrary("c"); // link with libc
exe.linkSystemLibrary("ncurses"); // link with ncurses.a (requires ncurses be installed where program is run)
@fivemoreminix
fivemoreminix / GuessingGame.java
Created October 29, 2019 12:56
A pseudo-programming language made to overengineer a guessing game.
/*
NUMBER GUESSING DOMAIN-SPECIFIC LANGUAGE IN JAVA
BY LUKE I. WILSON
*/
package org.vv;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Random;
package main
import (
"bufio"
"fmt"
"os"
"strings"
"time"
)
@fivemoreminix
fivemoreminix / heron.go
Last active September 15, 2019 21:12
A program to compute inverses of numbers (requires Go 1.13+ for floating-point hex)
package main
import (
"fmt"
"os"
"strconv"
)
const (
eps1m01 float64 = 1.0 - 0x1P-01
hello, friend, it is me george ohwell is back bitches
@fivemoreminix
fivemoreminix / unfilled_circle.gd
Last active April 24, 2019 02:57
Unfilled cicle script for GDScript
func draw_unfilled_circle(circle_center: Vector2, radius: float, color: Color, width = 1, resolution: float = 1):
var draw_counter = 1.0
var vec_radius = Vector2(radius, 0)
var line_origin = vec_radius + circle_center
var line_end = Vector2()
while draw_counter <= 360.0:
line_end = vec_radius.rotated(deg2rad(draw_counter)) + circle_center
draw_line(line_origin, line_end, color, width)
draw_counter += 1.0 / resolution