Limit the number of lines in XSLT item |
But I want it to show only the first five lines never mind what the width
of the div is, so characters limitation will not work here.
You're not alone. Here are some similar questions:
Is it possible to detect when text wraps?
Finding line-wraps
Controlling ellipsis style in CSS
Multi-line text-overflow:ellipsis in CSS or JS, with img tags
Defining minimum available height before floating divs?
Good luck.
References
Yes, SOFT HYPHEN is a hard problem
Unicode Line Breaking Algorithm
|
Limit number of lines in text by a regular expression |
I don't see why this would need any kind of lookaround. Just match only
lines that contain foo:
(?:
?[^
]*foo[^
]*){3}
Notice that with the optional
this might as well match a line that contains foo three times. To avoid
that, use
(?:(?:^|
)[^
]*foo[^
]*){3}
// or
(?:[^
]*foo[^
]*(?:
|$)){3}
(depending on your regex flavour you might use different anchors for string
beginning/end)
If you need foo standing on it's own, just add word boundaries to it:
(?:
?[^
]*foo[^
]*){3}
|
Extract the last 50 lines from an NSAttributedString |
You can use substring method of AttributedString:
if ([resultString length]>50) {
resultString = [resultString attributedSubstringFromRange:NSMakeRange(0,
50)];
}
NSMakeRange - 0 tells us where to start and 50 is length of substring
|
Equal spacing between lines of NSAttributedString with multiple font sizes for a UILabel in iOS 6 |
I have been doing something similar, so maybe you could try something like
this (typed in browser, watch out!):
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
[style setAlignment: NSTextAlignmentRight];
[style setLineSpacing:0];
for(NSString *line in linesArray) {
NSMutableParagraphStyle *subStyle = [style mutableCopy];
[subStyle setMaximumLineHeight:10]; // play around with this value
<-----
NSDictionary *attributes =
@{
NSFontAttributeName : [UIFont fontWithName:@"TimesNewRomanPSMT"
size:fontSize],
NSParagraphStyleAttributeName : paragraphStyle,
};
[attString appendAttributedString:[[NSAttributedString alloc]
initWithString:line attributes: attributes]];
fontSize += 10.0;
}
|
Git total number of deleted lines and added lines for complete log |
Find the hash of the first-commit-after-big-migration, or add a tag to it,
and use it in your git log command :
$ git log --numstat --pretty --oneline 0f5d22e..HEAD -- <filename> |
awk ...
|
Replace lines by line number with lines from other file |
One way with awk:
$ match="second textblock"
$ awk 'NR==FNR&&!p;$0~m{print p;p=1};NR>FNR&&FNR>1'
m="$match" file1 file2
first
text
block
#blank line
second textblock
all #blank line
the
other
lines
#blank line
|
Trying to get file with max lines to print with lines number |
you can try:
wc -l $1/* | grep -v total | sort -g | tail -1
actually to avoid the grep that would also remove files containing "total":
for f in $1/*; do wc -l $f; done | sort -g | tail -1
or even better, as suggested in comments:
wc -l $1/* | sort -rg | sed -n '2p'
you can even make it a function:
function get_biggest_file() {
wc -l $* | sort -rg | sed -n '2p'
}
% ls -l
... 0 Jun 12 17:33 a
... 0 Jun 12 17:33 b
... 0 Jun 12 17:33 c
... 0 Jun 12 17:33 d
... 25 Jun 12 17:33 total
% get_biggest_file ./*
5 total
EDIT2: using the function I gave, you can simply output what you need as
follows:
get_biggest $1/* | awk '{print "The file "" $2 "" has the maximum number of
lines: " $1}'
EDIT: if you tried to write the function as you've written it in the
question, you should
|
An algorithm to find number of numbers in a given limit 'l' (0 <= l <= 10^16) with atleast one occurence of a single digit number 'n'? |
Assuming you mean 0 <= l < 10^16 (not <= 10^16), all integers in
this range have 10 digits (allowing for leading 0s). There are 10^16 total
values in this range. I'd write the problem as:
Number with digit n = 10^16 - number WITHOUT digit n.
So how many ways can we not choose n in the 1's place? 9 ways. How many
ways can we not put an 'n' in the 10s OR 1's place? 9*9. Following this
logic, there are 9^16 ways of not putting an n in any of the 16 possible
slots.
So your answer is 10^16 - 9^16.
If you actually meant 0 <= l <= 16, that range has only one more
number, namely 10^16. The leading digit of this number is 1, so if n = 1
you have exactly 10^16 - 9^16 + 1 values with a 1 in it. If n != 1 then
the previous answer holds.
|
mysql LIMIT lines with a GROUP BY operand |
I don't think there is a straightforward single query solution to what you
are looking for, but depending on your data size and what you know up front
about the domain there are a few options.
First of all, you could use find_each instead which would still iterate
over your complete set, but it would avoid loading all 8000 into memory.
That would look like this:
grouped_mymodels = {}
all_mymodels = MyModel.find_each do |model|
grouped_models[model.category_id] ||= []
next if grouped_models[model.category_id] > 10
grouped_models[model.category_id] << model
end
Otherwise, I think you'd need to run more than one find operation to get
the top ten records for each category.
If you only need some of the data from the model you could look at using
GROUP_CONCAT or something el
|
Substitute `number` with `(number)` in multiple lines |
Let me address those in reverse.
First: there's no difference between :s/foo/bar and :s:foo:bar; whatever
delimiter you use after the s, vim will expect you to use from then on.
This can be nice if you have a substitution involving lots of slashes, for
instance.
For the first: to do this to the first number on the current line (assuming
no commas, decimal places, etc), you could do
:s:(d+):(1)
The (...) doesn't change what is matched - rather, it tells vim to remember
whatever matched what is inside, and store it. The first (...) is stored
in 1, the second in 2, etc. So, when you do the replacement, you can
reference 1 to get the number back.
If you want to change ALL numbers on the current line, change it to
:s:(d+):(1):g
If you want to change ALL numbers on ALL lines, change i
|
Java - limit number between min and max |
You do not need an external library for this, try this test case:
public class RandomNumber {
public static void main(String[] Args) {
System.out.println("random = " + randomInRange(5,10));
}
public static double randomInRange(double arg1, double arg2) {
double my_number = Math.ceil(Math.random() * (arg1 - arg2) + arg2);
return my_number;
}
}
|
Limit the number of pages |
I suppose you can override mpdf class addPage method, and if the number of
pages is more then you want, generate EnoughPagesException, catch it up in
your code, and there you have the mpdf object with the number of pages you
need.
|
Limit number of column |
<table>
<tr>
<?php
$count = 5;
while($report && !$report ->EOF && $count >
0) {
echo "<td>$name</td>";
$report ->MoveNext();
$count--;
}
?>
</tr>
</table>
Just added a simple counter to the while loop. By increasing the count you
can make more columns appear
|
Limit number of '1' in a string using Regexp |
There are possibly better versions, but this seems to do the trick:
/^([^1]*1){1,5}[^1]*$/
Broken down:
^ - Start of string
[^1]*1 - Zero or more non-1 characters
1 - A '1'.
([^1]*1){1,5} - This pattern occurring between one and five times.
[^1]* - Zero or more non-1 characters
$ - End of string
|
Limit Number of Checkboxes Checked |
Try this:
jQuery(function(){
var max = 3;
var categories = jQuery('label'); // use better selector for categories
categories.each(function(){
var checkboxes = $(this).find('input[type="checkbox"]');
checkboxes.change(function(){
var current = checkboxes.filter(':checked').length;
checkboxes.filter(':not(:checked)').prop('disabled', current
>= max);
});
});
});
|
Is there anyway to limit the number of character in UITextfield to 5? |
Is the delegate being called? If YES, then just try this:
- (BOOL)textField:(UITextField *)textField
shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString
*)string {
if ([textField.text length] > 5) {
textField.text = [textField.text substringToIndex:5-1];
return NO;
}
return YES;
}
|
Limit the number of posts from Facebook API |
Since string.Format(appURL) contains a Graph API request USER_ID/feed, we
can add a field that specify the limit:
dynamic feed = _facebookClient.Get(string.Format(appURL) + "?limit=10");
You will find more information about LIMIT here.
|
Highcharts: limit number of markers |
AFAIK you can disable markers per point but you have to supply the data as
objects, which can be problematic with large quantities of points:
series: [{
data: [
{ y: 29.9 },
{ y: 71.5, marker: { enabled: false } },
{ y: 106.4, marker: { enabled: false } },
{ y: 129.2 }]
}]
Documentation here (see third item).
|
Limit the Number of Posts in Wordpress |
There are multiple ways of doing it. But the easiest is to hook into
wp_insert_post and prevent it from working. You could force every new post
to draft until they delete/unpublish an older one and when they do you can
allow them to publish new one.
|
Limit number of JSON results |
If you don't want to get all the results, don't use each, which does
iterate through all the results in the first place. Simple as that. For
limited and known number of steps use simple logic as:
for (var i = 0; i <= 4; i++) {
var item = data.feed.entry[i];
// your other stuff goes here
}
...or, as other state correctly, ommit your query by 5 in the first place
and then use each freely.
|
How to limit number of accociations in Rails |
Besides validations, you could also use a custom method for adding child
objects:
def add_player(player)
if players.count < 2
self.players << player
else
raise 'Too many players'
end
end
This does enforce the limit when adding players using this method, but not
when accessed directly via association, e.g. obj.players << player.
|
Limit the number of attempts in Android |
As AnujMathur_07 told you can use SharedPreferences which are pretty easy
to use, but there is a but, if the user goes to the application data and
suppress them, he will be able to send 4 new message etc.
So maybe you can use database which is not so easily deleted or, easily you
can create a text file where you write something when the user send the
last message .
|
Limit number of images - Paperclip |
For the first part of the problem you have, i would suggest you use rails
built-in counter_cache method.
Your picture model would thus become:
class Picture < ActiveRecord::Base
belongs_to :imageable, :polymorphic => true, counter_cache: true
has_attached_file :image
end
Also you would need to add a column called pictures_count to the User
model.
This way in your controller you could check if the count is upto 5 records
and therefore inform them that they have uploaded the maximum allowed.
if @user.pictures.size == 5 #sorry no more uploads
For the second part of the problem. Is the form action pointed to the
new/create action or to your update action. If pointed to the new action a
new record would be created but if pointed to the update action then it
should change
|
Appengine - Limit the number of instances |
My app is currently having only litte number of traffic, so paying even a
little dollar is a matter to me. After learning and trying so many option
on how to optimize the instance class. I found the following setting that
gives me a lowest cost on running application with Billing Status Enabled
on Google Appengine.
I use F1 Class to set Frontend instance.
Here i the code in yaml version.
instance_class: F1
automatic_scaling:
max_idle_instances: 1 # default value
min_pending_latency: automatic # default value
max_pending_latency: 30ms
I use B1 class to set Backend instance.
Here i the code in yaml version.
instance_class: B1
basic_scaling:
max_instances: 1
idle_timeout: 10m
And here is the code to put in appeengine.web.xml (if compiling java with
maven)
<threadsafe&g
|
Dataconfig - is there a limit on number of sub-entities with in an entity? |
I have not come across a limit to sub entities. However in your case it
looks evident because if you remove 1 entity it works.
I would suggest you to join the query somehow or use a view.
|
Is there a limit on the number of WHERE conditions in a SELECT statement? |
No, But read here:
The maximum number of bytes in the text of an SQL statement is limited to
SQLITE_MAX_SQL_LENGTH which defaults to 1000000. You can redefine this
limit to be as large as the smaller of SQLITE_MAX_LENGTH and 1073741824.
|
How can I limit the maximum number of selected CheckBoxes? |
Try this:
int count = 1;
int maxnoofselected = 1;
@foreach (var project in Model.Projects)
{
if(count <= maxnoofselected)
{
<input type="checkbox"
id="@project.Name"
name="Projects"
value="@project.ID"
title="@project.Name"
checked="checked" />
<label
for="@project.Name">@project.Name</label><br/>
@count++;
}
else
{
<input type="checkbox"
id="@project.Name"
name="Projects"
value="@project.ID"
title="@project.Name" />
<label
for="@project.Name">@project.Name</label><br/>
}
}
If count is less or equal to maxnoofselected (i.e. your number) then check
box will be checked otherwise it will be unchec
|
Limit number of Rows inserted into a Table |
Create a Trigger before Insert on That table.
In Trigger you can check for count for records that same table has.
Check this link for Creating Trigger.
|
How to limit number of concurrent threads in Python? |
For example, I have a directory with many files, and I want to process
all of them, but only 4 at a time in parallel.
That's exactly what a thread pool does: You create jobs, and the pool runs
4 at a time in parallel. You can make things even simpler by using an
executor, where you just hand it functions (or other callables) and it
hands you back futures for the results. You can build all of this yourself,
but you don't have to.*
The stdlib's concurrent.futures module is the easiest way to do this. (For
Python 3.1 and earlier, see the backport.) In fact, one of the main
examples is very close to what you want to do. But let's adapt it to your
exact use case:
def process_all_files(d):
files = glob.glob(d + '/*')
with concurrent.futures.ThreadPoolExecutor(max_workers=4) as exe
|
OData - Limit the number of related entities |
Not with OData v3. OData v4 has support for this. The syntax would look
like,
~Customers?$expand=Orders($orderby=OrderID&$$top=5)
Refer to the V4 draft here.
You could always do it with multiple requests though with OData V3. Using
the $batch feature would let you do it in 2 requests, get all customers
first and then build a $batch request with GET
~/Customers(id)/Orders?$orderby=CustomerID&$top=5 for each customer in
the first request.
|
Nginx - Limit number of letters in subdomain |
I can spot a couple of syntax errors in your code:
Nginx uses curly braces { } to specify internal directives so when you are
using {0,2} it is trying to read that as a directive - you would need to
double quote to avoid this;
After your $ you should have a { to open up the directive for your location
statement.
However the biggest problem is that location is not related to subdomains -
what you're looking for is server_name in the stage above location. Read
more about server names in the documentation.
note: this is untested code;
I'd try something like the following:
server {
listen 80;
# We require the expression in double quotes so the `{` and `}` aren't
passed as directives.
# The `w` matches an alphanumeric character and the `{7}` matches at
least 7 occurren
|
How to limit maximum number of items in category in yii? |
Here is the example of custom rule for the class Page, provided that
parentId attribute is the nullable foreign key to parent page, which sets
to null if the Page has no parent, i.e. it is Main Page.
class Page extends CActiveRecord
{
const MAINPAGES_LIMIT = 10;
public function rules()
{
return array(
...
array('parentId', 'mayNewMainPageBeCreated',
'on'=>'insert'),
...
);
}
// custom rule validator
public function mayNewMainPageBeCreated($attribute, $params)
{
$count = Page::model()->count("parentId IS NULL");
if ($count >= self::MAINPAGES_LIMIT) {
$this->addError($attribute, "Can't create more Main Pages");
}
}
}
|
PHP SimpleXML limit number of shown items |
Same as you do it with the database records: Get the total amount of
"records" and use an offset and a number of items per page.
If you have 200 records and 10 items per page start and you're at page 2
you would show entry 10 to 20. So you have to iterate over your "records"
and count them. If the count is between 10 and 20 show the record.
|
Limit the number of rows returned - mysql |
[LIMIT {[offset,] row_count | row_count OFFSET offset}]
You pass row_count=32.
Check manual.
|
How to configure ThreadPoolExecutor to limit number of threads |
executor.execute(new RecieveThread(threadCounter.toString()));
No, this isn't how the ExecutorService classes work. You are submitting a
thread as if it is a Runnable. So you end up with a Thread class that
actually isn't a thread. The pool threads are just calling the
RecieveThread.run() method.
You should submit your small Runnable or Callable classes to the
ExecutorService thread-pool instead. Maybe a "task" to submit to the
ExecutorService is a MessageSendRecieve? It's hard to tell from your code.
For example, he's a small simple job class that I use as an example:
public class MyJob implements Runnable {
// you can construct your jobs and pass in context for them if
necessary
public MyJob(String someContext) {
...
}
public void run() {
// p
|
How to limit number of characters to paste in the text box? |
You can achieve this by the following way. Set maximum length of the text
box as 22
textBox1.MaxLength = 22;
In the text change event do the following
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text.Length == 10)
{
textBox1.AppendText("
");
}
}
This will automatically enters to next line after 10 characters
|
How to manually limit number of post in WordPress? |
This post can help - http://digwp.com/2009/12/limit-posts-without-plugin/
There are two methods, one is to take a variable and loop it till your
desired limit and keep incrementing it.
Here is the code snippet for the same.
<?php $i = 1; while (have_posts() && $i < 6) : the_post();
?>
<h1><a href="<?php the_permalink(); ?>"><?php
the_title(); ?></a></h1>
<p>?php the_time(); ?></p>
<?php the_content(); ?>
<p><?php the_tags(); ?></p>
<?php $i++; endwhile; ?>
<p><?php next_posts_link(); ?></p>
<p><?php previous_posts_link(); ?></p>
<?php else : ?>
<h1>Not Found</h1>
<p>Silly monkey.</p>
<
|
Limit number of rows added to 10 in 'Add Row' function |
You could add a check for how many rows already exist at the beginning of
your function, and bail out if it's at or greater than 10:
if ($('#addOnDay tr').length >= 10)
return;
Actually, since you already check the count to do the zebra-striping, just
add an additional check:
$(document).on('click','#addAddOnDay',function(){
var rowCount = $('#addOnDay tr').length;
if (rowCount >= 10)
return false;
var rowClass = (rowCount + 1) % 2 == 0 ? 'rowEven' : 'rowOdd';
...
});
|
Limit the number of google recaptcha characters |
There is no way to limit the number of characters of Google ReCaptcha.
If the user can't find a captacha because it's too messy, too long, he can
ask for another captcha, and that's how it works. Moreover, reducing the
number of character would just reduce the effectiveness of ReCaptcha.
If you really want something easier, you have to look for something else or
create your own captcha system.
|
Limit number of thread in Play 2.1 framework |
The setting you have forgotten is parallelism-min which defaults to 8. But
before you go and change that one please consider not using the default
dispatcher for this purpose: restricting it to two threads may well break
the system. I’d recommend configuring a specific dispatcher to be used
for your futures.
|