CurrentAttributes came out on Rails 5.2 allow us to control session variables, follow steps bellow
# frozen_string_literal: true| 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 |
| 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") |
| 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 { |
| class OrderStateMachine | |
| include Statesman::Machine | |
| state :pending, initial: true | |
| state :checking_out | |
| state :purchased | |
| state :shipped | |
| state :cancelled | |
| state :failed | |
| state :refunded |
| 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 |
| 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))) |
| relative_require "record" | |
| class Record | |
| record :a, :b | |
| end | |
| a = Record.new(a: 10, b: 20) | |
| a = a.merge(b: 10) | |
| p a |
| # 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 |
| # demo gameplay here: https://youtu.be/wQknjYk_-dE | |
| # this is the core game class. the game is pretty small so this is the only class that was created | |
| class Game | |
| # attr_gtk is a ruby class macro (mixin) that adds the .args, .inputs, .outputs, and .state properties to a class | |
| attr_gtk | |
| # this is the main tick method that will be called every frame the tick method is your standard game loop. | |
| # ie initialize game state, process input, perform simulation calculations, then render | |
| def tick | |
| defaults |