Skip to content

Instantly share code, notes, and snippets.

View emdeeeks's full-sized avatar

Gareth Griffiths emdeeeks

View GitHub Profile
@amirrajan
amirrajan / main.rb
Created March 9, 2025 00:22
DragonRuby Game Toolkit - Endurance The Probe
class Game
attr_gtk
def current_level_name
# used by level editor to figure out which data file to save/load
state.levels[state.current_level_index] || :todo
end
# helper method to move rect within the camera
def to_screen_space target
@amirrajan
amirrajan / main.rb
Created January 15, 2025 14:01
Legion Story Progression Concept
class Probe
def queue_story!(predicate: nil, entries:, completion_action: nil, completion_checkpoint:, completion: nil)
raise "Either completion_action or completion must be provided." if !completion_action && !completion
return if @action == :story
return if @current_story_items.length > 0
return if checkpoint_reached?(completion_checkpoint)
should_queue = if predicate.is_a? Proc
predicate.call
elsif predicate.is_a? FalseClass
# this file sets up the main game loop (no need to modify it)
# play game here: https://samples.dragonruby.org/samples/99_genre_lowrez/nokia_3310_snake/index.html
require "app/nokia_emulation.rb"
class Game
attr :args, :nokia_mouse_position
def tick
# create a new game on frame zero
new_game if Kernel.tick_count == 0
@amirrajan
amirrajan / main.rb
Last active February 26, 2025 15:13
DragonRuby Game Toolkit - Towers of Hanoi implementation (https://amirrajan.itch.io/hanoi)
class Game
attr_gtk
# get solution for hanoi tower
# https://youtu.be/rf6uf3jNjbo
def solve count, from, to, other
solve_recur(count, from, to, other).flatten
end
# recursive function for getting solution
@amirrajan
amirrajan / main.rb
Last active February 26, 2025 22:21
DragonRuby Game Toolkit - Shader Tech Demo https://www.youtube.com/watch?v=LZgvvU91yyI
class Game
attr_gtk
def tick
defaults
render
input
calc
end
@bones-ai
bones-ai / empty_bevy_app.rs
Last active December 3, 2024 06:25
An basic empty bevy app template with all the plugins I use
use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
use bevy::prelude::*;
use bevy::window::close_on_esc;
const WW: f32 = 1200.0;
const WH: f32 = 900.0;
const BG_COLOR: (u8, u8, u8) = (25, 20, 43);
fn main() {
App::new()
@vidarh
vidarh / rubywm.rb
Created November 21, 2023 20:16
rubywm.rb - a minimalist WM using pure-x11 and based on TinyWM
# Based on TinyWM by Nick Welch
require 'X11'
dpy = X11::Display.new
root = dpy.screens.first.root
# OK, so pure-x11 *really* badly needs built in keysym lookup,
# but I don't want to add that without doing it properly, so this
@ghn
ghn / app_form_builder.rb
Created April 28, 2023 11:18
Rails customs form Builder
# frozen_string_literal: true
# Inspiration: https://brandnewbox.com/notes/2021/03/form-builders-in-ruby/
#
# Example:
#
# f.input :field, options
#
# possible options:
# - as: symbol (:boolean, :data, :float, :radio, :select, :string, :text, :file, :time)
@hopsoft
hopsoft / 00_do_stuff_job.rb
Last active September 13, 2024 15:03
ActiveJob as Service Worker
# ActiveJob natively captures constructor arguments in an `@arguments` instance variable
# which is also exposed as an `arguments` property on each job instance.
#
# Calls to `perform_now` and `perform_later` both forward arguments to the constructor.
#
# For example, all of these invocation styles work.
#
# result = DoStuffJob.new("foobar").perform # sync
# result = DoStuffJob.new.perform("foobar") # sync
# result = DoStuffJob.perform_now("foobar") # sync
@dpaluy
dpaluy / referrable.rb
Created February 12, 2023 19:14
Referrable Rails
module Referrable
extend ActiveSupport: :Concern
included do
has_one referral, foreign_key: "referred_user_id", dependent: : destroy has_one referring_user, through: :referral alias_method :referred_by, :referring_user
has_many :referrals, foreign_key: "referring_user_id", dependent: :nullify has_many :referred_users, through: referrals
validates :referral_code, uniqueness: true, allow_nil: true
end
end