Skip to content

Instantly share code, notes, and snippets.

View benphelps's full-sized avatar
🇺🇦
Slava Ukrayini!

Ben Phelps benphelps

🇺🇦
Slava Ukrayini!
View GitHub Profile
@benphelps
benphelps / fmt.lua
Created July 19, 2024 10:22
A simple libfmt-esque addition to the lua string library.
-- A simple string formatting function that supports named arguments.
-- It is inspired by libfmt (https://github.com/fmtlib/fmt) and Python's str.format() method.
---@param input string The string to format.
---@vararg any The arguments to format the string with.
---@return string formatted The formatted string.
local function fmt(input, ...)
local args = { ... }
local is_table_arg = type(args[1]) == "table" and #args == 1
local index = 1
@benphelps
benphelps / raylib.lua
Created June 26, 2024 14:19
LuaLS (EmmyLua) type definitions for most of raylib + raygui
---@meta raylib
---@class (exact) Vector2
---@field x number x component
---@field y number y component
---@overload fun(x: number, y: number): Vector2
---@overload fun(): Vector2
Vector2 = {}
---@class (exact) Vector3
phelps:7qVlf2c69e7daca8b0b5cb0d3bc869faff3719a359777d8f5741f9739f212b34637a:175dac88690
require "./spec_helper"
def test_statement(statement : AST::LetStatement, name : String)
it "expectes token_literal to be let" do
statement.token_literal.should eq("let")
end
it "should be an AST::LetStatement" do
statement.should be_a(AST::LetStatement)
end
@benphelps
benphelps / pitmaster.lua
Last active September 30, 2019 21:35
A computer craft turtle program.
--[[
How about no.
]]
local CHEST_SLOT = 16
local PIT_WIDTH = 3
local PIT_LENGTH = 3
local PIT_DEPTH = 45
local function log(str, ...)
@benphelps
benphelps / Abstraction.php
Created May 10, 2017 22:16
PDO Abstraction
<?php
namespace PDG\Database;
use PDO;
/**
* An actually simple PDO wrapper. Woah, dude.
*/
class Abstraction
require 'active_support/inflector'
guard :rspec, cmd: 'WAT=wat spring rspec' + (ENV['DOC_FORMAT'] ? ' --format documentation' : ''), notification: false do
watch(%r{^spec/features/.+_spec\.rb$})
watch(%r{^spec/models/.+_spec\.rb$})
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1].singularize}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| "spec/features/#{m[1].singularize}_spec.rb" }
watch(%r{^app/models/(.+)\.rb$}) { |m| "spec/models/#{m[1]}_spec.rb" }
watch(%r{^spec/factories/(.+)_spec\.rb$}) do |m|
["app/models/#{m[1].singularize}.rb", "spec/models/#{m[1].singularize}_spec.rb"]
@benphelps
benphelps / __readme.md
Last active September 9, 2020 22:14
Action Specific Javascript for Rails 5

Action Specific Javascript for Rails 5

This is a simple example of action specific javascript. It also allows you to pass data to JS from inside rails controllers. Works with Turbolinks 5 (not required).

Installation

Add the files below to your project, then insert <%= insert_javascript_hook %> somewhere in the footer of your layout.

You'll need these gems:

gem 'jquery-rails'
def sub_heading(content = nil)
@sub_headings ||= []
if content
@sub_headings.push content
elsif block_given?
@sub_headings.each do |sub_heading|
yield sub_heading
end
else
Enumerator.new do |y|
@benphelps
benphelps / .gitlab-ci.yml
Created January 11, 2017 16:33
A test / deploy setup I use
image: benphelps/docker-ruby-phantomjs:latest
Testing:
services:
- postgres:latest
variables:
POSTGRES_DB: test
POSTGRES_HOST: postgres
POSTGRES_USER: testuser
POSTGRES_PASS: testuser
environment: test