require 'sketchup'
entities = Sketchup.active_model.entities
summa = Hash.new
for face in entities
next unless face.kind_of? Sketchup::Face
if (face.material)
summa[face.material.display_name] += face.area
end
end
Im trying to get the structure in the array as such:
summa { "Bric...
Hi,
Im learning rails and exploring a bit away from the book and creating a simple application with added functionality as i increase my knowledge. Im writing a simple blog application and i have a field in the form called date added, i don't want this to be a field i want it to get the date from the server and place it in to the datab...
Guys,
I have been looking for a portable method to digitally sign arbitrary text which can be placed in a document and distributed while maintaining its verifiable origin. Here is an example:
a = 'some text'
a.sign(<private key>) # => <some signature in ASCII format>
The contents of a can now be distributed freely. If a receiver want...
What open source (preferably gem-based) parser-generator options do I have in Ruby?
I've used (flex&bison)|(lex&yacc) from C in the past, and I'm comfortable with BNF-style specifications.
I've heard of treetop, but it looks a bit alien and verbose compared to yacc...
Purpose: I want to convert my text markup language to a BNF and ge...
I have a file with data like this:
01 JUL something
something
something 445
something else
01 JUL whatever
everwa3
lklkj 445
something else
02 JUL ljkjlkj
ljkljlkj
lkjkjlk 500
lkjkj
02 JUL ljlkjklj
lkjkjlkj
lkjkj ...
While reading a file I get broken UTF-8 String error whenever I have the following in my file
través
if I change it to normal e then it works.
Whats the way to fix this?
error only happens if I do line.lstrp or any other function. Just printing the lines is ok.
problem even happens when I try to match the string with regex.
...
I'm currently doing the following but it feels "kludgy":
module Sinatra
module DynFormat
def dform(data,ct)
if ct == 'xml';return data.to_xml;end
if ct == 'json';return data.to_json;end
end
end
helpers DynFormat
end
My goal is to plan ahead. Right now we're only working with XML for ...
Hi,
I have to run rails on a shared host for a client via cPanel.
The application is running on a subdomain and non standard port.
I am using Authlogic, so on the first visit it detects I am not logged in and I get a page with:
You are being redirected.
Clicking on that I get the login form, which then takes me to the target page, ...
I'm new to ruby so forgive me if this is simple or I get some terminology wrong.
I've got a bunch of unit tests (actually they're integration tests for another project, but they use ruby test/unit) and they all include from a module that sets up an instance variable for the log object. When I run the individual tests I'd like log.level...
Hi all, I'm writing a Ruby library which has a module with a bunch of classes inside it. Many of these classes need to be usable and modifiable by calling scripts, but I don't want (some of) the initializers to be visible/callable:
module MyLib
class Control
def initialize
# They can use this
end
def do_stuff
...
I'm at Rails 2.3.5 and I have this problem:
class BaseController < ApplicationController
before_filter :foo, :only => [:index]
end
class ChildController < BaseController
before_filter :foo, :only => [:index, :show, :other, :actions]
end
The problem is that on ChildController, the :foo before filter gets called twice.
I've tried ...
I just got started with rails, and when I testing in development mode, I see in the logs that my Mailer action is taking 1175ms. Is there anyway to find out what exactly is the slow step?
Also, there is a line that says (View:2, DB:1). I assume the DB means number of database lookups, but what about the view?
...
Hello,
i've the following code and tried the whole day to refactor the class methods to a sperate module to share the functionality with all of my model classes.
Code (http://pastie.org/974847):
class Merchant
include DataMapper::Resource
property :id, Serial
[...]
class << self
...
I'm getting this exception when doing a nested model form:
ActiveRecord::AssociationTypeMismatch in RecipesController#update
Ingredient(#35624480) expected, got Ingredient(#34767560)
The models involved are Recipe and Ingredient. Recipe has_many and accepts_nested_attributes_for :ingredients, which belongs_to :recipe.
I get this e...
The latest changesets to Ruby 1.9.2 no longer make the current directory . part of your LOAD_PATH. I have a non-trivial number of Rakefiles that assume that . is part of the LOAD_PATH, so this broke them. Was there a particular justification for doing this?
As for a fix, adding $: << "." everywhere works, but seems incredibly hacky and ...
I am creating an application that highlights user messages from a stream based on whether or not the user has been 'vouched'. It works fine if it's setup for a single author. For example
controller: @vouch = Vouch.last.vouched_user_nickname
view:
<% Twitter::Search.new(params[:id]).each do |tweet| %>
<li>
<%= image_tag tweet....
I have a TCPclient written on Ruby. I want to use it in background. Currently it has a loop:
loop do
end
So i can run a client, and it works forever.
Is there a way to run in as a service, and write a pid to file, then i'll able to kill that process by pid?
...
Edit: I figured out the answer. The problem was namespaces. The following code got it to work: @doc.xpath("xmlns:msms_pipeline_analysis/@date").to_s. I'd put this down as the answer, but this question has been closed.
I'm using Nokogiri to parse pepXML files from different peptide search engines. I have two pepXML files, both of which a...
This snippet of code populates an @options hash. values is an Array which contains zero or more heterogeneous items. If you invoke populate with arguments that are Hash entries, it uses the value you specify for each entry to assume a default value.
def populate(*args)
args.each do |a|
values = nil
if (a.kind_of? Hash)
#...
Hello. I am trying to create a tree structure with graphviz. I am open to either writing the graphviz code by hand or using the ruby-graphviz gem for ruby. Given the below picture can anyone provide any insight on the necessary code? Ignore that the lines are not straight...they should be when graphviz builds the graph. I am open to havi...