Skip to content

Instantly share code, notes, and snippets.

View base_controller.rb
class API::V1::BaseController < ApplicationController
skip_before_filter :verify_authenticity_token
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS'
@dhoelzgen
dhoelzgen / intercom.rb
Created Nov 15, 2013
Just add the following to your Intercom initializer which was generated by the intercom-rails gem. It disabled the messages module completely, so you can implement your own version using the API directly.
View intercom.rb
# Add a disabled modules configuration to the script tag configuration
module IntercomRails
class ScriptTag
alias_method :original_intercom_settings, :intercom_settings
def intercom_settings
hsh = original_intercom_settings
hsh[:disable_modules] = ['messages']
hsh
end
@dhoelzgen
dhoelzgen / dlv_formatter.rb
Created Aug 7, 2012
Better Formatting for DLV / DLV Complex Answer Sets
View dlv_formatter.rb
#!/usr/bin/env ruby
output = %x(/usr/local/bin/dlv-complex -silent #{ARGV[0]})
output = output.scan(/[[:print:]]/).join
@answerset = Hash.new
def reset
@bracket_level = 0
View screen.rb
require 'formula'
# Gets the latest Gnu Screen with 256 support
# Method from:
# http://ryanwilliams.org/2010/Oct/09/gnu-screen-256-colours-mac-os-x and
# http://pjkh.com/articles/2008/07/09/osx-iterm-screen-vim-256-colors
class Screen <Formula
head 'git://git.savannah.gnu.org/screen.git'
homepage 'http://www.gnu.org/software/screen/'
@dhoelzgen
dhoelzgen / gist:966044
Created May 11, 2011
SaboteurAgent in experimental DSL
View gist:966044
require 'simple_agent'
class SaboteurAgent < SimpleAgent
on_percept :visibleEntity do |name, position, team, status|
next if team == @team
broadcast
if enemy = @enemies[name]
enemy.position = position