Daily Archives

Articles indexed Monday May 3 2010

Page 5/107 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • How to determine Scale of Line Graph based on Pixels/Height?

    - by Dexter
    I have a problem due to my terrible math abilities, that I cannot figure out how to scale a graph based on the maximum and minimum values so that the whole graph will fit onto the graph-area (400x420) without parts of it being off the screen (based on a given equation by user). Let's say I have this code, and it automatically draws squares and then the line graph based on these values. What is the formula (what do I multiply) to scale it so that it fits into the small graphing area? vector<int> m_x; vector<int> m_y; // gets automatically filled by user equation or values int HeightInPixels = 420;// Graphing area size!! int WidthInPixels = 400; int best_max_y = GetMaxOfVector(m_y); int best_min_y = GetMinOfVector(m_y); m_row = 0; m_col = 0; y_magnitude = (HeightInPixels/(best_max_y+best_min_y)); // probably won't work magnitude = (WidthInPixels/(int)m_x.size()); m_col = m_row = best_max_y; // number of vertical/horizontal lines to draw ////x_magnitude = (WidthInPixels/(int)m_x.size())/2; Doesn't work well ////y_magnitude = (HeightInPixels/(int)m_y.size())/2; Doesn't work well ready = true; // we have values, graph it Invalidate(); // uses WM_PAINT

    Read the article

  • Do I need to include the 'this' when using a property name in a closure?

    - by Scott Whitlock
    I'm using a list of Actions to store an undo history for an object. Let's say I have a property of my object called myChildObject and it's being changed, so I want to store the undo action where I would set it back to it's current value: public class Class1 { public Class1() { } private readonly List<Action> m_undoActions = new List<Action>(); private SomeObject myChildObject { get; set; } public void ChangeState(SomeObject newChildObject) { // copies the reference SomeObject existingObject = myChildObject; m_undoActions.Add(() => myChildObject = existingObject); myChildObject = newChildObject; } } Looking at the lambda expression, existingObject is a local variable, so it's using a closure to pass a reference to that variable, but what about the property myChildObject? Do I need to use 'this' to preface it? Do I need to make a copy of the 'this' reference to a local variable first? Thanks for helping me understand this closure stuff.

    Read the article

  • How to cache and store objects and set an expire policy in android?

    - by virsir
    I have an app fetch data from internet, for better performance and bandwidth, I need to implement a cache layer. There are two different data coming from the internet, one is changing every one hour and another one does not change basically. So for the first type of data, I need to implement an expire policy to make it self deleted after it was created for 1 hour, and when user request that data, I will check the storage first and then goto internet if nothing found. I thought about using a SharedPrefrence or SQLDatabase to store the json data or serialized object string. My question is: 1) What should I use, SharedPrefrence or SQLDatabase or anything else, a piece of data is not big but there are maybe many instances of that data. 2) How to implement that expire system.

    Read the article

  • Unable to get simple ruby on rails Search to work :/

    - by edu222
    I am new to RoR, any help would be greatly appreciated :) I have a basic scaffolding CRUD app to add customers. I am trying to search by first_name or last_name fields. The error that I am getting is: NoMethodError in Clientes#find You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each Extracted source (around line #9): 6: <th>Apellido</th> 7: </tr> 8: 9: <% for cliente in @clientes %> 10: <tr> 11: <td><%=h cliente.client_name %></td> 12: <td><%=h cliente.client_lastname %></td> Application Trace C:/Rails/clientes/app/views/clientes/find.html.erb:9:in `_run_erb_app47views47clientes47find46html46erb' My find function in controllers/clientes_controlee.rb is: # Find def find @cliente = Cliente.find(:all, :conditions=>["client_name = ? OR client_lastname = ?", params[:search_string], params[:search_string]]) end My views/layouts clientes.html.erb form code fragment is: <span style="text-align: right"> <% form_tag "/clientes/find" do %> <%= text_field_tag :search_string %> <%= submit_tag "Search" %> <% end %> </span> The search template I created in views/clientes/find.html.erb: <h1>Listing clientes for <%= params[:search_string] %></h1> <table> <tr> <th>Nombre</th> <th>Apellido</th> </tr> <% for cliente in @clientes %> <tr> <td><%=h cliente.client_name %></td> <td><%=h cliente.client_lastname %></td> <td><%= link_to 'Mostrar', cliente %></td> <td><%= link_to 'Editar', edit_cliente_path(cliente) %></td> <td><%= link_to 'Eliminar', cliente, :confirm =>'Estas Seguro de que desear eliminar a este te cliente?', :method => :delete %></td> </tr> <% end %> </table> <%= link_to 'Atras', clientes_path %

    Read the article

  • Python API for VirtualBox

    - by jessica
    I have made a command-line interface for virtualbox such that the virtualbox can be controlled from a remote machine. now I am trying to implement the commmand-line interface using python virtualbox api. For that I have downloaded the pyvb package (python api documentation shows functions that can be used for implementing this under pyvb package). but when I give pyvb.vb.VB.startVM(instance of VB class,pyvb.vm.vbVM) SERVER SIDE CODE IS from pyvb.constants import * from pyvb.vm import * from pyvb.vb import * import xpcom import pyvb import os import socket import threading class ClientThread ( threading.Thread ): # Override Thread's init method to accept the parameters needed: def init ( self, channel, details ): self.channel = channel self.details = details threading.Thread.__init__ ( self ) def run ( self ): print 'Received connection:', self.details [ 0 ] while 1: s= self.channel.recv ( 1024 ) if(s!='end'): if(s=='start'): v=VB() pyvb.vb.VB.startVM(v,pyvb.vm.vbVM) else: self.channel.close() break print 'Closed connection:', self.details [ 0 ] server = socket.socket ( socket.AF_INET, socket.SOCK_STREAM ) server.bind ( ( '127.0.0.1', 2897 ) ) server.listen ( 5 ) while True: channel, details = server.accept() ClientThread ( channel, details ).start() it shows an error Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.5/threading.py", line 486, in __bootstrap_inner self.run() File "news.py", line 27, in run pyvb.vb.VB.startVM(v,pyvb.vm.vbVM.getUUID(m)) File "/usr/lib/python2.5/site-packages/pyvb-0.0.2-py2.5.egg/pyvb/vb.py", line 65, in startVM cmd='%s %s'%(VB_COMMAND_STARTVM, vm.getUUID()) AttributeError: 'str' object has no attribute 'getUUID'

    Read the article

  • Help combining these two queries

    - by Horace Loeb
    I need a SQL query that returns results matched by EITHER of the following SQL queries: Query 1: SELECT "annotations".* FROM "annotations" INNER JOIN "votes" ON "votes".voteable_id = "annotations".id AND "votes".voteable_type = 'Annotation' WHERE (votes.vote = 't' AND votes.voter_id = 78) Query 2: SELECT "annotations".* FROM "annotations" INNER JOIN "songs" ON "songs".id = "annotations".song_id INNER JOIN "songs" songs_annotations ON "songs_annotations".id = "annotations".song_id INNER JOIN "users" ON "users".id = "songs_annotations".state_last_updated_by_id WHERE (annotations.referent IS NOT NULL AND annotations.updated_at < '2010-04-05 01:51:24' AND (body = '?' OR body LIKE '%[?]%') AND ((users.id = songs.state_last_updated_by_id and users.needs_edit = 'f' and songs.state != 'work_in_progress') OR (songs.state = 'published')) Here's what I tried, but it doesn't work: SELECT "annotations".* FROM "annotations" INNER JOIN "songs" ON "songs".id = "annotations".song_id INNER JOIN "songs" songs_annotations ON "songs_annotations".id = "annotations".song_id INNER JOIN "users" ON "users".id = "songs_annotations".state_last_updated_by_id INNER JOIN "votes" ON "votes".voteable_id = "annotations".id AND "votes".voteable_type = 'Annotation' WHERE ((votes.vote = 't' and votes.voter_id = 78) OR (annotations.referent IS NOT NULL and annotations.updated_at < '2010-04-05 01:43:52' and (annotations.body = '?' OR annotations.body LIKE '%[?]%') and ((users.id = songs.state_last_updated_by_id and users.needs_edit = 'f') OR songs.state = 'published')))

    Read the article

  • WMIprvse process leaks memory on 2008 server R2

    - by Dani Fischer
    I have a Windows 2008 R2 server running on a VM machine. My .NET service is running on this server periodically querying WMI, for example: SELECT ProcessId FROM Win32_Service WHERE ... After a day or two WMIprvse takes up to 500M memory and WMI queries start getting out of memory exceptions. This article seems to be talking about this issue: "http://support.microsoft.com/kb/958124" I've seen other articles saying that Microsoft is aware of the problem and not going to issue a fix until the next major release. http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/256eb40c-d050-4278-a3d8-863e30db02a0 I'd appreciate any suggestions and insights on this.

    Read the article

  • check file revision through http only

    - by romant
    if the svn repo is exposed through say : http://svn to the users, and there's a file called script.sh Is there a way one can get the latest revision number of script.sh by means of just http access? Something along the lines of http://svn/rev?script.sh ?! Thank you.

    Read the article

  • Question about Virtual Inheritance hierarchy

    - by Summer_More_More_Tea
    Hi there: I encounter this problem when tackling with virtual inheritance. I remember that in a non-virtual inheritance hierarchy, object of sub-class hold an object of its direct super-class. What about virtual inheritance? In this situation, does object of sub-class hold an object of its super-class directly or just hold a pointer pointing to an object of its super-class? By the way, why the output of the following code is: sizeof(A): 8 sizeof(B): 20 sizeof(C): 20 sizeof(C): 36 Code: #include <iostream> using namespace std; class A{ char k[ 3 ]; public: virtual void a(){}; }; class B : public virtual A{ char j[ 3 ]; public: virtual void b(){}; }; class C : public virtual B{ char i[ 3 ]; public: virtual void c(){}; }; class D : public B, public C{ char h[ 3 ]; public: virtual void d(){}; }; int main( int argc, char *argv[] ){ cout << "sizeof(A): " << sizeof( A ) << endl; cout << "sizeof(B): " << sizeof( B ) << endl; cout << "sizeof(C): " << sizeof( C ) << endl; cout << "sizeof(D): " << sizeof( D ) << endl; return 0; } Thanks in advance. Kind regards.

    Read the article

  • Multilingual Text to Speech Libraries?

    - by Jeremy
    Hi all, I'm currently looking at developing a small client that has the ability to read text to speech in a variety of languages. Mainly targeting English & Japanese. So my question is, does anyone know of a library that is capable of reading English and Japanese to speech? My target development language initially, is c# Thanks for your time.

    Read the article

  • How to limit NSTextField text length and keep it always upper case?

    - by carlosb
    Need to have an NSTextField with a text limit of 4 characters maximum and show always in upper case but can't figure out a good way of achieving that. I've tried to do it through a binding with a validation method but the validation only gets called when the control loses first responder and that's no good. Temporarly I made it work by observing the notification NSControlTextDidChangeNotification on the text field and having it call the method: - (void)textDidChange:(NSNotification*)notification { NSTextField* textField = [notification object]; NSString* value = [textField stringValue]; if ([value length] > 4) { [textField setStringValue:[[value uppercaseString] substringWithRange:NSMakeRange(0, 4)]]; } else { [textField setStringValue:[value uppercaseString]]; } } But this surely isn't the best way of doing it. Any better suggestion?

    Read the article

  • Java newbie problem: package with private access

    - by HH
    Pack.java imports pack.TestPack; but it cannot access it. I cannot understand why it cannot access the class despite the import. Error Pack.java:7: TestPack() is not public in pack.TestPack; cannot be accessed from outside package System.out.println(new TestPack().getHello()); ^ 1 error Pack.java import pack.TestPack; import java.io.*; public class Pack { public static void main(String[] args){ System.out.println(new TestPack().getHello()); } } TestPack.java package pack; import java.util.*; import java.io.*; public class TestPack { private String hello="if you see me, you ar inside class TestPack"; public String getHello(){return hello;} TestPack(){} }

    Read the article

  • jQuery ajaxForm returning .json file

    - by Lowgain
    I've got a model creation form in rails which I also have returning JSON through ajax. My code so far look like: $('#new_stem').ajaxForm({ //#new_stem is my form dataType: 'json', success: formSuccess }); function formSuccess(stemObj) { //does stuff with stemObj } And I have a multipart form with a file uploader (but I'm not sure if that is relevant). When I submit the form it works fine (my models are properly being created and renders as json), but instead of the json getting handled by the formSuccess function, it prompts a download for "stems.json" (the path to my stem creation action) in Firefox. What would cause this to happen, and what could solve it? Not sure if this is part of the problem, but I don't have a submit button in my form, I have a link with a click handler that calls $('#new_stem).submit() Thanks guys!

    Read the article

  • Next step for Python app using Sqlite db

    - by ChrisC
    I want to write a db program in Python using Sqlite. I have the db table structure planned, and am ready to move to the next step, which I think is to work any bugs out of the db structure. I am totally inexperienced in development except for writing the original db (written in MS Access), and an Intro to C++ class (OOP concepts and console C++ programs). Is it time to test the db structure? If so, what's the best way, and what tool(s) should I use? Thank you.

    Read the article

  • XNA - Keyboard text input

    - by Sekhat
    Okay, so basically I want to be able to retrieve keyboard text. Like entering text into a text field or something. I'm only writing my game for windows. I've disregarded using Guide.BeginShowKeyboardInput because it breaks the feel of a self contained game, and the fact that the Guide always shows XBOX buttons doesn't seem right to me either. Yes it's the easiest way, but I don't like it. Next I tried using System.Windows.Forms.NativeWindow. I created a class that inherited from it, and passed it the Games window handle, implemented the WndProc function to catch WM_CHAR (or WM_KEYDOWN) though the WndProc got called for other messages, WM_CHAR and WM_KEYDOWN never did. So I had to abandon that idea, and besides, I was also referencing the whole of Windows forms, which meant unnecessary memory footprint bloat. So my last idea was to create a Thread level, low level keyboard hook. This has been the most successful so far. I get WM_KEYDOWN message, (not tried WM_CHAR yet) translate the virtual keycode with Win32 funcation MapVirtualKey to a char. And I get my text! (I'm just printing with Debug.Write at the moment) A couple problems though. It's as if I have caps lock on, and an unresponsive shift key. (Of course it's not however, it's just that there is only one Virtual Key Code per key, so translating it only has one output) and it adds overhead as it attaches itself to the Windows Hook List and isn't as fast as I'd like it to be, but the slowness could be more due to Debug.Write. Has anyone else approached this and solved it, without having to resort to an on screen keyboard? or does anyone have further ideas for me to try? thanks in advance. note: This is cross posted from the XNA Creators Forums, so if I get an answer there I'll post it here and Vice-Versa Question asked by Jimmy Maybe I'm not understanding the question, but why can't you use the XNA Keyboard and KeyboardState classes? My comment: It's because though you can read keystates, you can't get access to typed text as and how it is typed by the user. So let me further clarify. I want to implement being able to read text input from the user as if they are typing into textbox is windows. The keyboard and KeyboardState class get states of all keys, but I'd have to map each key and combination to it's character representation. This falls over when the user doesn't use the same keyboard language as I do especially with symbols (my double quotes is shift + 2, while american keyboards have theirs somewhere near the return key).

    Read the article

  • C++, Get text from a website

    - by pure841
    I was told I have to use winsock, but I dont know where to start. For example, I am trying to access, lets say http://www.newegg.com/, I am trying to get the text title of just the three front page products. Any help is greatly appreciated. :D

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >