Skip to content

Instantly share code, notes, and snippets.

View emdeeeks's full-sized avatar

Gareth Griffiths emdeeeks

View GitHub Profile
@tompng
tompng / colorize.rb
Last active August 26, 2023 08:43
福岡rubyist会議Quine
require'irb/color'
code = File.read(ARGV[0] || 'fukuokark.rb')
def hoge(s)
s.gsub("eval(s*'')","$a=s*''")
end
eval code.gsub('then{;eval', 'then{eval hoge')
w = 132
ended = false
colored = IRB::Color.colorize_code(code.lines[0].dup+'%').gsub(/\n.+/,"\n")
@Kellojo
Kellojo / WaveFunctionCollapse.cs
Created December 12, 2022 21:43
A simple wave function collapse algorithm implementation useful for procedural generation
using Kellojo.Utility;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WaveFunctionCollapse<T> where T : IWfcTile<T> {
public WfcCell<T>[,] Cells;
public int Entropy {
@ikaruga777
ikaruga777 / 0_order_state_machine.rb
Last active June 24, 2024 16:37
statesman2mermaid
class OrderStateMachine
include Statesman::Machine
state :pending, initial: true
state :checking_out
state :purchased
state :shipped
state :cancelled
state :failed
state :refunded
@amirrajan
amirrajan / main.rb
Last active February 26, 2025 21:04
DragonRuby Game Toolkit - Camera Shake (https://www.youtube.com/watch?v=-i1ILZsIqbU&ab_channel=AmirRajan)
def calc_camera
if player_charging?
if player_charge_percentage < 0.2
state.camera.trauma += 0.005
elsif player_charge_percentage < 0.5
state.camera.trauma += 0.01
elsif player_charge_percentage < 0.8
state.camera.trauma += 0.02
else
state.camera.trauma += 0.04
@matt-dray
matt-dray / perlin-dungeon-map-demo.R
Last active July 6, 2024 12:47
Quick demo of perlin noise from the {ambient} R package to generate a dungeon map
print_perlin_dungeon <- function(
m, # matrix of perlin noise via ambient::noise_perlin()
invert = FALSE # flips tile positions (use set.seed before generating noise)
) {
tile_wall = "#"
tile_floor = "."
# Standardise noise values from 0 to 1
m_bin <- round((m - min(m)) / (max(m) - min(m)))
@LucasBarretto86
LucasBarretto86 / rails_current_class_and_current_attributes.md
Last active February 2, 2023 21:16
Current class and ActiveSupport::CurrentAttributes Basic Implementation

Current class and ActiveSupport::CurrentAttributes

CurrentAttributes came out on Rails 5.2 allow us to control session variables, follow steps bellow

Basic implementation for common usage

Create current.rb class

# frozen_string_literal: true
@bradgessler
bradgessler / component_helper.rb
Last active April 10, 2023 15:01
Sane way to call a ViewComponent
# Copy this file to ./app/views/component_helper.rb if you want to unlock ViewComponent rendering super powers.
module ComponentHelper
# Instead of the awkward `render FooComponent.new(title: "foo")` calls in Rails templates,
# use a method like `foo_component title: "foo"`.
def method_missing(method_name, *args, **kwargs, &block)
if method_name.end_with? "_component"
component_class = method_name.to_s.classify.constantize
component = component_class.new(*args, **kwargs)
component.render_in(self, &block)
else
# frozen_string_literal: true
class ApplicationComponent < ViewComponent::Base
end
@pbstriker38
pbstriker38 / progress_circle_component.html.erb
Created December 9, 2021 19:23
Circular progress bar ViewComponent
<!-- Circle -->
<div>
<!-- Building a Progress Ring: https://css-tricks.com/building-progress-ring-quickly/ -->
<svg height="<%= @diameter %>" width="<%= @diameter %>">
<circle
class="text-gray-300"
stroke-width="<%= @stroke_width %>"
stroke="currentColor"
fill="transparent"
r="<%= normalized_radius %>"
@Stylesproline
Stylesproline / README.md
Created December 9, 2021 07:53
Awesome-Selfhosted