This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.places.find( { loc : { $near : [50,50] } } ).limit(20) | |
db.places.find( { loc : { $near : [50,50] , $maxDistance : 5 } } ).limit(20) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# define class | |
class Location | |
include Mongoid::Document | |
# fields | |
field :location, :type => Array | |
index [[ :location, Mongo::GEO2D ]], :min => -180, :max => 180 | |
field :name | |
# validations |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- doing map inside of monad on [String :: IO ] with putStrLn is not ok :< | |
map putStrLn list_of_io_strings |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()}. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |