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
Last active March 25, 2025 16:57
DragonRuby Game Toolkit Sprite Sheet Example
def tick args
args.labels << [640, 689, "Asset Presenter", 0, 1]
args.sprites << tile(0, 0, 100, 100)
args.sprites << tile(1, 0, 200, 200)
args.sprites << tile(2, 0, 300, 300)
10.map_with_index do |x|
10.map_with_index do |y|
args.sprites << tile(x, y, 30 + x * 64, 30 + y * 64)
end
@scmx
scmx / extract-objects-from-rails-models-and-controllers.md
Last active May 19, 2025 14:17
7 Patterns to Refactor Rails Models 7 years later #rails #model #refactor #valueobject #serviceobject #formobject #queryobject #viewobject #policyobject #decorator

7 Patterns to Refactor Rails Models 7 years later

You may have read the following excellent blogpost by Brian Helmkamp of CodeClimate. It nicely describes 7 types of objects that can be extracted from models and controllers in a Rails-app.

7 Patterns to Refactor Fat ActiveRecord Models https://codeclimate.com/blog/7-ways-to-decompose-fat-activerecord-models/ Brian Helmkamp on Oct 17, 2012.

Here are my thoughts on it, reading it as an experienced rails developer, 7 years later 😅 👴

@amirrajan
amirrajan / main.rb
Last active March 25, 2025 16:56
dragonruby gtk faux 3D
def cos v
Math.cos v
end
def flr n
n.floor
end
def sin v
Math.sin v
@0x263b
0x263b / archive_dm.rb
Last active September 25, 2021 13:28
Archive a discord DM and all attachments
#!/usr/bin/env ruby
# encoding: utf-8
Encoding.default_external = "UTF-8"
Encoding.default_internal = "UTF-8"
require "open-uri"
require "json"
require "net/https"
require "uri"
require "date"
@obelisk68
obelisk68 / tetris_for_Ruby2D.rb
Last active December 15, 2024 14:50
Ruby2D を使ったテトリス
require "ruby2d"
include Ruby2D::DSL
Wait = 18
class Tetromino
def initialize
@pat = Array.new(4)
pats = [["1111"], ["11", "11"], ["011", "110"], ["110", "011"],
["100", "111"], ["001", "111"], ["010", "111"]]
@dorzepowski
dorzepowski / clockify.sh
Last active November 18, 2019 18:16
Clockify simple CLI
#!/bin/bash
########################################################################################################################
########################################################################################################################
# README:
#
# This script is currently prepared to add work log entries (time entries) to clockify from command line.
# Currently supported parameters for time entry are:
# - Project Name (project will be searched in clockify by name case sensitive)
# - Tag Name (tag will be searched in clockify by name case sensitive [only one tag can be provided currently])
@dvinciguerra
dvinciguerra / simple_event_broker.rb
Created March 15, 2019 11:29
Ultra simple event broker made using Ruby
class Action
attr_reader :name, :payload, :callback
def initialize(**args, &block)
@name = args[:name]
@payload = args[:payload] || {}
@callback = block || proc {}
end
def process(payload)
@kwent
kwent / cancelable.rb
Created December 30, 2018 23:17
Cancelable Rails concern
module Cancelable
extend ActiveSupport::Concern
included do
scope :with_cancelled, -> { where.not(cancelled_at: nil) }
scope :not_cancelled, -> { where(cancelled_at: nil) }
def cancel
# Use update_attributes and not touch to trigger after_save
@emdeeeks
emdeeeks / chat.rb
Created December 25, 2018 20:56 — forked from PurwadiPw/chat.rb
Simple chat ruby using eventmachine
#!/usr/bin/env ruby
require 'rubygems'
require 'eventmachine'
class Server
attr_accessor :connections
def initialize
@connections = []
@ximus
ximus / change tracking.rb
Last active October 20, 2023 13:54
5min illustration of cheap and dirty change tracking with activerecord
# WARN: this relies on the single threaded nature of our apps!
class ApplicationModel < ActiveRecord::Base
before_save do
if ChangeTracking.currently_change_tracking?
changeset << [:update, self, changes]
end
end
before_create do