Skip to content

Instantly share code, notes, and snippets.

@dhoelzgen
dhoelzgen / base_controller.rb
Last active October 7, 2021 16:19
CORS in Rails 4 APIs
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 November 15, 2013 13:03
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.
# 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 August 7, 2012 08:55
Better Formatting for DLV / DLV Complex Answer Sets
#!/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
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 07:27
SaboteurAgent in experimental DSL
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