Skip to content

Instantly share code, notes, and snippets.

@kikito
kikito / books.xml
Created February 21, 2012 14:02
A sample xml document
<books>
<book>
<title>Tom Sawyer</title>
</book>
<book>
<title>The origin of the species</title>
</book>
<book>
<title>Life and death of Albert Camus</title>
</book>
@kikito
kikito / _photo.html.haml
Created April 10, 2012 13:43 — forked from assimovt/_photo.html.haml
Carrierwave uploader sample
# app/views/photos/_photo.html.haml
.photo[photo]
= image_tag photo.image_url(:thumb) if photo.image?
= link_to "Delete", property_photo_path(@property, photo), :method => :delete, :confirm => "Are you sure?", :remote => :true
@kikito
kikito / _intro.txt
Created May 8, 2012 08:52
mass_assignment management in cancan
This is an example of how I'd like to prevent mass_assignment using cancan.
On this example, the application has 4 roles: admin, owner, employee and contractor.
Each user has 4 fields: login, password, role and company_id.
Admin is the only role capable of creating owners and admins.
Owner can create users, but only of type employee and contractor, and only for their own company. They can not see or otherwise interact in any with users from other companies or admins.
@kikito
kikito / modal.html
Created October 11, 2012 16:44
Twitter bootstrap remote modal form helper
<div class="modal hide fade">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h3>I want to change the header!</h3>
</div>
<div class="modal-body">
<p>And also the body!</p>
</div>
<div class="modal-footer">
<p>And the footer too!</p>
@kikito
kikito / Results
Created November 9, 2012 17:55
Callbacks vs Coroutines vs Next when parsing 2-d tables in Lua
$ time lua callbacks.lua
lua callbacks.lua 0.52s user 0.00s system 97% cpu 0.534 total
$ time lua coroutines.lua
lua coroutines.lua 1.12s user 0.00s system 99% cpu 1.123 total
$ time lua next.lua
lua next.lua 1.35s user 0.00s system 99% cpu 1.358 total
@kikito
kikito / array.lua
Created November 16, 2012 15:42
Performance testing: Returning the results of an operation in Lua: array vs callback
local floor = math.floor
local function abs(x)
return x < 0 and -x or x
end
local function toGrid(cellSize, x,y)
return floor(x / cellSize) + 1, floor(y / cellSize) + 1
end
@kikito
kikito / context.rb
Created November 28, 2012 00:23
mustache
{ :title => "Frodo's Todos",
:items => [
{:name => "Walk into Mordor", :first => true},
{:name => "Throw Ring"}
]
}
@kikito
kikito / v0.5.rb
Created November 28, 2012 00:52
Tash
Template: "I can’t do this, {{name}}"
Context: {:name => 'Sam'}
@kikito
kikito / simpleFormat.js
Last active December 16, 2015 03:39 — forked from kares/simpleFormat.js
function simpleFormat(str) {
return '<p>' +
str.replace(/\r\n?/, "\n")
.replace(/\n\n+/g, '</p>\n\n<p>')
.replace(/([^\n]\n)(?=[^\n])/g, '$1<br/>') +
'</p>';
}
@kikito
kikito / levels-of-collision-detection.md
Created April 15, 2013 20:49
The levels of collision detection
  1. Detect when two AABBs are intersecting in a given moment (true/false)
  2. Instead of true/false, when they intersect, obtain the minimum displacement vector that would make the first one stop intersecting.
  3. Do the same when one of the elements is a circle.
  4. Same as before, but the boxes are not axis-aligned any more; they are Oriented Bounding Boxes (OBB)
  5. Do the same if one of the boxes is a polygon
  6. Now the two shapes can be moving. Given their initial positions, velocities and a time interval, calculate if they collide, and if so, the displacement vector that would move each one "backwards on their trajectory" to the point where they touch but don't intersect any more.
  7. Take into account all the special cases: Two objects might already be intersecting. They could also not be intersecting now, but have intersected along their trajectory.
  8. Divide the space in subregions so you can test pairs more efficiently. Take into account moving that ob