Search Results

Search found 362 results on 15 pages for 'jake rue'.

Page 12/15 | < Previous Page | 8 9 10 11 12 13 14 15  | Next Page >

  • Threadsafe way of exposing keySet()

    - by Jake
    This must be a fairly common occurrence where I have a map and wish to thread-safely expose its key set: public MyClass { Map<String,String> map = // ... public final Set<String> keys() { // returns key set } } Now, if my "map" is not thread-safe, this is not safe: public final Set<String> keys() { return map.keySet(); } And neither is: public final Set<String> keys() { return Collections.unmodifiableSet(map.keySet()); } So I need to create a copy, such as: public final Set<String> keys() { return new HashSet(map.keySet()); } However, this doesn't seem safe either because that constructor traverses the elements of the parameter and add()s them. So while this copying is going on, a ConcurrentModificationException can happen. So then: public final Set<String> keys() { synchronized(map) { return new HashSet(map.keySet()); } } seems like the solution. Does this look right?

    Read the article

  • How do I do arithmetic operations on HH:MM:SS format time strings in C#?

    - by Jake
    I have a series of times that are coming to me as strings from a web service. The times are formated as HH:MM:SS:000 (3 milisecond digits). I need to compare two times to determine if one is more than twice as long as the other: if ( timeA / timeB > 2 ) What's the simplest way to work with the time strings? If I was writing in Python this would be the answer to my question: Difference between two time intervals in Python

    Read the article

  • Getting the ranking of a photo in SQL

    - by Jake Petroules
    I have the following tables: Photos [ PhotoID, CategoryID, ... ] PK [ PhotoID ] Categories [ CategoryID, ... ] PK [ CategoryID ] Votes [ PhotoID, UserID, ... ] PK [ PhotoID, UserID ] A photo belongs to one category. A category may contain many photos. A user may vote once on any photo. A photo can be voted for by many users. I want to select the ranks of a photo (by counting how many votes it has) both overall and within the scope of the category that photo belongs to. The count of SELECT * FROM Votes WHERE PhotoID = @PhotoID being the number of votes a photo has. I want the resulting table to have generated columns for overall rank, and rank within category, so that I may order the results by either. So for example, the resulting table from the query should look like: PhotoID VoteCount RankOverall RankInCategory 1 48 1 7 3 45 2 5 19 33 3 1 2 17 4 3 7 9 5 5 ... ...you get the idea. How can I achieve this? So far I've got the following query to retrieve the vote counts, but I need to generate the ranks as well: SELECT PhotoID, UserID, CategoryID, DateUploaded, (SELECT COUNT(CommentID) AS Expr1 FROM dbo.Comments WHERE (PhotoID = dbo.Photos.PhotoID)) AS CommentCount, (SELECT COUNT(PhotoID) AS Expr1 FROM dbo.PhotoVotes WHERE (PhotoID = dbo.Photos.PhotoID)) AS VoteCount, Comments FROM dbo.Photos

    Read the article

  • Where is shared_ptr?

    - by Jake
    I am so frustrated right now after several hours trying to find where shared_ptr is located. None of the examples I see show complete code to include the headers for shared_ptr (and working). Simply stating "std" "tr1" and "" is not helping at all! I have downloaded boosts and all but still it doesn't show up! Can someone help me by telling exactly where to find it? Thanks for letting me vent my frustrations!

    Read the article

  • Copy and Store LPTSTR in class causes crash

    - by Jake M
    I am attempting to copy a LPTSTR and store that string as a member variable in an object. But my attempts to copy the LPTSTR seem to fail and when I go to access/print the value of the copied LPTSTR I get a program crash. Is it possible to copy a LPTSTR and store it in my class below or is it better to just use a TCHAR*? class Checkbox { private: LPTSTR text; HWND hwnd; public: Checkbox(HWND nHwnd, LPTSTR nText) { lstrcpy(checkText, text); } void print() { // Causes a crash MessageBox(hwnd, text, text, MB_OK); } };

    Read the article

  • setting codeigniter mysql datetime column to time() always sets it to 0

    - by Jake
    Hi guys. I'm using Codeigniter for a small project, and my model works correctly except for the dates. I have a column defined: created_at datetime not null and my model code includes in its array passed into db-insert: 'created_at' = time() This produces a datetime value of 0000-00-00 00:00:00. When I change it to: 'created_at' = "from_unixtime(" . time() . ")" it still produces the 0 datetime value. What am I doing wrong? How can I set this field to the given unix time? Also, I know mysql sets TIMESTAMP columns automatically for you - I'm not interested in that solution here. So far I can't find a complete example of this on the web.

    Read the article

  • How can I make my tableview enter editing mode?

    - by Jake
    Hi, for some reason I can't get my tableview to enter editing mode. It's a little harder than it might seem because I'm using some open source code to make a calendar (iCal esque) with a tableview under it, and it's not quite as straightforward as just using a regular tableview. Basically, I have two classes. One (let's say Class A) is a UIViewController and the other (Class B) is that viewController's datasource and tableview delegate. In Class B, I've implemented -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; which works fine, but if I put an edit nav bar item in Class A (the view controller), nothing happens. Am I forgetting certain protocols, or certain special methods that I need to write? Thanks for any help, and apologies if I'm missing something, I'm just learning to work with other people's code.

    Read the article

  • Replacing a unicode character in UTF-8 file using delphi 2010

    - by Jake Snake
    I am trying to replace character (decimal value 197) in a UTF-8 file with character (decimal value 65) I can load the file and put it in a string (may not need to do that though) SS := TStringStream.Create(ParamStr1, TEncoding.UTF8); SS.LoadFromFile(ParamStr1); //S:= SS.DataString; //ShowMessage(S); However, how do i replace all 197's with a 65, and save it back out as UTF-8? SS.SaveToFile(ParamStr2); SS.Free; -------------- EDIT ---------------- reader:= TStreamReader.Create(ParamStr1, TEncoding.UTF8); writer:= TStreamWriter.Create(ParamStr2, False, TEncoding.UTF8); while not Reader.EndOfStream do begin S:= reader.ReadLine; for I:= 1 to Length(S) do begin if Ord(S[I]) = 350 then begin Delete(S,I,1); Insert('A',S,I); end; end; writer.Write(S + #13#10); end; writer.Free; reader.Free;

    Read the article

  • Qt toggle always on top for a QMainWindow

    - by Jake Petroules
    void MainWindow::on_actionAlways_on_Top_triggered(bool checked) { Qt::WindowFlags flags = this->windowFlags(); if (checked) { this->setWindowFlags(flags | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint); this->show(); } else { this->setWindowFlags(flags ^ (Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint)); this->show(); } } The above solution works but because setWindowFlags hides the window, it needs to be reshown and of course that doesn't look very elegant. So how do I toggle "always on top" for a QMainWindow without that "flashing" side effect?

    Read the article

  • Function to get X, Y position of an object orbiting a point, given a distance and angle in radians?

    - by Jake Petroules
    I am trying to code a function for a camera that orbits a point. Assume a 3d coordinate plane where Z is up. Ignore Z. Let's say the camera's position starts at (0, 0, z). The object to orbit is at, say (50, 50, z). So we have a distance of ~70 units. Calling the function with {(50, 50, z), 70, x} where x is the position in orbit, in radians, should return where the position of the camera should be. I believe this involves cos and tan but my trig isn't that great... point3d getCameraPosition(point3d objectPosition, float distance, float rotationRadians) { // ??? }

    Read the article

  • What is the point of heightmaps?

    - by Jake Petroules
    I've been pondering this question awhile now... many 3d engines support advanced terrain rendering using quadtrees, LOD... all the features you expect. But every engine I've seen loads height data from heightmaps... grayscale bitmaps. I just can't understand how this is useful - each point in a heightmap can have one of 256 values. But what if you wanted to model Mt. Everest? with detail of 1 meter, or even greater? That's far outside the range of 256. Of course I understand that you can implement your own terrain format to achieve this, but I just can't see why heightmaps are so widely used despite their great limitations.

    Read the article

  • Simple RSA encryption (Java)

    - by jake blue
    This is simply for fun. This will not be used for any actual encryption. I'm only first year comp sci student and love cryptography. This took a long time to get working. At approximately N = 18, it begins breaking down. It won't encrypt messages properly after that point. I'm not sure why. Any insights? I'd also appreciate any links you could provide me to tutorials or interesting reading about Cryptography. import java.math.BigInteger; import java.security.SecureRandom; /** * Cryptography. * * Generates public and private keys used in encryption and * decryption * */ public class RSA { private final static BigInteger one = new BigInteger("1"); private final static SecureRandom random = new SecureRandom(); // prime numbers private BigInteger p; private BigInteger q; // modulus private BigInteger n; // totient private BigInteger t; // public key private BigInteger e; // private key private BigInteger d; private String cipherText; /** * Constructor for objects of class RSA */ public RSA(int N) { p = BigInteger.probablePrime(N/2, random); q = BigInteger.probablePrime(N/2, random); // initialising modulus n = p.multiply(q); // initialising t by euclid's totient function (p-1)(q-1) t = (p.subtract(one)).multiply(q.subtract(one)); // initialising public key ~ 65537 is common public key e = new BigInteger("65537"); } public int generatePrivateKey() { d = e.modInverse(t); return d.intValue(); } public String encrypt(String plainText) { String encrypted = ""; int j = 0; for(int i = 0; i < plainText.length(); i++){ char m = plainText.charAt(i); BigInteger bi1 = BigInteger.valueOf(m); BigInteger bi2 = bi1.modPow(e, n); j = bi2.intValue(); m = (char) j; encrypted += m; } cipherText = encrypted; return encrypted; } public String decrypt() { String decrypted = ""; int j = 0; for(int i = 0; i < cipherText.length(); i++){ char c = cipherText.charAt(i); BigInteger bi1 = BigInteger.valueOf(c); BigInteger bi2 = bi1.modPow(d, n); j = bi2.intValue(); c = (char) j; decrypted += c; } return decrypted; } }

    Read the article

  • Maven. What to do with "homeless" jars?

    - by Jake
    I have some proprietary.jar that I need to include in my project, but I don't wish to install it to the local repository. What I did initially was to put the jar into version control in my project's lib/ folder, and then specify the Maven dependency as: <!-- LOCAL DEPENDENCY --> <dependency> <groupId>topsecret</groupId> <artifactId>proprietary</artifactId> <version>0.0.1</version> <scope>system</scope> <systemPath>${basedir}/lib/java/proprietary.jar</systemPath> </dependency> However, this becomes a big problem when my project becomes someone else's dependency. Maven will not be able to validate this POM because the path is not absolute. What is the best way to overcome this problem?

    Read the article

  • Using reflection to find all linq2sql tables and ensure they match the database

    - by Jake Stevenson
    I'm trying to use reflection to automatically test that all my linq2sql entities match the test database. I thought I'd do this by getting all the classes that inherit from DataContext from my assembly: var contexttypes = Assembly.GetAssembly(typeof (BaseRepository<,>)).GetTypes().Where( t => t.IsSubclassOf(typeof(DataContext))); foreach (var contexttype in contexttypes) { var context = Activator.CreateInstance(contexttype); var tableProperties = type.GetProperties().Where(t=> t.PropertyType.Name == typeof(ITable<>).Name); foreach (var propertyInfo in tableProperties) { var table = (propertyInfo.GetValue(context, null)); } } So far so good, this loops through each ITable< in each datacontext in the project. If I debug the code, "table" is properly instantiated, and if I expand the results view in the debugger I can see actual data. BUT, I can't figure out how to get my code to actually query that table. I'd really like to just be able to do table.FirstOrDefault() to get the top row out of each table and make sure the SQL fetch doesn't fail. But I cant cast that table to be anything I can query. Any suggestions on how I can make this queryable? Just the ability to call .Count() would be enough for me to ensure the entities don't have anything that doesn't match the table columns.

    Read the article

  • Capture bitmap of window in isolation (Windows OS)?

    - by Jake Petroules
    I know there's a way to capture a bitmap of a window in Windows without anything that may be obscuring it (e.g. you have a window with a dialog in front, but the dialog is not captured as it would be if you did a simple pixel grab), but I can't remember how to do so. Also I believe this is only possible in Windows Vista and above, with the introduction of the compositing window manager?

    Read the article

  • Not allowing characters after Space. Mysql Insert With PHP

    - by Jake
    Ok so I think this is easy but I dont know (I'm a novice to PHP and MySQL). I have a select that is getting data from a table in the database. I am simply taking whatever options the user selects and putting it into a separate table with a php mysql insert statement. But I am having a problem. When I hit submit, everything is submitted properly except for any select options that have spaces don't submit after the first space. For example if the option was COMPUTER REPAIR, all that would get sent is COMPUTER. I will post code if needed, and any help would be greatly appreciated. Thanks! Ok here is my select code: <?php include("./config.php"); $query="SELECT id,name FROM category_names ORDER BY name"; $result = mysql_query ($query); echo"<div style='overflow:auto;width:100%'><label>Categories (Pick three that describe your business)</label><br/><select name='select1'><option value='0'>Please Select A Category</option>"; // printing the list box select command while($catinfo=mysql_fetch_array($result)){//Array or records stored in $nt echo "<option>$catinfo[name]</option><br/> "; } echo"</select></div>"; ?> And here is my insert code ( Just to let you know its got everything not just the select!) ?php require("./config.php"); $companyname = mysql_real_escape_string(addslashes(trim($_REQUEST['name']))); $phone = mysql_real_escape_string(addslashes($_REQUEST['phone'])); $zipcode = mysql_real_escape_string(addslashes($_REQUEST['zipcode'])); $city = mysql_real_escape_string(addslashes($_REQUEST['city'])); $description = mysql_real_escape_string(addslashes($_REQUEST['description'])); $website = mysql_real_escape_string(addslashes($_REQUEST['website'])); $address = mysql_real_escape_string(addslashes($_REQUEST['address'])); $other = mysql_real_escape_string(addslashes($_REQUEST['other'])); $payment = mysql_real_escape_string(addslashes($_REQUEST['payment'])); $products = mysql_real_escape_string(addslashes($_REQUEST['products'])); $email = mysql_real_escape_string(addslashes($_REQUEST['email'])); $select1 = mysql_real_escape_string(addslashes($_REQUEST['select1'])); $select2 = mysql_real_escape_string(addslashes($_REQUEST['select2'])); $select3 = mysql_real_escape_string(addslashes($_REQUEST['select3'])); $save=$_POST['save']; if(!empty($save)){ $sql="INSERT INTO gj (name, phone, city, zipcode, description, dateadded, website, address1, other2, payment_options, Products, email,cat1,cat2,cat3) VALUES ('$companyname','$phone','$city','$zipcode','$description',curdate(),'$website','$address','$other','$payment','$products','$email','$select1','$select2','$select3')"; if (!mysql_query($sql,$link)) { die('Error: ' . mysql_error()); } echo "<br/><h2><font color='green' style='font-size:15px'>1 business added</font></h2>"; mysql_close($link); } ?>

    Read the article

< Previous Page | 8 9 10 11 12 13 14 15  | Next Page >