Skip to content

Instantly share code, notes, and snippets.

@mooreniemi
mooreniemi / 600x PS7-4
Created November 26, 2012 15:37
runSimulation
# Enter your code for runSimulation in this box.
def runSimulation(num_robots, speed, width, height, min_coverage, num_trials,
robot_type):
"""
Runs NUM_TRIALS trials of the simulation and returns the mean number of
time-steps needed to clean the fraction MIN_COVERAGE of the room.
The simulation is run with NUM_ROBOTS robots of type ROBOT_TYPE, each with
speed SPEED, in a room of dimensions WIDTH x HEIGHT.
def insert(atMe, newFrob):
"""
atMe: a Frob that is part of a doubly linked list
newFrob: a Frob with no link
This procedure appropriately inserts newFrob into the linked list that atMe is a part of.
"""
# Your Code Here
if newFrob.myName() < atMe.myName():
if atMe.getBefore() == None:
atMe.setBefore(newFrob)
# comments.js.coffee
jQuery ->
# Create a comment
$(".comment-form")
.on "ajax:beforeSend", (evt, xhr, settings) ->
$(this).find('textarea')
.addClass('uneditable-input')
.attr('disabled', 'disabled');
.on "ajax:success", (evt, data, status, xhr) ->
$(this).find('textarea')
<div class="comment" id=<%=comment.id %>>
<div class="well"><%= comment.body %><br>
<%= comment.user.username %>
<small><%= comment.updated_at.strftime('%b %d, %Y at %I:%M %p') %></small>
<%= link_to "×", comment_path(comment), :method => :delete, :remote => true, :confirm => "Are you sure you want to remove this comment?", :disable_with => "×", :class => 'close' %></div>
</div>
def good_fact(x)
def fact_tail(x,sum)
if x == 0
return sum
else
fact_tail(x-1,x*sum)
end
end
fact_tail(x,1)
end
@mooreniemi
mooreniemi / example update
Last active August 29, 2015 14:10
activerecord pattern example 1
def update
@model = Model.find(params[:id]) # ActiveRecord's find method being used here
@model.update_attributes(params) # ActiveRecord's update_attributes method being used here
if @model.save # ActiveRecord's save method being used here
respond_with(@model)
else
respond_with(@model.errors)
end
end
~/Documents/Code/haskell cabal install ghc-mod-5.2.1.1 -v3
Using a sandbox located at /Users/Alex/Documents/Code/haskell/.cabal-sandbox
Searching for ghc in path.
Found ghc at /usr/local/bin/ghc
("/usr/local/bin/ghc",["--numeric-version"])
/usr/local/bin/ghc is version 7.8.2
looking for tool ghc-pkg near compiler in /usr/local/bin
found ghc-pkg in /usr/local/bin/ghc-pkg
("/usr/local/bin/ghc-pkg",["--version"])
/usr/local/bin/ghc-pkg is version 7.8.2
@mooreniemi
mooreniemi / gist:2307d398131127b75840
Created April 16, 2015 16:01
from pda vs adt article
adt IntList
representation
list = NIL | CELL of integer * list
operations
nil = NIL
adjoin(x : integer, l : list) =
CELL(x, l)
null?(l : list) = case l of
NIL ⇒ true
CELL(x, l) ⇒ false
This file has been truncated, but you can view the full file.
2015-04-30 17:38:31
Full thread dump Java HotSpot(TM) Client VM (20.65-b04-466.1 mixed mode):
"http-/127.0.0.1:8080-89" daemon prio=5 tid=0000000043816c00 nid=0xc1b35000 waiting on condition [00000000c1b2e000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <000000000fd5f520> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:156)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:811)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireInterruptibly(AbstractQueuedSynchronizer.java:867)
Java::JavaLang::OutOfMemoryError (Java heap space):
java.lang.reflect.Array.newArray(Native Method)
java.lang.reflect.Array.newInstance(java/lang/reflect/Array.java:52)
oracle.jdbc.driver.BufferCache.get(oracle/jdbc/driver/BufferCache.java:226)
oracle.jdbc.driver.PhysicalConnection.getCharBuffer(oracle/jdbc/driver/PhysicalConnection.java:7672)
oracle.jdbc.driver.OracleStatement.prepareAccessors(oracle/jdbc/driver/OracleStatement.java:1005)
oracle.jdbc.driver.T4CTTIdcb.receiveCommon(oracle/jdbc/driver/T4CTTIdcb.java:277)
oracle.jdbc.driver.T4CTTIdcb.receive(oracle/jdbc/driver/T4CTTIdcb.java:146)
oracle.jdbc.driver.T4C8Oall.readDCB(oracle/jdbc/driver/T4C8Oall.java:844)
oracle.jdbc.driver.T4CTTIfun.receive(oracle/jdbc/driver/T4CTTIfun.java:358)