Skip to content

Instantly share code, notes, and snippets.

@eriksk
eriksk / mapio.cs
Created May 18, 2012 17:05
Oh IO I really love/hate you
List<MapLayer> layers = new List<MapLayer>();
MapSettings settings = new MapSettings();
List<Ledge> ledges = new List<Ledge>();
int[,] grid;
using (StreamReader r = new StreamReader(path))
{
settings.gravity = float.Parse(r.ReadLine(), CultureInfo.InvariantCulture);
settings.friction = float.Parse(r.ReadLine(), CultureInfo.InvariantCulture);
settings.mood = int.Parse(r.ReadLine());
@eriksk
eriksk / replace.js
Created July 5, 2012 10:40
Replace all occurences in js
"This ain't a scene it's a god damn arms race".replace(/god/g, "God");
@eriksk
eriksk / rails_custom_config.rb
Created July 6, 2012 09:19
Config files with YAML in rails.
# config file whatever.yml
development:
my_var: hello
test:
my_var: hello
production:
my_var: hello
@eriksk
eriksk / hash_from_xml.rb
Created July 11, 2012 08:11
Using Hash.from_xml outside of rails
# is pretty simple, just require active support
require 'active_support/core_ext/hash'
hash = Hash.from_xml(xml)
@eriksk
eriksk / gist:3096376
Created July 12, 2012 07:00
Simple script for running gem commands in ruby
#!/usr/bin/env ruby
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
require 'my_gem'
require 'my_gem/command'
args = ARGV.dup
ARGV.clear
@eriksk
eriksk / gist:3111721
Created July 14, 2012 14:54
CLI coloring
# super simple way of coloring console output with ruby
# we extend string so we can simply call the method of the color on string literals, like so:
"This text should be blue!".blue
# and it will output a blue text string!
class String
# colorization
@eriksk
eriksk / gist:3121568
Created July 16, 2012 08:38
Events in Ruby
# an array of lambdas
listeners = []
# just some function that prints text
def callback_puts text
puts text
end
# add some listeners
listeners.push lambda{ callback_puts("Hello") }
@eriksk
eriksk / gist:3199757
Created July 29, 2012 15:56
C# Resource pooling
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OGLib.Utilities
{
public class Pool<T> where T : class, new()
{
private T[] items;
@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
@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;