Skip to content

Instantly share code, notes, and snippets.

View dhoelzgen's full-sized avatar

Daniel Hoelzgen dhoelzgen

View GitHub Profile
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 / 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']
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 =
def reset
@bracket_level = 0
require 'formula'
# Gets the latest Gnu Screen with 256 support
# Method from:
# and
class Screen <Formula
head 'git://'
homepage ''
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
if enemy = @enemies[name]
enemy.position = position