logic

Time comparison trouble with Rails

I have a very simple task at hand. If the last time a record was updated has been longer than 15 minutes, display a button. Otherwise, don't display the button. The field is a datetime. My view code: <% if @object.display_button? -%> my button <% end -%> My display button method on that object: def display_button? return fals...

How to provide multiple search functionality in website???

I am developing a web application, in which I have the following type of search functionality; Normal search: where user will enter the search keyword to search the records. Popular: this is no a kind of search, it will display the popular records on the website, something as digg and other social bookmarking sites does. Recent: In thi...

Google Checkout : Best way to handle cart editing and checkout confirmation

Hello all, I am in the process of implementing Google Checkout in an e-store. Once customers click the 'Google Checkout' button, my project requires that they are able to navigate back to the e-store to possibly edit the cart. Customers should be able to click the 'back' button, type in the URL to my cart page, or click the 'edit' link ...

Are there any tools to aid with complex 'if' logic?

One of my personal programming demons has always been complex logic that needs to be controlled by if statements (or similiar). Not always necessarily that complex either, sometimes just a few states that needs to be accounted for. Are there any tools or steps a developer can perform during design time to help see the 'states' and take ...

Caching query results in ORMs - satisfying arbitrary subset queries

I know N/Hibernate uses a cache to satisfy queries that it has seen before, and that is called a query cache. However, can it satisfy a subset of that query? I'd imagine not since I'd guess that the general problem of figuring that out is undecidable. Are there any strategies for doing this, though? Say I have a query for all widgets wh...

PHP: Creating a psuedo-join method inside an object

I am trying to create an object that is capable of handling query-like conditional statements. This is so I can 'join' two conditions together to create a dependency between them based on the type of 'join' being used. I currently have a simple object that contains the following methods: public function addCondition ( Condition $conditi...

Godel, Escher, Bach Typographical Number Theory (TNT) puzzles and solutions

In chapter 8 of Godel, Escher, Bach by Douglas Hofstader, the reader is challenged to translate these 2 statements into TNT: "b is a power of 2" and "b is a power of 10" Are following answers correct?: (Assuming '∃' to mean 'there exists a number'): ∃x:(x.x = b) i.e. "there exists a number 'x' such that x multiplied x equals b" I...

How to locate a particular exception in a Exception stack

Let us assume that a particular Exception "SomeException" is part of the exception stack, so let us assume ex.InnerException.InnerException.InnerException is of type "SomeException" Is there any built-in API in C# which will try to locate a given exception type in exception stack? Example: SomeException someExp = exp.LocateExceptionI...

How to reduce a logical statement?

I'm pretty sure I can remember doing something like this in one of my college level courses and that there was some kind of formula to it, but my mind is failing me beyond that. Given the statement: ( a OR b OR d ) AND ( a OR c ) I'm pretty sure that this can be reduced to: ( a OR b OR d OR c ) But I cannot remember how I would go abo...

How could I implement logical implication with bitwise or other efficient code in C?

I want to implement a logical operation that works as efficient as possible. I need this truth table: p q p → q T T T T F F F T T F F T This, according to wikipedia is called "logical implication" I've been long trying to figure out how to make this with bitwise operations in C without using cond...

Logic design pattern

In a game, many entities should be updated every frame. Im toying with different design patterns to achieve this. Up until now, Ive had a singleton manager class to which every Logic instance is added. But Im considering the following, a static list in the Logic class itself. This is nice since it would remove a class from the project. "...

The ternary operator and if A, B, else C. Are there any important differences?

There are a few ways to do this in javascript. Foremost and most readable and flexible is probably: if (a){ //b } else { //c } Something else that only* works with assigning and is less readable is: var foo = 'c'; if (a){ foo = 'b'; } My main question, though, is about the last two methods I can think of: var foo = a ...

Game logic issue

Hi, i am making a noughts and crosses game (tic tac toe) and in my logic class i represent the state of the game with a 2d array, but this is the problem, im checking the array like so if(gameModel[0][0] == gameModel[1][1] && gameModel[0][0] == gameModel[2][2]){ return true; } if(gameModel[2][0] == gameModel[1][1] && gameMod...

How to determine if a date range occurs any time within another date range?

I have an Event table that specifies a date range with start_date and end_date fields. I have another date range, specified in code, that defines the current week as 'week_start' and 'week_end'. I'd like to query all Events for the week. The cases seem to be: Event begins and ends within the week Event begins before the week, but en...

Trying to understand the MD5 algorithm

Hey! I am trying to do something in C with the MD5 (and latter trying to do something with the SHA1 algorithm). My main problem is that I never really did anything complex in C, just simple stuff (nothing like pointers to pointers or structs). I got the md5 algorithm here. I included the files md5.c and md5.h in my C project (using cod...

Logic in a regular expression...

Hi all, I'm putting together some regexps to handle redirecting incoming links from an old site to the equivalent page on the new site. I'm hoping I can handle the following situation in the regexp so I don't have to do it on the back-end: Incoming link: /reservations/inn_details.asp?num=717 Redirected link: /reservations/property-de...

How do I write Ax ( P(x) and Q(x) ) in Coq?

I'm trying out Coq, but I'm not completely sure what I'm doing. Is: Theorem new_theorem : forall x, P:Prop /\ Q:Prop Equivalent to: Ax ( P(x) and Q(x) ) (where A is supposed to be the universal quantifier). Edit: I think they are. ...

How to convert an equation into formulas for individual variables?

How to convert an equation into formulas for individual variables? I am thinking about a math equations like: c^2 = a^2 + b^2 I would like to have a function that could process any formula, and give me the individual variable formulas. The above equation would produce the following: a = (c^2 - b^2)^0.5 b = (c^2 - a^2)^0.5 c = (a^2 +...

SQL function question

Hi, having trouble coming up with search parameters for this issue, so I can't find an answer on my own. Column X | Message (info 1) | Message (info 2) (info 1) | Above is the contents of one column I need to handle. The result of the query should be the part INSIDE the parentheses only. Problem is,...

Shared Domain Logic?

Take for example: CreateOrderTicket(ByVal items As List(Of OrderItems)) As String Where would you put this sort of logic given: CreateOrder should generate a simple list ( i.e. Item Name - Item Price ) PizzaOrderItem SaladBarOrderItem BarOrderItem Would you recommend: Refactoring common to an abstract class/interface with shared pr...