Skip to content

Instantly share code, notes, and snippets.

View deanrad's full-sized avatar
🎯
Staying On Target

Dean Radcliffe deanrad

🎯
Staying On Target
View GitHub Profile
# Alternative to add_column that will do nothing if a column by that name exists already
# Ensures a column of the name will exist - either creating it or leaving the existing one be
# Looks up the table_name in AR::Base's descendants to query them whether this column exists (by name) yet
# Currently does not ensure that the options for the column are the same, nor ensure all models are loaded
def self.ensure_column tn, cn, *opts
klass = begin
@@tables_to_classes ||=
ActiveRecord::Base.class_eval{ subclasses }.inject({}) do |map, this_class|
map[this_class.table_name] = this_class
map
# MY FIRST (NON-WORKING) ATTEMPT - borrowing from rails/lib/console_sanbox..
# I think it works only for console where a single connection can be counted on
# Allow for server to run in a mode where xactions are rolled back on exit,
# like script/console's --sandbox option. eg: > SANDBOX=1 script/server -p 3001
if ENV['SANDBOX']=="1"
$stderr.puts "NOTE: YOU ARE RUNNING IN SANDBOX MODE, ALL XACTIONS WILL ABORT ON EXIT"
conf = YAML::load( File.open(RAILS_ROOT + '/config/database.yml'))[RAILS_ENV]
$stderr.puts conf.inspect
ActiveRecord::Base.establish_connection(conf)
memoizer = {};
function memosin(arg){
if( memoizer[arg] ){
return memoizer[arg]
}
else{
memoizer[arg] = mysin(arg)
return memoizer[arg]
}
@deanrad
deanrad / gist:1020227
Created June 11, 2011 03:42
On my Mac, lein is broken fresh off a bootstrapper install
hihat:clojure_1 $> lein repl
Exception in thread "main" java.lang.ClassNotFoundException: clojure.main
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at sun.misc.Launcher$ExtClassLoader.findClass(Launcher.java:229)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
find . -mtime 1 # sort by modified time
@deanrad
deanrad / ChessJS
Created September 6, 2013 02:41
BDD version of an incremental version of player-to-player chess
<!DOCTYPE html>
</html>
<head>
<title>Jasmine Test Suite for Player-to-Player Chess</title>
</head>
<body>
<script type="text/javascript" src="//searls.github.io/jasmine-all/jasmine-all-min.js"></script>
<!-- script type="text/javascript" src="/js/jasmine-all-min.js"></script -->
<script type="text/javascript">
describe("Positions Vectors and Sides, oh my", function(){
@deanrad
deanrad / Creative Problem Solving Tips.md
Last active December 26, 2015 20:49
My versions of Eno Cards for Programmers
  • Involve a different sense - draw it, or hand-wave it
  • Ask your question of a duck
  • Type your question out in a forum or chatroom
  • Validate your assumptions - what have you mis-taken for granted ?
  • Break it to learn: "If I break it this way, I expect it to do X"
  • Step away from it, activate your other senses
  • Resort to a cheat, clearly labeling it as HACK, and return right after the next problem
  • Look at the order in which you do things

Node 2 hour course

Agenda

  • 0:00 - 0:05 Course Outline
  • 0:05 - 0:30 Discussion - What Is Node, Really ?
  • 0:30 - 0:55 Micro-challenges and review
  • 0:55 - 1:00 Break
  • 1:00 - 1:50 Labs - Learnyounode
  • 1:50 - 2:00 Review
@deanrad
deanrad / gist:7522293
Created November 18, 2013 04:03
Git Resources
http://prezi.com/tnrx86yhlzll/git-happens-2-kcdc/
@deanrad
deanrad / Kangax JS Quiz #7.js
Created January 25, 2014 19:08
JS.Chi Explanation of Kangax Javascript Quiz problem #7 about the binding rules for 'this'
// JS.Chi Explanation of Kangax Javascript Quiz problem #7 about the binding rules for 'this'
// Dean Radcliffe, Deanius Solutions, Inc.
// www.deanius.com
// Presenter Setup: Split-screen browser/sublime, using JsRun to execute in chunks
console.clear();
/************** SEEING IT *****************/