Skip to content

Instantly share code, notes, and snippets.

db.places.find( { loc : { $near : [50,50] } } ).limit(20)
db.places.find( { loc : { $near : [50,50] , $maxDistance : 5 } } ).limit(20)
# define class
class Location
include Mongoid::Document
# fields
field :location, :type => Array
index [[ :location, Mongo::GEO2D ]], :min => -180, :max => 180
field :name
# validations
-- doing map inside of monad on [String :: IO ] with putStrLn is not ok :<
map putStrLn list_of_io_strings
@JakubOboza
JakubOboza / mrisc.rb
Created July 8, 2011 10:22 — forked from pachacamac/mrisc.rb
A Simple Assembler Language and VM
#!/usr/bin/env ruby
class MRISC
def run(code)
tokens = code.gsub(/(\*.*?\*)|[^a-z0-9,-;@\._]/,'').split(';')
@vars,stack,i = {:_pc=>-1,:_oc=>0},[],0
tokens.map!{|t| t.chars.first=='@' ? (@vars[t.to_sym]=i-1;nil) : (i+=1;t.split(',').map{|e|numeric?(e) ? e.to_i : e.to_sym})}.compact!
while @vars[:_pc] < tokens.size-1
@vars[:_pc] += 1
@vars[:_oc] += 1
var http = require('http');
var util = require('util');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
var msg = util.inspect(req);
res.end( msg );
console.log( msg );
}).listen(8000, "127.0.0.1");
var http = require('http'),
util = require('util'),
url = require('url');
function Counter(options) {
if (! (this instanceof arguments.callee)) {
return new arguments.callee(arguments);
}
this.settings = {
@JakubOboza
JakubOboza / gist:1106325
Created July 26, 2011 09:00
Ruby Style Guide
Original Source: https://github.com/chneukirchen/styleguide
= Christian Neukirchen's Ruby Style Guide
You may not like all rules presented here, but they work very well for
me and have helped producing high quality code. Everyone is free to
code however they want, write and follow their own style guides, but
when you contribute to my code, please follow these rules:
mapF(Pattern, Root) ->
ergrep ! {spawn, self()},
Items = filelib:wildcard(Root),
lists:map(fun(I) -> process_item(filelib:is_dir(I), I, Pattern) end, Items),
ergrep ! {die, self()}.
reduceF(ProcCount, Results) ->
receive
{emit, Ref, Value } -> reduceF(ProcCount, [Value | Results]);
{spawn, Ref } -> reduceF(ProcCount + 1, Results);
{die, Ref } -> Count = ProcCount - 1,
if
Count =:= 0 -> Results;
true -> reduceF(Count, Results)
end
after
@JakubOboza
JakubOboza / app.rb
Created August 4, 2011 22:39
backend
require 'sinatra'
set :public, File.dirname(__FILE__) + '/public'
get '/' do
%q{
<head>
<link rel=stylesheet href="/main.css" type="text/css" media=screen>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript"