Search Results

Search found 118 results on 5 pages for 'petr macek'.

Page 3/5 | < Previous Page | 1 2 3 4 5  | Next Page >

  • Math: How to sum each row of a matrix

    - by macek
    I have a 1x8 matrix of students where each student is a 4x1 matrix of scores. Something like: SCORES S [62, 91, 74, 14] T [59, 7 , 59, 21] U [44, 9 , 69, 6 ] D [4 , 32, 28, 53] E [78, 99, 53, 83] N [48, 86, 89, 60] T [56, 71, 15, 80] S [47, 67, 79, 40] Main question: Using sigma notation, or some other mathematical function, how can I get a 1x8 matrix where each student's scores are summed? # expected result TOTAL OF SCORES S [241] T [146] U [128] D [117] E [313] N [283] T [222] S [233] Sub question. To get the average, I will multiply the matrix by 1/4. Would there be a quicker way to get the final result? AVERAGE SCORE S [60.25] T [36.50] U [32.00] D [29.25] E [78.25] N [70.75] T [55.50] S [58.25] Note: I'm not looking for programming-related algorithms here. I want to know if it is possible to represent this with pure mathematical functions alone.

    Read the article

  • Problem with url_for and named routes in ActionMailer View: "Need controller and action"

    - by macek
    I'm attempting to provide a confirmation link in my user welcome email and I'm getting the following Rails error: Need controller and action! It makes a fuss about this line: <p>Please take a moment to activate your account by going to: <%= link_to confirm_user_url(:id => @user.confirmation_code) %>.</p> In my development.rb environment, I have the following line: config.action_mailer.default_url_options = { :host => "localhost", :port => 3000 } There's no problem with the @user variable. I've tested the email with things like @user.username and @user.confirmation_code. I'm only getting trouble with url_for and named routes like confirm_user_url. When I check my routes with rake routes, confirm_user shows up, so it's not an issue with the named route not existing. I can't seem to figure it out. What gives?

    Read the article

  • Ruby File IO question; Maintain file read position between script executions

    - by macek
    I have two files a.txt and b.txt (henceforth a and b). My script iterates through a, does some operation, and potentially inserts a line to b. In the event the script stops, I need it to pick up where it left off. In the example below: foo was copied to b bar was copied to b zim was not copied to b (did not pass some criteria) gaz was copied to b Script stops (for whatever reason) When script starts again, how to open a and start on line "dib"? a.txt foo bar zim gaz // <= last successful copy dib // <= I want to start here on next script execution gir b.txt foo bar gaz // <= note omission of "zim" above gaz

    Read the article

  • has_many through a habtm relationship in Rails

    - by macek
    I'm trying to define a has_many X, :through => Y where Y is a habtm relationship. Rails is throwing a fit about this. See comment in user model: class User < ActiveRecord::Base has_many :posts # I want to display a list of all tags this user is involved in has_many :tags, :through => :posts # ERROR end class Post < ActiveRecord::Base has_and_belongs_to_many :tags end class Tag < ActiveRecord::Base has_and_belongs_to_many :posts end What can I do to fix this?

    Read the article

  • Docs for auto-generated methods in Ruby on Rails

    - by macek
    Rails has all sorts of auto-generated methods that I've often times struggled to find documentation for. For example, in routes.rb, if I have: map.resources :projects do |p| p.resources :tasks end This will get a plethora of auto-generate path and url helpers. Where can I find documentation for how to work with these paths? I generally understand how to work with them, but more explicit docs might help me understand some of the magic that happens behind the scenes. # compare project_path(@project) project_task_path(@project, @task) # to project_path(:id => @project.id) project_task_path(:project_id => @project.id, :id => @task.id) Also, when I change an attribute on a model, @post.foo_changed? will be true. Where can I find documentation for this and all other magical methods that are created like this? If the magic is there, I'd love to take advantage of it. And finally: Is there a complete resource for config.___ statements for environment.rb? I was able to find docs for Configuration#gem but what attributes can I set within the stubs like config.active_record.___, config.action_mailer.___, config.action_controller.___, etc. Again, I'm looking for a complete resource here, not just a settings for the examples I provided. Even if you can only answer one of these questions, please chime in. These things seem to have been hiding from me and it's my goal to get them some more exposure, so I'll be upvoting all links to docs that point me to what I'm looking for. Thanks! ps, If they're not called auto-generated methods, I apologize. Someone can teach me a lesson here, too :) Edit I'm not looking for tutorials here, folks. I have a fair amount of experience with rails; I'm just looking for complete docs. E.g., I understand how routing works, I just want docs where I can read about all of the usage options.

    Read the article

  • I want multipart/alternative; ActionMailer only sending text/html

    - by macek
    I'm following the Ruby on Rails Guide: ActionMailer Basics Section 2.7 Snippet: Action Mailer will automatically send multipart emails if you have different templates for the same action. So, for our UserMailer example, if you have welcome_email.text.plain.erb and welcome_email.text.html.erb in app/views/user_mailer, Action Mailer will automatically send a multipart email with the HTML and text versions setup as different parts. Well, I have both: app/views/user_mailer/welcome_mail.text.html.erb app/views/user_mailer/welcome_mail.text.plain.erb app/models/user_mailer.rb class UserMailer < ActionMailer::Base def welcome_mail(user) recipients user.email from "[email protected]" subject "Thanks for registering" body :user => user end end Any luck?

    Read the article

  • Adding RESTful route to Rails app

    - by macek
    I'm reading these two pages resources Adding more RESTful actions The Rails Guides page shows map.resources :photos, :new => { :upload => :post } And its corresponding URL /photos/upload This looks wonderful. My routes.rb shows this map.resources :users, :new => { :signup => :get, :register => :post } When I do: [~/my_app]$ rake routes I see the two new routes added signup_new_user GET /users/new/signup(.:format) register_new_user POST /users/new/register(.:format) Note the inclusion of /new! I don't want that. I just want /users/signup and /users/register (as described in the Rails Routing Guide). Any help?

    Read the article

  • How to make a jQuery plugin (the right way)?

    - by macek
    I know there are jQuery cookie plugins out there, but I wanted to write one for the sake of better learning the jQuery plugin pattern. I like the separation of "work" in small, manageable functions, but I feel like I'm passing name, value, and options arguments around too much. Is there a way this can be refactored? I'm looking for snippets of code to help illustrate examples provided with in answers. Any help is appreciated. Thanks :) example usage $.cookie('foo', 'bar', {expires:7}); $.cookie('foo'); //=> bar $.cookie('foo', null); $.cookie('foo'); //=> undefined Edit: I did a little bit of work on this. You can view the revision history to see where this has come from. It still feels like more refactoring can be done to optimize the flow a bit. Any ideas? the plugin (function($){ $.cookie = function(name, value, options) { if (typeof value == 'undefined') { return get(name); } else { options = $.extend({}, $.cookie.defaults, options || {}); return (value != null) ? set(name, value, options) : unset(name, options); } }; $.cookie.defaults = { expires: null, path: '/', domain: null, secure: false }; var set = function(name, value, options){ console.log(options); return document.cookie = options_string(name, value, options); }; var get = function(name){ var cookies = {}; $.map(document.cookie.split(';'), function(pair){ var c = $.trim(pair).split('='); cookies[c[0]] = c[1]; }); return decodeURIComponent(cookies[name]); }; var unset = function(name, options){ value = ''; options.expires = -1; set(name, value, options); }; var options_string = function(name, value, options){ var pairs = [param.name(name, value)]; $.each(options, function(k,v){ pairs.push(param[k](v)); }); return $.map(pairs, function(p){ return p === null ? null : p; }).join(';'); }; var param = { name: function(name, value){ return name + "=" + encodeURIComponent(value); }, expires: function(value){ // no expiry if(value === null){ return null; } // number of days else if(typeof value == "number"){ d = new Date(); d.setTime(d.getTime() + (value * 24 * 60 * 60 * 1000)); } // date object else if(typeof value == "object" && value instanceof "Date") { d = value; } return "expires=" + d.toUTCString(); }, path: function(value){ return "path="+value; }, domain: function(value){ return value === null ? null : "domain=" + value; }, secure: function(bool){ return bool ? "secure" : null; } }; })(jQuery);

    Read the article

  • Arbitrary precision arithmetic with Ruby

    - by macek
    How the heck does Ruby do this? Does Jörg or anyone else know what's happening behind the scenes? irb(main):001:0> 999**999 368063488259223267894700840060521865838338232037353204655959621437025609300472231530103873614505175218691345257589896391130393189447969771645832382192366076536631132001776175977932178658703660778465765811830827876982014124022948671975678131724958064427949902810498973271030787716781467419524180040734398996952930832508934116945966120176735120823151959779536852290090377452502236990839453416790640456116471139751546750048602189291028640970574762600185950226138244530187489211615864021135312077912018844630780307462205252807737757672094320692373101032517459518497524015120165166724189816766397247824175394802028228160027100623998873667435799073054618906855460488351426611310634023489044291860510352301912426608488807462312126590206830413782664554260411266378866626653755763627796569082931785645600816236891168141774993267488171702172191072731069216881668294625679492696148976999868715671440874206427212056717373099639711168901197440416590226524192782842896415414611688187391232048327738965820265934093108172054875188246591760877131657895633586576611857277011782497943522945011248430439201297015119468730712364007639373910811953430309476832453230123996750235710787086641070310288725389595138936784715274150426495416196669832679980253436807864187160054589045664027158817958549374490512399055448819148487049363674611664609890030088549591992466360050042566270348330911795487647045949301286614658650071299695652245266080672989921799342509291635330827874264789587306974472327718704306352445925996155619153783913237212716010410294999877569745287353422903443387562746452522860420416689019732913798073773281533570910205207767157128174184873357050830752777900041943256738499067821488421053870869022738698816059810579221002560882999884763252161747566893835178558961142349304466506402373556318707175710866983035313122068321102457824112014969387225476259342872866363550383840720010832906695360553556647545295849966279980830561242960013654529514995113584909050813015198928283202189194615501403435553060147713139766323195743324848047347575473228198492343231496580885057330510949058490527738662697480293583612233134502078182014347192522391449087738579081585795613547198599661273567662441490401862839817822686573112998663038868314974259766039340894024308383451039874674061160538242392803580758232755749310843694194787991556647907091849600704712003371103926967137408125713631396699343733288014254084819379380555174777020843568689927348949484201042595271932630685747613835385434424807024615161848223715989797178155169951121052285149157137697718850449708843330475301440373094611119631361702936342263219382793996895988331701890693689862459020775599439506870005130750427949747071390095256759203426671803377068109744629909769176319526837824364926844730545524646494321826241925107158040561607706364484910978348669388142016838792902926158979355432483611517588605967745393958061959024834251565197963477521095821435651996730128376734574843289089682710350244222290017891280419782767803785277960834729869249991658417000499998999

    Read the article

  • Problem with url_for in ActionMailer template

    - by macek
    I'm attempting to provide a confirmation link in my user welcome email and I'm getting the following Rails error: Need controller and action! It makes a fuss about this line: <p>Please take a moment to activate your account by going to: <%= link_to confirm_user_url(:id => @user.confirmation_code) %>.</p> In my development.rb environment, I have the following line: config.action_mailer.default_url_options = { :host => "localhost", :port => 3000 } There's no problem with the @user variable. I've tested the email with things like @user.username and @user.confirmation_code. I'm only getting trouble with url_for and named routes like confirm_user_url. When I check my routes with rake routes, confirm_user shows up, so it's not an issue with the named route not existing. I can't seem to figure it out. What gives?

    Read the article

  • Test Driven Development (TDD) with Rails

    - by macek
    I am looking for TDD resources that are specific to Rails. I've seen the Rails Guide: The Basics of Creating a Rails Plugin which really spurred my interest in the topic. I have the Agile Development with Rails book and I see there's some testing-related information there. However, it seems like the author takes you through the steps of building the app, then adds testing afterward. This isn't really Test Driven Development. Ideally, I'd like a book on this, but a collection of other tutorials or articles would be great if such a book doesn't exist. Things I'd like to learn: Primary goal: Best Practices Unit testing How to utilize Fixtures Possibly using existing development data in place of fixtures What's the community standard here? Writing tests for plugins Testing with session data User is logged in User can access URL /foo/bar Testing success of sending email Thanks for any help!

    Read the article

  • Calculate sum of objects for each unique object property in Ruby

    - by macek
    I was helping with an answer in this question and it sparked a question of my own. Pie is an object that has a pieces array made of of PiePiece objects. Each PiePiece has a flavor attribute How do I create a hash that looks like this: # flavor => number of pieces { :cherry => 3 :apple => 1 :strawberry => 2 } This works, but I think it could be improved def inventory hash = {} pieces.each do |p| hash[p.flavor] ||= 0 hash[p.flavor] += 1 end hash end Any ideas?

    Read the article

  • Send SYN packet in C#?

    - by Petr
    Hi, I am wondering whether it is even possible or I cannot do such a raw socket manipulation? If so, how can I try it? I am not trying to do this old DoS attack, just curious how to send it thru C#. Thanks

    Read the article

  • Persistent workflow with durable delay activity hosted in ASP.NET

    - by Petr Felzmann
    The situation: a workflow hosted in ASP.NET application using WorkflowServiceHost and contains durable delay. The workflow is currently inside the delay activity and was persisted into database. Then the application pool, under which the ASP.NET application is running, goes to be recycled (e.g. by web.config change) and there are no more http requests to the ASP.NET application. And now is the time when delay activity should finish and next activity in the workflow should be executed. Does it mean the next activity will not be executed until any request to the ASP.NET application because the app pool was recycled?

    Read the article

  • Workflow Foundation: How to create Receive activity with custom message in xaml designer?

    - by Petr Felzmann
    I need to have Receive activity which can receive my custom data. I found examples, but all use coded workflows like such public class ProcessRequest : Activity { public ProcessRequest() { Variable request = new Variable { Name = "request" }; Receive receiveRequest = new Receive { ServiceContractName = "IProcessRequest", OperationName = "Foo", CanCreateInstance = true, Content = ReceiveContent.Create(new OutArgument(request)) }; } } The main point is that Receive.Content property. It is not clear for me how I can do it in XAML designer. What I have to set in the dialog of the Content property - Message or Parameters and what to set inside those options? Thanks for the light!

    Read the article

  • Stack & heap understanding question

    - by Petr
    Hi, I would really appreciate if someone could tell me whether I understand it well: class X { A a1=new A() //reference on the stack, object value on the heap a1.VarA=5; //on the stack - value type A a2=new A() //reference on the stack, object value on the heap a2.VarA=10; //on the stack - value type a1=a2; //on the stack, the target of a1 reference is updated to a2 value on the heap //also both a1 and a2 references are on the stack, while their "object" values on the heap. But what about VarA variable, its still pure value type? } class A { int VarA; }

    Read the article

  • .NET projects build automation with NAnt/MSBuild + SVN

    - by petr k.
    Hi everyone, for quite a while now, I've been trying to figure out how to setup an automated build process at our shop. I've read many posts and guides on this matter and none of them really fits my specifics needs. My SVN repository is laid out as follows \projects \projectA (a product) \tags \1.0.0.1 \1.0.0.2 ... \trunk \src \proj1 (a VS C# project) \proj2 \documentation Then I have a network share, with a folder for each project (product), which in turn contains the binaries, written documentation and the generated API documentation (via NDoc - each project may have an .ndoc file in the repository) for every historical version (from the tags SVN folder) and for the latest version as well (from the trunk). Basically, what I want to do in a scheduled batch build are these steps: examine the project's SVN folder and identify tags not present in the network share for each of these tags check out the tag folder build (with Release config) copy the resulting binaries to the network share search for .ndoc files generate CHM files via NDoc copy the resulting CHM files to the network share do the same as in 2., but for the HEAD revision of trunk Now, the trouble is, I have no idea where to start. I do not keep .sln files in the repository, but I am able to replace these with MSBuild files which in turn build the C# projects belonging to the specific product. I guess the most troubling part is the examination of the repository for tags which have not been processed yet - i.e. searching the tags and comparing them to a project's directory structure on the network share. I have no idea how to do that in any of the build tools (NAnt, MSBuild). Could you please provide me with some pointers on how to approach this task as a whole and in detail as well? I do not care if I use NAnt, MSBuild, or both. I am aware that this might be rather complex, but every idea and NAnt/MSBuild snippet will be a great help. Thanks in advance.

    Read the article

  • Parsing multibyte string in PHP

    - by Petr Peller
    I would like to write a (HTML) parser based on state machine but I have doubts how to acctually read/use an input. I decided to load the whole input into one string and then work with it as with an array and hold its index as current parsing position. There would be no problems with single-byte encoding, but in multi-byte encoding each value does not represent a character, but a byte of a character. Example: $mb_string = 'žšcr'; //4 multi-byte characters in UTF-8 for($i=0; $i < 4; $i++) { echo $mb_string[$i], PHP_EOL; } Outputs: L ž L A This means I cannot iterate through the string in a loop to check single characters, because I never know if I am in the middle of an character or not. So the questions are: How do I multi-byte safe read a single character from a string in a performance friendly way? Is it good idea to work with the string as it was an array in this case? How would you read the input?

    Read the article

  • How to force PyYAML to load strings as unicode objects?

    - by Petr Viktorin
    The PyYAML package loads unmarked strings as either unicode or str objects, depending on their content. I would like to use unicode objects throughout my program (and, unfortunately, can't switch to Python 3 just yet). Is there an easy way to force PyYAML to always strings load unicode objects? I do not want to clutter my YAML with !!python/unicode tags. # Encoding: UTF-8 import yaml menu= u"""--- - spam - eggs - bacon - crème brûlée - spam """ print yaml.load(menu) Output: ['spam', 'eggs', 'bacon', u'cr\xe8me br\xfbl\xe9e', 'spam'] I would like: [u'spam', u'eggs', u'bacon', u'cr\xe8me br\xfbl\xe9e', u'spam']

    Read the article

< Previous Page | 1 2 3 4 5  | Next Page >