I want to embed in a page a detailed structure report of my model objects, like print_r() or var_export() produce (now I’m doing this with running var_export() on get_object_vars()). But what I actually want to see is only some properties (in most cases), but at this moment I have to use Ctrl+F and seek the variable I want, instead of just staring at it right after the page completes loading. So I’m embedding buttons to show/hide large arrays etc. but thought: ‘What if there already is the thing I do right now?’ So is there?
Update:
What would your ideal interface look like?
First of all, dumped models fit in the first screen. All the properties can be seen at the first look at the screen (there are not many of them, around 10 per each, three models total, so it is possible). Small arrays can be shown unrolled too. Let the size of the array to count it as ‘small’ be definable. Ideally, the user can see values of the properties without doing any click, scrolling the screen or typing something.
There must be some improvements to representing the values, say, if an array is empty, show
array ‘My_big_array’ is empty
and if a boolean variable starting with is_, has_, had_ has a false as the value, make the variable (let us take is_available for example) shown as
is_NOT_available
in red, and if it has true as the value, show
is_available
in green. Without any value shown. The same goes for defined constants.
That would be ideal.
I want to make focus on this kind of switches.
Krumo seems useful, but since it always closes up the variable without making difference of how large it is, I cannot use it as is, but there might appear something similar on github soon :)
Second update starts here:
Any programmer who sees is_available = false will know what it means, no need to do more
Bringing in color indication I forgot about one thing: the ‘switches’ let’s call them so, may me important or not. So I have right now some of them that will show in green or red, this is for something global, like caching, which is shown as
Caching is… ON
with ‘ON’ written in green, (and ‘OFF’ in red when disabled) while the words about what it is, i.e. ‘Caching is… ’ are written in black.
And some which are not so important, for example I haven’t defined
REVEAL_TIES is… not set
with ‘not set’ written in gray, while the words describing what it is stay in black. And if it would be set the whole phrase would be in black since there is nothing important: if this small utility for showing some undercover things is working, I will see some messages after it, if it isn’t — site will be working independently of its state.
Dividing switches into important ones and not with corresponding color match should improve readability, especially for those users who are not programmers and just enabled debug mode because some guy from bugzilla said do that — for them it would help to understand what is important and what is not.
A big thanks to all who replied.
Related
I'm hoping to solve this in pure html. I suspect a solution may not exist, and I'm willing to learn a PHP solution. If that doesn't exist either, I'll learn whatever language I must.
Take the following form for example
<form>
Price $<input type="number" name="price"><br>
</form>
It may not immediately be obvious to the user that this field accepts cents as well as dollars. (By, for example, typing 1.1 for $1.10.)
The same issue will come up when I ask a customer how many kilograms they wish to order, it won't immediately be obvious to them that they can order 100 grams by typing "0.1"
What I would like is for the field to start as ".00" with the curser appearing on the left when clicked, but as soon as the user types "." it will overwrite the existing ".". When the user types further numbers, the first two digits should overwrite the existing 0s, and further digits will be disabled.
This way, the user will be prompted to consider if they want to specify a certain number of cents (for a price) or grams (for a weight) without a condescending text field explaining what a decimal point is.
Does a html solution exist? If not, what other solutions exist? (I don't know ANY solutions.)
Example
There seems to be some confusion among my answers as to what I'm asking for, so I created a quick and dirty example:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form>
<br><br><br>
Price $<input style="text-align:right" type="number" name="price" value=".00">
</form>
</body>
</html>
(I know, style attribute inside a tag, I'm going to hell to burn for eternity.)
Using this, and photoshop, I created a simulation of the functionality I wanted, comic book style.
As shown, I already know how to get the initial state. I thought this might be possible with one quick piece of code, but if it can't, I have broken the question down into its core components below:
How do I move the cursor to a in front of the decimal point when the user clicks to the right of the decimal point?
How do I make the text overwrite the initial decimal point with a new decimal point, and have it continue to overwrite?
How do I disallow extra decimal points?
How do I disallow the user from writing more than a predetermined number of digits? (two, in the example shown above)
How do I automatically replace characters deleted (by backspace for example) with a 0?
Up-votes to anyone who can answer at least one of the questions above, or at least reveals a valuable insight towards answering one of the questions above.
Sorry, this question is getting more complex than I initially thought it was.
Update
I'm beginning to expect a PHP solution doesn't exist either. I'm still quite new to coding, so I could be completely wrong, but this is why:
PHP is a server side language, and this task requires live instantaneous functionality on the client's end without waiting for a server to validate their request to delete a decimal point.
This functionality is too specific and advanced for html and CSS. Therefore, it must be achieved through something else. I'll still leave this question up here, in case anyone wants to have a stab at the answer, but my knowledge of other languages (like JavaScript) isn't quite advanced enough to compile individual core component answers into one final functional answer... yet.
So I'm going to busy myself updating my website using the skills I have for the tasks that require doing. Even when I'm ready to learn a new language, this is too advanced a problem to tackle straight away. But, when I'm learning new functions, if I discover something that will solve this problem, I'll post the full code back here for the community to reference in future.
I am using Sublime Text 3 as a PHP editor, I've been customizing the PHP.tmLanguage file to include more syntax scopes, right now I cannot figure out how to capture class method invocations.
$html = new HTML("hr");
$html->output_ml("moo");
output_ml is currently declared as scope variable.other.property.php
I would like to add a scope to pertain to specifically to class method calls, but I am having trouble defining the regex in the tmLanguage file.
I've tried
<dict>
<key>match</key>
<string>(?i)\$[a-z_][a-z0-9_]*->([a-z_][a-z_0-9]*)\s*\(</string>
<key>name</key>
<string>meta.method-call.php</string>
</dict>
You were pretty close, I just tweaked a few things:
(?i:(?!\$[a-z_][a-z0-9_]*->)([a-z_][a-z_0-9]*)\s*\()
First thing I did was wrap the entire expression in the "case-insensitive" modifier, just so nothing got missed. Probably not necessary, but whatever. Second, and more importantly, I took your first group that was outside of parentheses, and made them a negative lookahead. This way, they match the class name and the arrow, but don't report it - basically saying "match whatever is ahead of us as long as we exist in front of it, but don't match us."
Now, you'll have a scope that matches just the method's name.
Demo
Now, here's what I don't get - why you should have to do this. I maintain both a language syntax and a color scheme, so I have a lot of experience with scoping in Sublime Text and TextMate. And to my knowledge, the PHP .tmLanguage already includes scopes for function calls. I'm not a PHP expert by any means, but I know the basics, so I made three examples of different PHP function calls:
Green highlights a large variety of function calls in different languages. In the top example, baz_quux is scoped as meta.function-call.object.php, in the middle example it's meta.function-call.static.php, and in the bottom it's just meta.function-call.php. I don't understand where you're getting variable.other.property.php from.
However, if I take away the parentheses after the function calls above:
I get the following scopes, from top down: variable.other.property.php (aha!), constant.other.class.php, and constant.other.php. If I put the parens back, and add a space or three after the end of the function name, they are still highlighted as functions, in green.
So, while we had some fun with regexes today, ultimately your work has already been done for you. If you're going to be doing more scope-hunting, I highly recommend the ScopeAlways plugin, which, like its name implies, always lists the full scope of the current cursor position in the bottom bar (you can turn it off via the Command Palette if you want). If I get a request to expand my color scheme's highlighting to a new language, I just open up as much code as I can find and poke around with my mouse, looking at the different scopes, then editing my theme to correct colors as needed, or add new ones for brand-new scopes. I then scan through the .tmLanguage file (after converting it to YAML) and see if I missed anything.
Good luck with your work!
I'm building a web application in PHP, and part of the requirement is that I need to be able to quickly process data on a scanned copy of a fairly simple form, and save it to a database for later retrieval.
Given the following image
how can I identify and assign a database field a value of either true or false (true when it sees a tick, and false otherwise)?
I'm thinking along the following line of implementation:
I will keep two copies of the above image - the first will have ticks shown (as above), and the second will be a "clean" copy of the image with the borders left behind. Comparing between the two images will yield a difference; the difference will return either a value of true or false.
There are drawbacks as far as I can observe of the above implementation. What happens if the user scribbles something in it (as seen above) but it does not mean anything? How do I even ensure that the returned values of true or false are assigned to the appropriate columns in the database?
I don't have any code implementation at this point in time, and I'm not asking for it. Rather, I'm asking for guidance on where to look and how I can efficiently do this.
You may try using OpenCV framework for PHP (https://github.com/mgdm/OpenCV-for-PHP, http://mgdm.net/talks/confoo11/making-php-see.pdf) and use contour detection (or any other classificators) to find signs like "V" and skip false-positives.
You might want to use a PHP OCR library.
I will do thin in a following way: I will divide image into 2x6 grid and count black pixels in each row. If the number n contains in <A;B> then we can assume that row is checked. If someone scratch off an answer then n is larger than B.
So if n is in <A;B> range we can check its pattern - for example common part of the all marked rows because of user's handwriting.
I run a photo website where users are free to enter any tag they like, even tags not used before. As a result, a photo of a tag may sometimes be tagged as "insect" whilst somebody else tags it as "insects".
I'd like to keep the free-tagging capability, yet would like to have a way to filter out such near-duplicates. The total collection of tags is currently at 1,500. My idea is to read all of them from the DB into mem and then run an alghoritm on it that displays "suspects".
My idea of a suspect is that x% of the characters in the string are the same (same char and order), where x is configurable. I could probably code a really inefficient way to do this but I was wondering if there is an existing solution to this problem?
Edit: Forgot to mention: just sorting the tags isn't enough, as that would require me to go through the entire set to find dupes.
There are some flaws in your logic. For example, what happens when the plural of an object is different from the singular (i.e. person vs. people or even candy vs. candies).
If English is the primary language, check out Soundex which allows phonetic matches. Also consider using a crowd-sourced synonym model where users can create links to existing tags.
Maybe the algorithm you are looking for is approximate string matching.
http://en.wikipedia.org/wiki/Approximate_string_matching.
by a given word you can match it to list of words and if the 'distance' is close add it to suspects.
A fast implementation is to use dynamic programming like the Needleman–Wunsch algorithm.
I have made a blog example of this in C# where you can configure the 'distance' using a matrix character lookup file.
http://kunuk.wordpress.com/2010/10/17/dynamic-programming-example-with-c-using-needleman-wunsch-algorithm/
Is "either contains either" fine? You could do a SQL query something like this, if your images are in a database (which would only make sense):
SELECT * FROM ImageTags WHERE INSTR('theNewTag', TagName) > 0 OR INSTR(TagName, 'theNewTag') > 0 LIMIT 1;
If you really want to do this efficiently I would suggest some sort of JavaScript implementation that displays possibilities as the user is typing in a tag that they want. Not only will it save the user time to happily see 5 suggestions as they type. It will automatically stop them from typing "suspects" when "suspect" shows up as a suggestion. That is, of course, unless they really want "suspects" as a point of urgency.
You could load a huge list of words and as the user types narrow them down. I get the feeling that this could be very simplistic esp if you want to anticipate correctly spelled words. If someone misses a letter, they'll probably go back to fix it when they see a list of suggestions that isn't at all what they meant to type. And when they do correctly type a word it'll pop up in the suggestions.
Does anyone know a clever way to create even columns of text using php?
So lets say I have a few paragraphs of text and I want to split this into two columns of even length (not string length, I'm talking even visible length).
At the moment I'm splitting based on word count, which (as you can imagine) isn't working too well. For instance, on one page I have a list (ul li style) which is increasing the line breaks but not the word count. eg: whats happening is that the left column (with the list in it) is visibly longer than the right column (and if there was a list in the right hand column then it would be the same the other way round).
So does anyone have a clever way to split text? For instance using my knowledge of objective c there is a "size that fits" function. I know how wide the columns are going to be, so is there any way to take that, and the string, and work out how high its going to be? Then cut it in half? Or similar?
Thanks
ps: no css3 nonsense please, we're targeting browsers as far back as ie6 (shudder). :)
I know you're looking at a PHP solution but since the number of lines will depend on how it's rendered in the browser, you'll need to use some javascript.
You basically need to know the dimensions of the container the text is in and using the height divided by the text's line-height, you'll get the number of lines.
Here's a fiddle using jQuery: http://jsfiddle.net/bh8ZR/
There is not a lot of information here as to the source data. However, if you know that you have 20 lines of data, and want to split it, why not simply use an array of the display lines, then divide by two. Then you can take the first half of the PHP array and push it into the second column when you hit the limit of the first.
I think you're going to have trouble displaying these columns in a web browser and having a consistent look and feel because you're trying to apply simple programming logic to a visual layout. CSS and jQuery were designed to help layout issues. jQuery does have IE6 compatibility.
I really don't think you're going to find a magic bullet here if you have HTML formatting inside the data you're trying to display. The browser is going to render this based on a lot of variables. Page width, font size, etc. This is exactly why CSS and other layout styles are there, to handle this sort of formatting.
Is there any reason why you're not trying to solve this in the browser instead of PHP? IE6 to me is not a strong enough case not to do this where it belongs.