Search Results

Search found 257 results on 11 pages for 'boris karl schlein'.

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

  • Socket server with multiple clients, sending messages to many clients without hurting liveliness

    - by Karl Johanson
    I have a small socket server, and I need to distribute various messages from client-to-client depending on different conditionals. However I think I have a small problem with livelyness in my current code, and is there anything wrong in my approach: public class CuClient extends Thread { Socket socket = null; ObjectOutputStream out; ObjectInputStream in; CuGroup group; public CuClient(Socket s, CuGroup g) { this.socket = s; this.group = g; out = new ObjectOutputStream(this.socket.getOutputStream()); out.flush(); in = new ObjectInputStream(this.socket.getInputStream()); } @Override public void run() { String cmd = ""; try { while (!cmd.equals("client shutdown")) { cmd = (String) in.readObject(); this.group.broadcastToGroup(this, cmd); } out.close(); in.close(); socket.close(); } catch (Exception e) { System.out.println(this.getName()); e.printStackTrace(); } } public void sendToClient(String msg) { try { this.out.writeObject(msg); this.out.flush(); } catch (IOException ex) { } } And my CuGroup: public class CuGroup { private Vector<CuClient> clients = new Vector<CuClient>(); public void addClient(CuClient c) { this.clients.add(c); } void broadcastToGroup(CuClient clientName, String cmd) { Iterator it = this.clients.iterator(); while (it.hasNext()) { CuClient cu = (CuClient)it.next(); cu.sendToClient(cmd); } } } And my main-class: public class SmallServer { public static final Vector<CuClient> clients = new Vector<CuClient>(10); public static boolean serverRunning = true; private ServerSocket serverSocket; private CuGroup group = new CuGroup(); public void body() { try { this.serverSocket = new ServerSocket(1337, 20); System.out.println("Waiting for clients\n"); do { Socket s = this.serverSocket.accept(); CuClient t = new CuClient(s,group); System.out.println("SERVER: " + s.getInetAddress() + " is connected!\n"); t.start(); } while (this.serverRunning); } catch (IOException ex) { ex.printStackTrace(); } } public static void main(String[] args) { System.out.println("Server"); SmallServer server = new SmallServer(); server.body(); } } Consider the example with many more groups, maybe a Collection of groups. If they all synchronize on a single Object, I don't think my server will be very fast. I there a pattern or something that can help my liveliness?

    Read the article

  • iPhone SDK - Comparing characters in string

    - by Karl Daniel
    Basically what I'm trying to do is compare 2 strings one from a plist and one from the user's input. I use a while loop to step through each character and compare it and if true then I increase an integer then once the loop has finished I work out the percentage correct / similarity of the plist answer and the user's answer. I seem to be having a problem however as the only return I'm getting is 0. Below is the code I'm using... The code below is all functioning and the question no longer requires answering... Working code... answerLength = boxAnswer.length; //Gets number of characters of first string. plistLength = plistAnswer.length; //Gets number of characters of second string. characterRange = 0; //Sets the variable for which character to look at. charactersCorrect = 0; //Sets the variable of number of matching characters. unichar answerCharacter; //Declares a unichar for the first string. unichar plistCharacter; //Declares a unichar for the second string. while (answerLength > 0 && plistLength > 0) { answerCharacter = [boxAnswer characterAtIndex:characterRange]; //Gets character of first string at the index of the range integer. plistCharacter = [plistAnswer characterAtIndex:characterRange]; //Gets character of second string at the index of the range integer. answerLength--; //Reduces number of characters left to compare. plistLength--; characterRange++; //Increases integer to tell it to look at next character in string. if (answerCharacter == plistCharacter) { //Checks to see if character of first string and character of second string match. charactersCorrect++; //If true increases the number correct. } } //Works out percentage of matching characters out of the total string. totalChar = plistAnswer.length; totalPercentage = (charactersCorrect/totalChar)*100; percentageCorrect.text = [NSString stringWithFormat:@"%i%%",totalPercentage]; Variable Declarations... int answerLength; int plistLength; int characterRange; double totalChar; double charactersCorrect; int totalPercentage;

    Read the article

  • Where did this class come from?

    - by Karl
    How would you go about establishing where a class ( or maybe resource ) has been loaded from? I am trying to work out exactly where a class has been loaded from. Does anyone know if you can find out the following: Which Jar file did the class come from ? What classloader loaded the file?

    Read the article

  • [Rais] OAuth with Digg API

    - by Karl
    I'm attempting to get Rails to play nice with the Digg API's OAuth. I'm using the oauth gem (ruby one, not the rails one). My code looks approximately like this: @consumer = OAuth::Consumer.new(API_KEY, API_SECRET, :scheme => :header, :http_method => :post, :oauth_callback => "http://locahost:3000", :request_token_url => 'http://services.digg.com/1.0/endpoint?method=oauth.getRequestToken', :access_token_url => 'http://services.digg.com/1.0/endpoint?method=oauth.getAccessToken', :authorize_url => 'http://digg.com/oauth/authorize') @request_token = @consumer.get_request_token session[:request_token] = @request_token.token session[:request_token_secret] = @request_token.secret redirect_to @request_token.authorize_url Which is by-the-book in terms of what the gem documentation gave me. However, Digg spits a "400 Bad Request" error back at me when @consumer.get_request_token is called. I can't figure out what I'm doing wrong. Any ideas?

    Read the article

  • Great Circle & Ray intersection

    - by Karl T
    I have a Latitude, Longitude, and a direction of travel in degrees true north. I would like to calculate if I will intersect a line defined by two more Lat/Lon points. I figure the two points defining the line would create my great circle and my location and azimuth would define my ray (or possibly a small circle). Any ideas?

    Read the article

  • problem with trying to create ssms add-in

    - by Karl
    I'm trying to create an add-in for SSMS 2008 and/or 2008 R2 but I've run into a problem straight away. I can get my add-in to work and on SSMS start-up get it to simply show a message box. However, after downloading various code-samples, when trying to reference Microsoft.SqlServer.Management.UI.VSIntegration.ServiceCache I get a null reference exception: Commands2 commands = (Commands2)ServiceCache.ExtensibilityModel.Commands; I get this problem when using SSMS 2008 or SSMS 2008 R2. I'm working on Visual Studio 2010. It's a bit frustrating because I'm keen to learn more about SSMS add-ins but can't seem to get past the few samples out there. Any advice/tips appreciated. Thanks

    Read the article

  • Rails STI: SuperClass Model Methods called from SubClass

    - by Karl
    I would like a little confirmation that I'm doing this correctly. Using rails single table inheritance I have the following models and class method: class PhoneNumber < ActiveRecord::Base def self.qual?(number) klass = self klass.exists?(:phone_number => phone_number) end end class Bubba < PhoneNumber end class Rufus < PhoneNumber end Bubba.qual?("8005551212") Tests pass and everything seems to work properly in rails console. Just wanted to confirm that I'm not headed for future trouble by using self in the superclass PhoneNumber and using that to execute class methods on subclasses from the parent. Is there a better way?

    Read the article

  • Run Configuration Batch Script

    - by Karl
    For the purpose of a demonstration I'm looking for a way to start an eclipse run configuration from outside using a script (e.g. windows batch script). I have no idea if that's possible or how to do it.. Does anybody have an idea?

    Read the article

  • Inserting only unique values into an array

    - by karl
    I have a set of values that I'm pushing into an array in the order they occur $valsArray = array(); //I process each value from a file (code removed for simplicity) //and then add into the array $valsArray[] = $val; How do I turn this into an associative array instead where the value gets inserted (as $key of associative array) only if it doesn't exist. If it does exist increment its count ($value of associative array) by 1. I'm trying to find a more efficient way of handling those values compared to what I'm doing now.

    Read the article

  • Google maps nearest points avoiding rivers / by itinerary

    - by Karl Lacroix
    Here is the deal : I need to find the closest points from a point with a radius. For example, I need to get all the points in a 15 km radius. Thats easy with Google Maps Radius and all the examples on the web ;) The problem is that from my office, a point is under the 15km radius, but it's on the other side of a river, so the car itinerary is about 30 km (using a bridge)! Is there a simple solution to exclude those points or to calculate by intineraries ? I supposed that I'll need to calculate all itineraries with returned points? DirectionsRequest API? Thanks! :)

    Read the article

  • Clean Up Controller, Update Item Quantity within Cart

    - by Karl Entwistle
    Hi guys I was wondering if anyone could help me out, I need to clean up this controller as the resulting code to simply update an items quantity if it already exists seems way too complex. class LineItemsController < ApplicationController def create @product = Product.find(params[:product_id]) if LineItem.exists?(:cart_id => current_cart.id) item = LineItem.find(:first, :conditions => [ "cart_id = #{@current_cart.id}"]) LineItem.update(item.id, :quantity => item.quantity + 1) else @line_item = LineItem.create!(:cart => current_cart, :product => @product, :quantity => 1, :unit_price => @product.price) flash[:notice] = "Added #{@product.name} to cart." end redirect_to root_url end end ` As always any help is much appreciated, the code should be fairly self explanatory, thanks :) PS posted it here as well as it looks a bit funny on here http://pastie.org/994059

    Read the article

  • Why does using Collections.emptySet() with generics work in assignment but not as a method parameter

    - by Karl von L
    So, I have a class with a constructor like this: public FilterList(Set<Integer> labels) { ... } and I want to construct a new FilterList object with an empty set. Following Joshua Bloch's advice in his book Effective Java, I don't want to create a new object for the empty set; I'll just use Collections.emptySet() instead: FilterList emptyList = new FilterList(Collections.emptySet()); This gives me an error, complaining that java.util.Set<java.lang.Object> is not a java.util.Set<java.lang.Integer>. OK, how about this: FilterList emptyList = new FilterList((Set<Integer>)Collections.emptySet()); This also gives me an error! Ok, how about this: Set<Integer> empty = Collections.emptySet(); FilterList emptyList = new FilterList(empty); Hey, it works! But why? After all, Java doesn't have type inference, which is why you get an unchecked conversion warning if you do Set<Integer> foo = new TreeSet() instead of Set<Integer> foo = new TreeSet<Integer>(). But Set<Integer> empty = Collections.emptySet(); works without even a warning. Why is that?

    Read the article

  • Form With Quantity doesn't seem to submit

    - by Karl Entwistle
    Hey guys, I've been trying to understand the documentation and find an example, but I'm at a loss. This is just a submit form within the cart for updating the quantity. However, the updated quantity is not getting saved to the database -- it always makes the quantity 0. Please help. Form <% for line_item in @cart.line_items %> <% form_for :lineitems, :url => {:controller => "line_items", :action => "cart_update", :id => "#{line_item.product_id}"} do |l| %> <%= l.text_field :quantity, :size => '3', :value => line_item.quantity %> <%= l.submit 'cart_update' %> <% end %> Route map.connect 'line_item_update', :controller => 'line_items', :action => 'cart_update' Controller def cart_update @product = Product.find(params[:id]) item = LineItem.find_or_create_by_cart_id(:cart_id => current_cart.id, :product_id => @product.id, :quantity => 0, :unit_price => @product.price) item.quantity = (params[:quantity]).to_i item.save redirect_to :controller => 'products' end

    Read the article

  • JQuery post not working when moving web-app to a win server 2003

    - by karl
    I have build a webapplication using ASP.NET MVC and JQuery. On my local machine this works fine,but when moving it to a Windows server 2003 the JQuery method post stops working. I'm also using the load method and this works fine. function methodOne(id) { alert("debug1: <%= Url.Action( "MethodOne", "controller" ) + "/" %>" + id); $.post <%= Url.Action( "MethodOne", "controller" ) + "/" %>" + id, function(data) { alert("debug2"); ... } else { alert("Debugg: Add presentation to user failed"); } }); } The debug2 is never outputed. $('#panel').load("<%= Url.Action( "Method", "Controller" ) %"); Works fine.

    Read the article

  • Weird use of generics

    - by Karl Trumstedt
    After a bit of programming one of my classes used generics in a way I never seen before. I would like some opinions of this, if it's bad coding or not. abstract class Base<T> : where T : Base<T> { // omitted methods and properties. virtual void CopyTo(T instance) { /*code*/ } } class Derived : Base<Derived> { override void CopyTo(Derived instance) { base.CopyTo(instance); // copy remaining stuff here } } is this an OK use of generics or not? I'm mostly thinking about the constraint to "itself". I sometimes feel like generics can "explode" to other classes where I use the Base class.

    Read the article

  • PHP - While loop

    - by Karl Entwistle
    print "<ul>"; foreach ($arr as $value) { echo("<li>" . $value[storeid] . " " . ($value[dvdstock] + $value[vhsstock]) . "</li>"); } print "</ul>"; Will output •2 20 •2 10 •1 20 •1 20 •1 10 I was wondering how I would adapt this loop so it outputs the total values for each &value[storeid] •1 50 •2 30 Thanks very much :)

    Read the article

  • java: relationship of the Runnable and Thread interfaces

    - by Karl Patrick
    I realize that the method run() must be declared because its declared in the Runnable interface. But my question comes when this class runs how is the Thread object allowed if there is no import call to a particular package? how does runnable know anything about Thread or its methods? does the Runnable interface extend the Thread class? Obviously I don't understand interfaces very well. thanks in advance. class PrimeFinder implements Runnable{ public long target; public long prime; public boolean finished = false; public Thread runner; PrimeFinder(long inTarget){ target = inTarget; if(runner == null){ runner = new Thread(this); runner.start() } } public void run(){ } }

    Read the article

  • Finding the right terminology for a dictionary table

    - by Karl Forner
    My concern is about what I currently call "dictionary tables", that are database tables containing a list of controlled vocabulary. Let's use an example: Suppose you have a table User containing fields: user_id : primary key first_name last_name user_type_id : foreign key to the UserType table and another table UserType with just two fields: user_type_id : primary key name : the name/value of a particular type of user. For instance, the UserType table may contain (1, Administrator), (2, PowerUser), (3, Normal)... My question is: what is the canonical term for a table like UserType, that only contains a list of (dictinct) words. I want to publish some code that help managing this kind of tables, but first I have to name them ! Thanks for your help. Current state of thought: For now I feel Lookup Tables is a good term. It is also used with the same meaning in these posts: http://dbix-class.35028.n2.nabble.com/RFC-Component-for-Lookup-tables-td3504085.html http://tonyandrews.blogspot.de/2004/10/otlt-and-eav-two-big-design-mistakes.html Lookup Tables Best Practices: DB Tables... or Enumerations The only problem is that lookup table is also sometimes used to name a junction table.

    Read the article

  • Great Circle & Rhumb line intersection

    - by Karl T
    I have a Latitude, Longitude, and a direction of travel in degrees true north. I would like to calculate if I will intersect a line defined by two more Lat/Lon points. I figure the two points defining the line would create my great circle and my location and azimuth would define my Rhumb line. I am only interested in intersections that will occur with a few hundred kilometers so I do not need every possible solution. I have no idea where to begin.

    Read the article

  • trouble accessing localhost from ie7 running on parallels (win xp) on mac os x

    - by Karl R
    I'm running the app engine devserver on localhost:8080, and want to access it from ie7 running on parallels. I've tried all of the tips here: http://stackoverflow.com/questions/61449/how-do-i-access-the-host-from-vmware-fusion And they seem like they should work, particularly accessing via the gateway ip address. I've also sudo ipfw add allow tcp from 8080 to 8089 for good measure. Still no dice. I can access the external internet from ie7. The connection settings on parallels are set to 'Shared networking'. I'm out of ideas.

    Read the article

  • Redirect all requests to a subdirectory

    - by Karl Keefer
    I have a drupal site install at example.com/drupal but now that the site is built I want to forward all requests to that directory, without it ever showing "drupal" in url. I think this can be done with .htaccess, but I didn't know if that was a hack-y answer. I'm using mediatemple's GridServer so I don't have complete control over apache settings and stuff, although I do have SSH.

    Read the article

  • after_create :create a new line in DB

    - by Karl Entwistle
    Hey guys I was wondering if anyone could help me with an issue im having, basically id like to have Account.create after a PayPal notification is received, There is a simple cart model which corresponds to line_items within the cart so add_account_to_market would look like this in pseudo code def add_account_to_market if status == "Completed" find the line items(via cart_id) that correspond to the cart.id that just been paid create an account with user_id set to the current carts user id end end Ive never tried to do something like this in Rails and its not working, Ive been pulling my hair out all night trying to fix this, hopefully someone can help or point me in the right direction. Thanks :) class PaymentNotification < ActiveRecord::Base belongs_to :cart serialize :params after_create :mark_cart_as_purchased after_create :add_account_to_market private def mark_cart_as_purchased if status == "Completed" cart.update_attribute(:purchased_at, Time.now) cart.update_attribute(:paid, true) end end def add_account_to_market if status == "Completed" l = LineItem.find(:all, :conditions => "cart_id = '#{cart.id}'") for l.quantity Account.new(:user_id => cart.user_id) end end end end PS mark_cart_as_purchased method is working fine, its just the add_account_to_market im having issues with.

    Read the article

  • C++ Header file questions

    - by Karl
    So I'm trying to learn C++ and I've gotten as far as using header files. They really make no sense to me. I've tried many combinations of this but nothing so far has worked: Main.cpp: #include "test.h" int main() { testClass Player1; return 0; } test.h: #ifndef TEST_H_INCLUDED #define TEST_H_INCLUDED class testClass { private: int health; public: testClass(); ~testClass(); int getHealth(); void setHealth(int inH); }; #endif // TEST_H_INCLUDED test.cpp: #include "test.h" testClass::testClass() { health = 100; } testClass::~testClass() {} int testClass::getHealth() { return(health); } void testClass::setHealth(int inH) { health = inH; } What I'm trying to do is pretty simple, but the way the header files work just makes no sense to me at all. Code blocks returns the following on build: obj\Debug\main.o(.text+0x131)||In function main':| *voip*\test\main.cpp |6|undefined reference totestClass::testClass()'| obj\Debug\main.o(.text+0x13c):voip\test\main.cpp|7|undefined reference to `testClass::~testClass()'| ||=== Build finished: 2 errors, 0 warnings ===| I'd appreciate any help. Or if you have a decent tutorial for it, that would be fine too (most of the tutorials I've googled haven't helped)

    Read the article

  • [Rails] HTTP Get Request

    - by Karl
    I've been trying to get Rails to play with the new Facebook Graph API. After I get the authorization "code", I need to send another request which returns the access token in JSON form. It seems to work fine, however I want to fetch the access token JSON without redirecting the user. I'm attempting to use Net::HTTP.get, but I'm not sure how to use it to get a request body, or even if it's the right thing to use to begin with. Can anyone give an example of performing an HTTP GET?

    Read the article

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