Skip to content

Instantly share code, notes, and snippets.

View BFalkner's full-sized avatar

Brennan Falkner BFalkner

View GitHub Profile
[Component]
public class CSVList : List<string>
{
// ReSharper disable UnusedPrivateMember
private string Value
// ReSharper restore UnusedPrivateMember
{
get { return string.Join(",", this.ToArray()); }
set
{
Server Error in '/' Application.
Value cannot be null.
Parameter name: row
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: row
Source Error:
var conf = new MapConfiguration();
conf.DefaultStore = new DatabaseStore(conf, Settings.Database);
conf.Initialize();
DataContext = new DataContext(conf);
Keywords = Request.Form["Keywords"]
.Replace("\r\n", ",")
.Split(',')
.Where(k => k.Length > 0)
.Select(k => k.Trim()).ToList()
def self.find_by_probability(user)
links = Link.find :all, :include => :votes
users = User.select { |u| u.votes.id }.to_a
links.map do |link|
link.probability = bayes(
link,
users_with_link(link, users),
proc{|e, h| common_links(e, user, h) / all_links(e, user, h) },
proc{|e| e.votes.size.to_f / links.size },

Notes

The original subs actually making a query with printing the query, so no real queries here either.

The 'transaction' from the original doesn't appear to do anything except close over the connection argument. I didn't implement any transactional functionality because the original didn't appear to have any.

It doesn't make sense to memoize the non-query stuff and always run the query which is going to be your slowest thing. It also doesn't make sense to memoize inserts which always need to run.

Output

class RenameThingsToRecords < ActiveRecord::Migration
def self.up
command = OrderedHash.new
command['renameCollection'] = "#{MongoMapper.database.name}.things"
command['to'] = "#{MongoMapper.database.name}.records"
MongoMapper.connection.db('admin').command(command)
end
def self.down
command = OrderedHash.new
>> hash = {:blah.lte => 5}
=> {#<MongoMapper::FinderOperator:0x105113338 @field=:blah, @operator="$lte">=>5}
>> hash[:blah.lte]
=> nil
>> :blah.lte == :blah.lte
=> false
class Test
include Enumerable
def initialize(arr)
@arr = arr
end
def each(&block)
@arr.each do |el|
puts "start #{el}"
def integer?
ActivePattern::Pattern.build do |value, pass|
if value.is_a? Integer
value
elsif value.is_a? String
/\A[-+]?\d+\z/ === value ? value.to_i : pass
else
pass
end
end