Skip to content

Instantly share code, notes, and snippets.

View prehnRA's full-sized avatar

Robert Prehn prehnRA

View GitHub Profile
class CheckSlowPokeJob < ActiveJob::Base
def perform(slowpoke) # The slowpoke to check
slowpoke.check()
end
end
slowpoke = SlowPoke.find(1)
# Queues up a job to check slowpoke #1 later
CheckSlowPokeJob.perform_later(slowpoke)
my_bar = Bar.find(1)
my_baz = Baz.find(1)
my_bar.to_global_id # gid://foo/Bar/1
my_baz.to_global_id # gid://foo/Baz/1
my_bar.id == my_baz.id # true
my_bar.to_global_id == my_baz.to_global_id # false
class Shufflebag < Enumerator
def initialize(arr)
i = 0
super() do |y|
loop do
arr = arr.shuffle if i == 0
y << arr[i]
i = (i + 1) % arr.length
end
end
class LRS
SIZE = 10
attr_accessor :key_history, :inner
def initialize()
self.key_history = []
self.inner = {}
end
def get(key)
@prehnRA
prehnRA / word_wrap.rb
Created October 30, 2015 16:41
Coding Challenge: Word Wrap
# Write a method called `word_wrap` that takes 1 to 2 arguments.
# The first argument is a string.
# The second argument is optional, and represents a maximum line length. The
# default value should be 80.
# `word_wrap` should a string formatted such that no line is longer than the
# line length specified by the second argument (i.e. no more than N characters
# between newlines).
# You should not break words apart, however, you can assume that the line width
# will never be shorter than the longest word.
# Write a method called `word_wrap` that takes 1 to 2 arguments.
# The first argument is a string.
# The second argument is optional, and represents a maximum line length. The
# default value should be 80.
# `word_wrap` should a string formatted such that no line is longer than the
# line length specified by the second argument (i.e. no more than N characters
# between newlines).
# You should not break words apart, however, you can assume that the line width
# will never be shorter than the longest word.
class Node
attr_accessor :next
def initialize(nxt)
@next = nxt
end
def self.linked_list_with_cycle
node = linked_list_without_cycle
node.next.next.next = node
@prehnRA
prehnRA / StripeShader.shader
Last active May 6, 2016 03:19
A basic shader for making grids on an object
Shader "Unlit/StripeShader"
{
Properties
{
// Color property for material inspector, default to white
// _Color is the color of the grid lines, actually (need to flip these
// at some point)
_Color ("Main Color", Color) = (1,1,1,0.5)
// _Color2 is actually the main body color
_Color2 ("Other Color", Color) = (1,1,1,0.5)
@prehnRA
prehnRA / StatsTest.cs
Created September 28, 2016 13:34
Unity editor script for running test every time code changes
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class StatsTest : MonoBehaviour {
[UnityEditor.Callbacks.DidReloadScripts]
private static void OnScriptsReloaded() {
Statistics stats = new Statistics();
stats.Run();
stats.Log();
@prehnRA
prehnRA / SkyboxCamera.cs
Created October 19, 2016 23:23
A script to capture a scene to a cubemap asset for use as a sky box
using UnityEngine;
using UnityEditor;
public class SkyboxCamera : MonoBehaviour {
const int TEXTURE_SIZE = 1024;
void Update() {
if(Input.anyKey) {
Capture();
}