Skip to content

Instantly share code, notes, and snippets.

public const float PiOverTwo = (float)Math.PI * 2f;
public static float SLerp(float x, float y, float amount)
{
float diff = (float)Math.Abs(y - x);
if (diff > Math.PI)
{
if (y > x)
x += PiOverTwo;
@eriksk
eriksk / StringScrambler
Created November 21, 2014 09:52
String scrambler
class StringScrambler
{
private readonly char[] _scrambleLetters;
private Random rand = new Random();
public StringScrambler(char[] scrambleLetters)
{
if (scrambleLetters == null) throw new ArgumentNullException("scrambleLetters");
_scrambleLetters = scrambleLetters;
@eriksk
eriksk / gist:9f6ac9f9d54810ce4758
Created August 7, 2014 05:56
Generic GameObject for MonoGame
public class GameObject
{
private Vector2 originInPixels;
public Vector2 position, scale, origin;
public Color color;
public Texture2D texture;
public Rectangle source;
public SpriteEffects flip;
public float rotation;
@eriksk
eriksk / gist:26afde7a810f9fa8db7d
Created August 1, 2014 06:26
Java JRuby Scripting
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("jruby");
if(engine == null){
System.out.println("failed to load jruby");
return;
}
ScriptContext context = engine.getContext();
@eriksk
eriksk / gist:5633399
Last active December 17, 2015 15:39
OpenGL render a spinning colored cube in Ruby
require 'opengl'
include Gl, Glu, Glut
WIDTH = 512
HEIGHT = 512
NEAR = 0.1
FAR = 1000
class Vec3
attr_accessor :x, :y, :z
@eriksk
eriksk / gist:5204017
Created March 20, 2013 11:38
Drop all tables in MS SQL database
EXEC sp_MSforeachtable @command1 = "DROP TABLE ?"
@eriksk
eriksk / gist:4195380
Created December 3, 2012 14:35
Fixes all bugs
git rm -r *
git commit -m "fixed all bugs"
@eriksk
eriksk / gist:3914779
Created October 18, 2012 21:14
Compile and run sfml project on mac with g++
g++ -F /Library/Frameworks -c main.cpp | g++ main.o -o main -framework sfml-window -framework sfml-graphics -framework sfml-system | exec ./main
@eriksk
eriksk / gist:3566320
Created September 1, 2012 07:16
Kill script for unity, will destroy an object after a specified amount of time. Really handy for particles and stuff
using UnityEngine;
using System.Collections;
public class KillAfterTime : MonoBehaviour {
public float time = 0f;
float current = 0f;
void Update () {
current += Time.deltaTime;
@eriksk
eriksk / gist:3308086
Created August 9, 2012 21:07
require all ruby files in a directory
rb_files = File.join('my_directory', '*.rb')
Dir.glob(rb_files).each do |file|
require_relative file
end