Skip to content

Instantly share code, notes, and snippets.

%couchdb connection information
-record(couch_config,{host="0.0.0.0",port=5984,db="mydatabase"}).
update_couchdb_property(OrigProps, {Key, _Value} = ChngProp) when is_list(OrigProps), is_tuple(ChngProp) ->
case lists:keymember(Key, 1, OrigProps) of
true ->
NewProps = lists:keyreplace(Key, 1, OrigProps, ChngProp);
false -> %append
NewProps = lists:append(OrigProps,[ChngProp])
end,
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char** argv) {
char protein[4] = "ACGT";
int size = atoi(argv[1]);
int i = 0;
int pos = 0;
for(i; i < size; ++i) {
#!/bin/sh -ex
# CouchDBX-Core-Builder
# Downloads, Install Erlang & CouchDB into a package
# Copyright 2009 Jan Lehnardt <jan@apache.org>
# Apache 2.0 Licensed
# customise here:
# use full svn path for branches like "branches/0.9.x"
@bradfordw
bradfordw / rlsp.rb
Created November 9, 2009 14:07 — forked from h0rs3r4dish/rlsp.rb
#!/usr/bin/ruby
RLSP_VERSION = "1.4.1"
class Lambda
attr_accessor :args, :body
def initialize(args=[],body="")
@args = (args.class == Array) ? args : [args]
@body = body
end
def authorized?
model = Kernel.const_get(params[:controller].classify)
model.first(:conditions => {:_id => current_user._id}).is_a?(model)
end
Loading production environment (Rails 2.3.4)
>> u = User.new
=> #<User contribution_count: nil, crypted_password: nil, reset_password_code_until: nil, _id: nil, username: nil, reset_password_code: nil, email: nil>
>> u.valid?
NameError: uninitialized constant MongoMapper::EmbeddedDocument::ClassMethods::ObjectId
from /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/mongo_mapper-0.6.1/lib/mongo_mapper/embedded_document.rb:66:in `object_id_key?'
from /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/mongo_mapper-0.6.1/lib/mongo_mapper/finder_options.rb:63:in `to_mongo_criteria'
from /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/mongo_mapper-0.6.1/lib/mongo_mapper/finder_options.rb:60:in `each_pair'
from /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/mongo_mapper-0.6.1/lib/mongo_mapper/finder_options.rb:60:in `to_mongo_criteria'
from /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/mongo_mapper-0.6.1/lib/mongo_mapper/finder_options.rb:38:in `criteria'
-module(histo).
-compile(export_all).
-define(WORDS,[ "a", "at", "red", "green", "dog"]).
parse_input(Input) ->
lists:foldl(fun(Letter, D) -> dict:update(Letter, fun(N) -> N + 1 end, 1, D)
end, dict:new(),
[L || L <- Input]).
start_find(InputHisto) ->
# mongo_template.rb
# fork of Ben Scofield's Rails MongoMapper Template (http://gist.github.com/181842)
#
# To use:
# rails project_name -m http://gist.github.com/gists/219223.txt
# remove unneeded defaults
run "rm public/index.html"
run "rm public/images/rails.png"
run "rm public/javascripts/controls.js"
Getting a non replicated mongo instance's operation log for indexing:
db.oplog.$main.find({ ts: { t: {gte: last_processed_time } } }).sort({$natural:1});
-module(ann).
-define(SIG,fun(X) -> 1 / (1 + math:exp(-X)) end).
-define(SIG_DERIV,fun(X) -> math:exp(-X) / (1 + math:exp(-2 * X)) end).
-compile(export_all).
dp(X,Y) ->
lists:foldl(fun(E,Sum) -> E + Sum end, 0,
vector_map(fun(EX,EY) -> EX * EY end, X, Y)).