Skip to content

Instantly share code, notes, and snippets.

View danmayer's full-sized avatar

Dan Mayer danmayer

View GitHub Profile
@danmayer
danmayer / wumpus.java
Created March 11, 2012 01:38
Wumpus world, old java code I found on one of my blogs
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class Room {
@danmayer
danmayer / I18n_bad_test.rb
Created January 6, 2012 02:30
A example of a bad I18n rails test... Found some tests failing in a project because tests in different files would change I18n.locale, changes like this make your tests fail if not run in your standard order.
require File.dirname(__FILE__) + '/../test_helper'
class FakeTest < ActiveSupport::TestCase
test "first de" do
puts "about to be de: #{I18n.locale}"
assert_equal 'en', "#{I18n.locale}"
I18n.locale = 'de'
assert true
end
Dir.glob("./mayerdan.com/**/*.php") do |local_filename|
unless local_filename.to_s.match(/ayerdan\.com\/pics/) ||
local_filename.to_s.match(/wastedbrains\.com\/art\/index\.php/) ||
local_filename.to_s.match(/simplepie\/demo/) ||
local_filename.to_s.match(/proj\/picts\/slideshow\.php/) ||
local_filename.to_s.match(/prog\/bencode\/slideshow\.php/) ||
local_filename.to_s.match(/proj\/phpquiz/) ||
local_filename.to_s.match(/picts\/linpha-1\.0beta3\/adodb/)
doc = File.read(local_filename)
@danmayer
danmayer / gist:1491781
Created December 17, 2011 23:29
Remove bad files
rm -f mayerdan.com/.htaccess
rm -f mayerdan.com/MT/.htaccess
rm -f melonandorange.com/.htaccess
rm -f melonandorange.com/dom/.htaccess
rm -f melonandorange.com/nicole/.htaccess
rm -f MYMOVETOLA.COM/.htaccess
rm -f scoreher.com/.htaccess
rm -f wastedbrains.com/.htaccess
rm -f .htaccess
rm -rf backup/mayerdan.com/tmp_1637643485416709.php
@danmayer
danmayer / init_gemset.rb
Created October 2, 2011 17:44
This helps setup and trust a new gemset in a project
#!/usr/bin/env ruby
# example usage: init_gemset mygemset
# to use this setup an alias in your .bash_profile
#
# #setup new gemset
# function initgemset()
# {
# local myresult=`ruby /Users/danmayer/projects/script_helpers/init_gemset.rb $#1`
# eval "$myresult"
@danmayer
danmayer / AR_bug.rb
Created September 29, 2011 15:26
ActiveRecord Association objects make no sense (bug in any?)
# this is rails 2.3.x so perhaps it has been fixed but any on a empty AR association object that has [] returns true.
# after being inspected or to_s it returns false (as it should
# rails console
[].any? => false
none = ar_object.association_objects (like Person.find(2).posts where there are no posts) => []
none.any? => false
none.ancestors.map(&:to_s).sort == (from Rails.development.log none.ancestors.map(&:to_s).sort ) => true
(just to make sure all the same things are loaded -> "ActiveRecord::AssociationPreload", "ActiveRecord::Associations", "ActiveRecord::AttributeMethods"... and many more)
@danmayer
danmayer / ruby_closure_compiler_helper.rb
Created July 4, 2011 16:33
Compress a collection of js files with closure compiler
require 'net/http'
require 'uri'
COMPRESS_LEVEL = "SIMPLE_OPTIMIZATIONS"
FILE_PATH = "assets/www/"
FILES = ['application','custom','plugin','base']
def compress(compilation_level,jscode)
response = Net::HTTP.post_form(URI.parse('http://closure-compiler.appspot.com/compile'), {
'js_code' => jscode,
@danmayer
danmayer / redis_connect_example
Created June 12, 2011 00:41
connect resque web to different redis server
#connect resque web to different redis server
`resque-web ./resque-conn.rb`
#cat ./resque-conn.rb =>
Resque.redis = Redis.new(:host => “127.0.0.1”, :port => 6379, :db => 1)
@danmayer
danmayer / swap_buffer_window.el
Created June 5, 2011 16:41
This function makes emacs move the current buffer to another window. It also closes the current tab and sets focus on the new buffer
;; move buffer to other window
;; after c-x 3 to split screen this lets you move buffers between sides.
;; altered code from:
;; http://stackoverflow.com/questions/1774832/how-to-swap-the-buffers-in-2-windows-emacs
(defun swap-buffer-window ()
"Put the buffer from the selected window in next window, and vice versa"
(interactive)
(let* ((this (selected-window))
(other (next-window))
(this-buffer (window-buffer this)))
@danmayer
danmayer / gist:941718
Created April 26, 2011 03:02
mocha_should_default_prevent_stubbing_non_existent_method
#I think mocha should default to preventing non existent methods, but make it easy to sidestep when you half to
#I find that putting this in your test_helper.rb can help to keep your tests more maintainable in the long run
Mocha::Configuration.prevent(:stubbing_non_existent_method)
def allow_non_existent_stubbing
Mocha::Configuration.allow(:stubbing_non_existent_method)
yield
Mocha::Configuration.prevent(:stubbing_non_existent_method)
end