Search Results

Search found 11277 results on 452 pages for 'jeff certain'.

Page 27/452 | < Previous Page | 23 24 25 26 27 28 29 30 31 32 33 34  | Next Page >

  • fastest way to check to see if a certain index in a linq statement is null

    - by tehdoommarine
    Basic Details I have a linq statement that grabs some records from a database and puts them in a System.Linq.Enumerable: var someRecords = someRepoAttachedToDatabase.Where(p=>true); Suppose this grabs tons (25k+) of records, and i need to perform operations on all of them. to speed things up, I have to decided to use paging and perform the operations needed in blocks of 100 instead of all of the records at the same time. The Question The line in question is the line where I count the number of records in the subset to see if we are on the last page; if the number of records in subset is less than the size of paging - then that means there are no more records left. What I would like to know is what is the fastest way to do this? Code in Question int pageSize = 100; bool moreData = true; int currentPage = 1; while (moreData) { var subsetOfRecords = someRecords.Skip((currentPage - 1) * pageSize).Take(pageSize); //this is also a System.Linq.Enumerable if (subsetOfRecords.Count() < pageSize){ moreData = false;} //line in question //do stuff to records in subset currentPage++; } Things I Have Considered subsetOfRecords.Count() < pageSize subsetOfRecords.ElementAt(pageSize - 1) == null (causes out of bounds exception - can catch exception and set moreData to false there) Converting subsetOfRecords to an array (converting someRecords to an array will not work due to the way subsetOfRecords is declared - but I am open to changing it) I'm sure there are plenty of other ideas that I have missed.

    Read the article

  • Calculate the number of ways to roll a certain number

    - by helloworld
    I'm a high school Computer Science student, and today I was given a problem to: Program Description: There is a belief among dice players that in throwing three dice a ten is easier to get than a nine. Can you write a program that proves or disproves this belief? Have the computer compute all the possible ways three dice can be thrown: 1 + 1 + 1, 1 + 1 + 2, 1 + 1 + 3, etc. Add up each of these possibilities and see how many give nine as the result and how many give ten. If more give ten, then the belief is proven. I quickly worked out a brute force solution, as such int sum,tens,nines; tens=nines=0; for(int i=1;i<=6;i++){ for(int j=1;j<=6;j++){ for(int k=1;k<=6;k++){ sum=i+j+k; //Ternary operators are fun! tens+=((sum==10)?1:0); nines+=((sum==9)?1:0); } } } System.out.println("There are "+tens+" ways to roll a 10"); System.out.println("There are "+nines+" ways to roll a 9"); Which works just fine, and a brute force solution is what the teacher wanted us to do. However, it doesn't scale, and I am trying to find a way to make an algorithm that can calculate the number of ways to roll n dice to get a specific number. Therefore, I started generating the number of ways to get each sum with n dice. With 1 die, there is obviously 1 solution for each. I then calculated, through brute force, the combinations with 2 and 3 dice. These are for two: There are 1 ways to roll a 2 There are 2 ways to roll a 3 There are 3 ways to roll a 4 There are 4 ways to roll a 5 There are 5 ways to roll a 6 There are 6 ways to roll a 7 There are 5 ways to roll a 8 There are 4 ways to roll a 9 There are 3 ways to roll a 10 There are 2 ways to roll a 11 There are 1 ways to roll a 12 Which looks straightforward enough; it can be calculated with a simple linear absolute value function. But then things start getting trickier. With 3: There are 1 ways to roll a 3 There are 3 ways to roll a 4 There are 6 ways to roll a 5 There are 10 ways to roll a 6 There are 15 ways to roll a 7 There are 21 ways to roll a 8 There are 25 ways to roll a 9 There are 27 ways to roll a 10 There are 27 ways to roll a 11 There are 25 ways to roll a 12 There are 21 ways to roll a 13 There are 15 ways to roll a 14 There are 10 ways to roll a 15 There are 6 ways to roll a 16 There are 3 ways to roll a 17 There are 1 ways to roll a 18 So I look at that, and I think: Cool, Triangular numbers! However, then I notice those pesky 25s and 27s. So it's obviously not triangular numbers, but still some polynomial expansion, since it's symmetric. So I take to Google, and I come across this page that goes into some detail about how to do this with math. It is fairly easy(albeit long) to find this using repeated derivatives or expansion, but it would be much harder to program that for me. I didn't quite understand the second and third answers, since I have never encountered that notation or those concepts in my math studies before. Could someone please explain how I could write a program to do this, or explain the solutions given on that page, for my own understanding of combinatorics? EDIT: I'm looking for a mathematical way to solve this, that gives an exact theoretical number, not by simulating dice

    Read the article

  • MACRO Question: Returning pointer to a certain value

    - by Andrei Ciobanu
    Is it possible to write a MACRO that has a type and a value as its input parameters (MACRO(type,value)), and returns a valid pointer to a location that holds the submitted value. This macro should perform like the following function, but in a more generic manner: int *val_to_ptr(int val){ int *r = NULL; r = nm_malloc(sizeof(*r)); *r = val; return r; } Where nm_malloc() is a failsafe malloc. The Macro usage should be compatible with this usage: printf("%d",*MACRO(int,5)); Is it possible to achieve that ?

    Read the article

  • is counter has certain value inside a class in python

    - by mazlor
    i am learning classes in python and when i was reading the documentation i found this example that i didn't understand : class MyClass: """A simple example class""" def __init__(self): self.data = [] i = 12345 def f(self): return 'hello world' then if we assign : x = MyClass() x.counter = 1 now if we implement while loop : while x.counter < 10: x.counter = x.counter * 2 so the value of x.counter will be : 16 while for example if we have a variable y : y = 1 while y < 1 : y = y *2 then if we look for the value of y we find it 1 so i don't know how is the value of counter became 16 . thanks

    Read the article

  • Always send certain values with an ajax request/post

    - by DZittersteyn
    I'm building a system that displays a list of user, and on selection of a user requests some form of password. These values are saved in a hidden field on the page, and need to be sent with every request as a form of authentication. (I'm aware of the MITM-vulnerability that lies herein, but it's a very low-key system, so security is not a large concern). Now I need to send these values with each and every request, to auth the currently 'logged in' user. I'd like to automate this, via ajaxSetup, however i'm running into some issues. My first try was: init_user_auth: function(){ $.ajaxSetup({ data: { 'user' : site_user.selected_user_id(), 'passcode': site_user.selected_user_pc(), 'barcode' : site_user.selected_user_bc() } }); }, However, as I should have known, this reads the values once, at the time of the call to ajaxSetup, and never rereads them. What I need is a way to actually call the functions every time an ajax-call is made. I'm currently trying to understand what is happening here: https://groups.google.com/forum/?fromgroups=#!topic/jquery-dev/OBcEfgvTJ9I, however through the flamewar and very low-level stuff going on there, I'm not exactly sure I get what is going on. Is this the way to proceed, or should I just face facts and manually add login-info to each ajax-call?

    Read the article

  • I can't access certain subkeys in an entry in the registry

    - by shifuimam
    I'm trying to get to HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\GameUX\, but the only subkey being returned in C# is MachineSettings - even though there are additional subkeys, including Games and several keys named for different user SIDs. How can I access these other keys? Even a standard user account can read the content of both Games and that account's own SID (when looking in regedit)...

    Read the article

  • How to have game audio loop at a certain point

    - by Essential
    I have a storm in my game, and so I've made an ambient audio file which slowly grows into a storm and rain fades in, which then becomes a loopable storm audio file. Here is how I've done it: // Play intro clip and merge into main loop var introTime = stormIntro.length; AudioSource.PlayClipAtPoint( stormIntro, Vector3.zero, 0.7 ); Invoke( "StormMusic", introTime ); The way I'm currently trying to do it is get the length of the storm_intro audio clip, play the clip, and then invoke storm_loop to begin after the length of the intro has completed. This kinda works, but not really because there's occasionally a gap between the two. So how can I do it so the transition is seamless?

    Read the article

  • relaunch app when it ends or when it prints out certain text (stdout)

    - by acidzombie24
    I have an app which acts almost like a daemon. Sometimes it quits on error and many times it prints an error msg then ask users to press any key to close. How can i relaunch the app when either case happens? I am more interested in the 2nd case. I can do this in c++, C# or python. The script is an old python that i dont want to change (a newer c# version is in the works but not stable)

    Read the article

  • WP: redirect users to a certain category using cookies

    - by kass
    Basically like cragslist. once you select city on craigslist, nexttime when you go to the site, it redirects you to the city you selected. What I want to achieve: When a person comes to the site and selects a particular category, the next time they come to the site (returning user) - the page will open up on that category section. I would think this would be fairly easy to do via setting a cookie when the visitor clicks on the category link (or when the category page loads). When they return the following time, the cookie is read and then the page redirects accordingly. Unfortunately my knowledge of PHP and cookies is limited, (hence my search for answers) so I need to ask if anyone can help me out! Anyone have any ideas? Thanks!

    Read the article

  • Skipping authorization for certain methods

    - by mathee
    Per the Agile Development book, I have an Admin MVC that controls how users log in. In ApplicationController, I have a before_filter that checks for authorization. So, this will check that the user has logged in for every page. The problem is that I want everyone to be able to access the new method, for example, in Users (that is, anyone should be able to create a new user -- naturally! Only admin users should have access to the other methods in UsersController such as edit, etc.). What's the best way to do that?

    Read the article

  • disallow certain url in robots.txt

    - by chrism
    We implemented a rating system on a site a while back that involves a link to a script. However, with the vast majority of ratings on the site at 3/5 and the ratings very even across 1-5 we're beginning to suspect that search engine crawlers etc. are getting through. The urls used look like this: http://www.thesite.com/path/to/the/page/rate?uid=abcdefghijk&value=3 When we started we add the following to our robots.txt: User-agent: * Disallow: /rate Is this incorrect or are googlebot and others simply ignoring our robots.txt?

    Read the article

  • Quickly generate junk data of certain size in Javascript

    - by user1357607
    I am writing an upload speed test in Javascript. I am using Jquery (and Ajax) to send chunks of data to a server in order to time how long it takes to get a response. This should, in theory give an estimation, of the upload speed. Of course to cater for different bandwidths of the user I sequentially upload larger and larger amounts of junk data until a threshold duration is reached. Currently I generate the junk data using the following function, however, it is very slow when generation megabytes of data. function generate_random_data(size){ var chars = "abcdefghijklmnopqrstuvwxyz"; var random_data = ""; for (var i = 0; i < size; i++){ var random_num = Math.floor(Math.random() * char.length); random_data = random_data + chars.substring(random_num,random_num+1); } return random_data; Really all I am doing is generating a chunk of bytes to send to the server, however, this is the only way I could find out how in Javascript. Any help would be appreciated.

    Read the article

  • matching certain numbers at the end of a string

    - by user697473
    I have a vector of strings: s <- c('abc1', 'abc2', 'abc3', 'abc11', 'abc12', 'abcde1', 'abcde2', 'abcde3', 'abcde11', 'abcde12', 'nonsense') I would like a regular expression to match only the strings that begin with abc and end with 3, 11, or 12. In other words, the regex has to exclude abc1 but not abc11, abc2 but not abc12, and so on. I thought that this would be easy to do with lookahead assertions, but I haven't found a way. Is there one? EDIT: Thanks to posters below for pointing out a serious ambiguity in the original post. In reality, I have many strings. They all end in digits: some in 0, some in 9, some in the digits in between. I am looking for a regex that will match all strings except those that end with a letter followed by a 1 or a 2. (The regex should also match only those strings that start with abc, but that's an easy problem.) I tried to use negative lookahead assertions to create such a regex. But I didn't have any success.

    Read the article

  • Mercurial Merging only certain changesets

    - by PostMan
    Ok, so we recently converted from SVN to Mercurial. We are using TortoiseHG normally. In our one repository we have all of our projects, C++ / .NET / ASP. We have about 100 projects, all using common library projects. So it would be quite difficult task to create multiple repo's for each project. Now, we have the default branch, and let's say branchA. I'm working on BranchA and adding my uber changes to it, and I change a common library, let's say an extension method I want to commit this to branchA and default, how would I go about this? However, I don't want all my changes from branchA to be merged into default, and I don't want all the other changes from default Hopefully this is sufficient information!

    Read the article

  • Find fields with certain characters

    - by Kemo
    I'm trying to SELECT fields with multiple dots ( . ) in their value. Exactly, I'm trying to find fields with a subdomain as an entry in domain column, e.g.; SELECT * FROM domains WHERE ( number of dots in domain value bigger than 1 ). Any suggestions ?

    Read the article

  • Getting certain rows from list of rows(C#3.0)

    - by Newbie
    I have a datatable having 44 rows. I have converted that to list and want to take the rows from 4th row till the last(i.e. 44th). I have the below program IEnumerable<DataRow> lstDr = dt.AsEnumerable().Skip(4).Take(dt.Rows.Count); But the output is Enumeration yielded no results I am using c#3.0 Please help.

    Read the article

  • C++: Is there a way to limit access to certain methods to certain classes without exposing other pri

    - by dadads
    I have a class with a protected method Zig::punt() and I only want it to be accessible to the class "Avocado". In C++, you'll normally do this using the "friend Avocado" specifier, but this will cause all of the other variables to become accessible to "Avocado" class; I don't want this because this breaks encapsulation. Is what I want impossible, or does there already exist an obscure trick out there that I can use to achieve what I want? Or possibly alternative class design patterns that'll achieve the same thing? Thanks in advance for any ideas!

    Read the article

  • Search for all instances of certain annotation type

    - by user1064918
    Suppose I have this annotation @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Name { String value(); } This is going to be used as follows @Name("name1") public static Foo foo = new Foo(); I have multiples of these across my project source files. Is there an fairly simple way to search and collect all those "foo"s that're preceded by @Name? In other words, I'd like to write a method that would return a Set<Foo> containing these. Thanks!!!

    Read the article

< Previous Page | 23 24 25 26 27 28 29 30 31 32 33 34  | Next Page >