Skip to content

Instantly share code, notes, and snippets.

View ZeroPivot's full-sized avatar
💭
Working on Ruby/Rust Projects.

ArityWolf ZeroPivot

💭
Working on Ruby/Rust Projects.
View GitHub Profile
@ZeroPivot
ZeroPivot / triangle.rs
Created July 16, 2024 23:09 — forked from kylewlacy/triangle.rs
Rust gfx triangle example using SDL2
// Copyright 2014 The Gfx-rs Developers.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
def lagrange_four_squares(n)
# Initialize the squares array with zeros
squares = [0, 0, 0, 0]
# First check if n is a perfect square
if Math.sqrt(n) % 1 == 0
squares[0] = Math.sqrt(n).to_i
return squares.join('² + ') + '²'
end
# Common configuration.
AllCops:
TargetRubyVersion: 3.0
NewCops: enable
SuggestExtensions: true
RubyInterpreters:
- ruby
- macruby
- rake
# Partitioned Arrays
**WIP.** - ***Last updated: 3/31/2022**
A partitioned array data structure which works with JSON for disk storage, and a pure JSON parser is in progress. With two constants, the algorithm creates a data structure and allocates empty associative array elements and understands the structure of the partitions.
The main purpose was I needed a way to divide an array into subelements, so that in gamedev I can flip on and off portions of the array in question to save on memory.
The data structure overall is an `Array-Of-Hashes`.
# rubocop:disable Style/FrozenStringLiteralComment
# rubocop:disable Style/IfUnlessModifier
# rubocop:disable Layout/LineLength
# Ranged binary search, for use in CGMFS
# array_id = relative_id - db_num * (partition_rate + 1)
# When checking and adding, see if the index searched for in question
PARTITION_RATE = 10
OFFSET = 1
# Common configuration.
AllCops:
TargetRubyVersion: 3.0
NewCops: enable
SuggestExtensions: true
RubyInterpreters:
- ruby
- macruby
- rake
@ZeroPivot
ZeroPivot / .rubocop.yml
Last active September 30, 2021 17:53 — forked from dsandstrom/.rubocop.yml
Rubocop config files for Ruby 3.0 / Rails 6+
# .rubocop.yml
# rubocop config files for Ruby 3.0 / Rails 6+ project
AllCops:
TargetRubyVersion: 3.0
NewCops: enable
SuggestExtensions: true
Include:
# A Study of "Value Objects" in Ruby 3.0 with RBS for static typing
#
# Ruby Code by ZeroPivot
#
# Studied from JavaScript article @ plainenglish.io (by Nayab Siddiqui);
# * URL: https://javascript.plainenglish.io/why-you-should-stop-representing-age-as-a-number-in-your-code-ea1026a86bc8
# A Value Object Class named Age
# Returns a new Age object on the addition of time (y/m/d)
# Instance objects are treated in an immutable fashion
# rubocop:disable Style/StringLiterals
# rubocop:disable Style/FrozenStringLiteralComment
# rubocop:disable Lint/RedundantCopDisableDirective
# rubocop:disable Layout/TrailingEmptyLines
# rubocop:disable Lint/RedundantCopDisableDirective
# rubocop:disable Layout/EmptyLines
require 'json'
require_relative 'aoh'
# Converts some string to JSON format, mostly for usage in the DragonRuby toolkit
@ZeroPivot
ZeroPivot / sinatra_cheatsheet.md
Created January 24, 2021 19:17 — forked from taktran/sinatra_cheatsheet.md
Sinatra cheatsheet

Useful commands

last_response
    .body

last_request
    .path
    .url
    .session

.cookies