Skip to content

Instantly share code, notes, and snippets.

Dean Radcliffe deanius

View GitHub Profile
View ensure_column
# 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
View server.rb
# 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)
View gist:790002
memoizer = {};
function memosin(arg){
if( memoizer[arg] ){
return memoizer[arg]
}
else{
memoizer[arg] = mysin(arg)
return memoizer[arg]
}
@deanius
deanius / gist:1020227
Created Jun 11, 2011
On my Mac, lein is broken fresh off a bootstrapper install
View gist:1020227
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)
View gist:3166514
find . -mtime 1 # sort by modified time
@deanius
deanius / ChessJS
Created Sep 6, 2013
BDD version of an incremental version of player-to-player chess
View ChessJS
<!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(){
@deanius
deanius / Creative Problem Solving Tips.md
Last active Dec 26, 2015
My versions of Eno Cards for Programmers
View Creative Problem Solving Tips.md
  • 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
View Node-Intro1.md

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
View gist:7522293
http://prezi.com/tnrx86yhlzll/git-happens-2-kcdc/
@deanius
deanius / Kangax JS Quiz #7.js
Created Jan 25, 2014
JS.Chi Explanation of Kangax Javascript Quiz problem #7 about the binding rules for 'this'
View Kangax JS Quiz #7.js
// 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 *****************/
You can’t perform that action at this time.