logic

Compressing big number (or string) to small value

Friends, Here is the situation: An ASP.NET page has following query string parameter. MyServer.com/ShowSomething.aspx?IDs=1000000012,1000000021,1000000013,1000000022&... Here IDs parameter will always have numbers separated by something, in this case ",". Currently there are 4 numbers but normally they would be in between 3-7. Now, I...

PHP - Need Help With Logic

Hello all, I'm currently working on a PHP/MySQL script that does the following, in this order: 1) Checks DB for any videos that need converting 2) Once determined that a video needs to be converted, it begins to convert *3) Notifies the "creator" of video that it's been created. *4) Notifies all users who are "receivers" of the video,...

PHP Pagination, MySQL LIMIT problem

As some of you may know, use of the LIMIT keyword in MySQL does not preclude it from reading the preceding records. For example: SELECT * FROM my_table LIMIT 10000, 20; Means that MySQL will still read the first 10000 records and throw them away before producing the 20 we are after. So, when paginating a large dataset, high page num...

Scheduling Script with PHP/MySQL - Help with Logic

Hello all, I'm looking to develop a small script where users can insert their "schedule." However, I need some help determining the logic of how to create the DB structure and how to input the "time" of the events in the database. One thing to note, however, is that when users enter their "schedule", they will not be entering exact da...

Combinator logic axioms

I'm carrying out some experiments in theorem proving with combinator logic, which is looking promising, but there's one stumbling block: it has been pointed out that in combinator logic it is true that e.g. I = SKK but this is not a theorem, it has to be added as an axiom. Does anyone know of a complete list of the axioms that need to be...

jQuery password strength checker

I'm quite new to jQuery, and I've written a simple function to check the strength of a password for each keypress. The idea is that every time a user enters a character, the contents is evaluated to test the strengh of the password they have entered... I'm sure everyone has seen these before. Anyhow, the logic I have used is that no pa...

PHP Detect how many URLS in the string

I'm implementing a contact form for a website, and I'd like to avoid using a captcha because I believe it has a negative effect on user experience. Instead, I've decided to trial detecting the number of URLs that have been submitted with the message. I am retrieving the message as a string from the $_POST submission. I know inbuilt PH...

What can be the efficient approach to solve the 8 puzzle problem?

The 8-puzzle is a square board with 9 positions, filled by 8 numbered tiles and one gap. At any point, a tile adjacent to the gap can be moved into the gap, creating a new gap position. In other words the gap can be swapped with an adjacent (horizontally and vertically) tile. The objective in the game is to begin with an arbitrary config...

Points system like stackoverflow

Hello, I am trying to create a point system in my program similar to stack overflow i.e. when the user does some good deed (activity) his/her points are increased. I am wondering what is the best way to go about implementing this in terms of db schema + logic. I can think of three options: Add an extra field called points in the user...

jQuery sort by rating (desc) and hide divs based on value

Hello, I am trying to achieve the following. I have a dozen divs with something like: <div id=1><div>test 1</div><div>4</div></div> <div id=2><div>test2</div><div>1</div></div> <div id=3><div>test3</div><div>6</div></div> <div id=4><div>test4</div><div>3</div></div> <div id=5><div>test5</div><div>2</div></div> <div id=6><div>test6<...

How do you replicate an array whilst keeping the same keys?

Ok. I've written a simple(ish) function to take an argument and return the same argument with the danger html characters replaced with their character entities. The function can take as an argument either a string, an array or a 2D array - 3d arrays or more are not supported. The function is as follows: public function html_safe($inp...

PHP, alternating weeks logic

I need to write some code in PHP that performs an action only on alternating weeks, based on the day of the week (mon, tue etc) rather than the number (1st, 7th etc). So on a cycle starting on a Monday it should run for one week then not the following week. I am sure this must be easier than I think but can't seem to work it out, so h...

return variable approach

Ok I have ten variables but one needs to be set, but I need to check for each of the values until one is set. I'm doing a SWITCH/CASE statement but I'm not sure if this is the best approach because I don't see how I can return only the variable that I need set. $passed_var = 'A'; // Static $var_array = getSelectedVar($passed_var); for...

Using Boolean operators

This works fine if ((a >= 40 && a <= 50) || (a >= 60 && a <= 80)) // do something How do I do the reverse of it? if ((a < 40 && a > 50) || (a < 60 && a > 80)) // do something The code does not work as expected. I want something like if not (condition) ...

Methodologies for Change-Proof Development in Agile Environment

Hi, I am wondering whether there is any methodology to design the program logic which is agile-proof. Currently for example I am developing an application for video recording and uploading. At the beginning it was planned just to enable the user to select the stored recordings from the library and edit title or upload the selected vide...

Anybody know of a good logic layout application?

I don't know exactly what to call this kind of application, but I'm looking for a good program that'll allow me to layout and test logical circuits. Something that has ands, ors, xors, nots, transistors, and all the basic logical components. Something kind of like UML except with basic electrical components. Something that could generate...

Validating Timestamp overlaps with PHP

Hello all. My database holds date, start and end variables. In my code I grab the start and them as the user selects them, and convert them to timestamps like so (all inside a foreach loop).. $selectionDate = strtotime($timeQry['date']); $startTimes[] = strtotime($timeQry['start'],$selectionDate); $endTimes[] = strtotim...

power function in prolog.

What is wrong with my power function? pow(_,0,1). pow(X,Y,Z) :- pow(X,Y-1,X*Z). ?- pow(2,3,Z). ERROR: Out of global stack ...

Request-Response logic

public function run() { /* * wrap uri in a decorator */ $uri = new URI(trim(str_replace($this->base_path, "", $_SERVER["REQUEST_URI"]), "/")); /* * fetch appropriate resource from uri */ $this->resource = new Resource($uri); /* * prepare the request */ $request = new Request; /* * get the response of the app base...

Count up and down elegantly

I'm trying to make a flashing object, i.e., increment it's alpha value from 0 to 255 (gradually) and then back down to 0, and repeat. Is there a way I can do this without using some boolean? Getting it to increment is easy: alpha = time.elapsed()%256; But what's a nice way to get it to count back down again after that? ...