Set TextMate to use Allman indentation for PHP - textmate

For programming PHP with TextMate (OS X) I'd like it to use Allman indentation:
for($i = 0; $i < 1000; $i++)
{
echo($i);
}
Rather than the default indentation:
for($i = 0; $i < 1000; $i++) {
echo($i);
}
I can only find bundles to re-indent existing code, but not to simply use this indentation by default.

Turned out to be simple. Simply press enter first, then type the first curly brace, like so:
Type for($i = 0; $i < 1000; $i++)
Press enter
Type the opening curly brace {
Code will then be formatted like so:
for($i = 0; $i < 1000; $i++)
{
echo($i);
}

Related

Laravel Blade - loop for

How can i do it:
#for ($i = 1; $i < 11; $i++)
#if ($categorie->t$i != null)
{{$categorie->t$i}}
#endif
#endfor
categorie->t$i = categorie->t1 , t2, t3 ... t10.
Thanks !
You can access the item t$i by concatinating the string 't' with the value of $i, and afterwards accessing this.
First:
$item_name = 't' . $i;
Then:
$category->$item_name
This should do the trick.

Deleting Particular repeated field data from Google protocol buffer

.proto file structure
message repetedMSG
{
required string data = 1;
}
message mainMSG
{
required repetedMSG_id = 1;
repeated repetedMSG rptMSG = 2;
}
I have one mainMSG and in it too many (suppose 10) repetedMSG are present.
Now i want to delete any particular repetedMSG (suppose 5th repetedMSG )from mainMSG. For this i tried 3 ways but none of them worked.
for (int j = 0; j<mainMSG->repetedMSG_size(); j++){
repetedMSG reptMsg = mainMsg->mutable_repetedMSG(j);
if (QString::fromStdString(reptMsg->data).compare("deleteMe") == 0){
*First tried way:-* reptMsg->Clear();
*Second tried Way:-* delete reptMsg;
*Third tried way:-* reptMsg->clear_formula_name();
break;
}
}
I get run-time error when i serialize the mainMSG for writing to a file i.e. when execute this line
mainMSG.SerializeToOstream (std::fstream output("C:/A/test1", std::ios::out | std::ios::trunc | std::ios::binary)) here i get run-time error
You can use RepeatedPtrField::DeleteSubrange() for this. However, be careful about using this in a loop -- people commonly write code like this which is O(n^2):
// BAD CODE! O(n^2)!
for (int i = 0; i < message.foo_size(); i++) {
if (should_filter(message.foo(i))) {
message.mutable_foo()->DeleteSubrange(i, 1);
--i;
}
}
Instead, if you plan to remove multiple elements, do something like this:
// Move all filtered elements to the end of the list.
int keep = 0; // number to keep
for (int i = 0; i < message.foo_size(); i++) {
if (should_filter(message.foo(i))) {
// Skip.
} else {
if (keep < i) {
message.mutable_foo()->SwapElements(i, keep)
}
++keep;
}
}
// Remove the filtered elements.
message.mutable_foo()->DeleteSubrange(keep, message.foo_size() - keep);

Calling name of the numbers automatically in a for loop

I have an ini file with information like:
slExpsave_0 = 0.23;
slExpsave_1 = 0.40;
slExpsave_2 = -0.85;
...
I need to use them in a loop;
...
for(var i=0; i<3; i++)
{
slExpArray[i].value = slExpsave_[i];
}
But it doesn't work.
What is the reason for this?
I'm guessing this is Javascript, so you should use an array if you want to access them within a loop:
slExpsave_ = [0.23, 0.40, -0.85];
Does this help?
Let me explain my problem more clearly.
As I did it manually, It worked as I wanted:
slExpsave_0 = 0.23;
slExpsave_1 = 0.40;
slExpsave_2 = -0.85;
slExpArray[0].value = slExpsave_0; // output is 0.23;
slExpArray[1].value = slExpsave_1; // output is 0.40;
slExpArray[2].value = slExpsave_2; // output is -0.85;
when I tried to do it automatically by put in the for loop:
the first one I tried:
for(var i=0; i<3; i++)
{
slExpArray[i].value = "slExpsave_" + i;
}
// output is slExpsave_0, slExpsave_1, slExpsave_2
the second was:
for(var i=0; i<3; i++)
{
slExpArray[i].value = slExpsave_[i];
}
// doesn't work.

PHP GD Linear Dodge (Add)

There is a function in PHP GD for Linear Dodge?
I wrote this function but I would like to know if exists a function like this in PHP GD
function imagecopyAdd (&$dst_im, &$src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h)
{
for($i = 0; $i < $src_w; $i++)
{
for($c = 0; $c < $src_h; $c++)
{
$rgb1 = imagecolorat($dst_im, ($i+$dst_x), ($c+$dst_y));
$colors1 = imagecolorsforindex($dst_im, $rgb1);
$rgb2 = imagecolorat($src_im, ($i+$src_x), ($c+$src_y));
$colors2 = imagecolorsforindex($src_im, $rgb2);
$r = $colors1["red"]+$colors2["red"];
if($r > 255)
$r = 255;
$g = $colors1["green"]+$colors2["green"];
if($g > 255)
$g = 255;
$b = $colors1["blue"]+$colors2["blue"];
if($b > 255)
$b = 255;
$color = imagecolorallocate($dst_im, $r, $g, $b);
imagesetpixel($dst_im, ($i+$dst_x), ($c+$dst_y), $color);
}
}
}
While my understanding of image manipulation at more than a visual level is fundamental at best, it seems like this may be built in to the options for imagefilter.
See this comment for the users' custom implementation that he says performs the exact same function as the built in option:
It turns out PHP's Colorize is the equivalent of Photoshop's "Linear Dodge" layer filter.
Note these lines in his comment:
// Usage: Just as imagefilter(), except with no filtertype.
// imagefilterhue(resource $image, int $red, int $green , int $blue)
imagefilterhue($im,2,70,188);
// The equivalent with colorize, as tested in demo image:
imagefilter($im, IMG_FILTER_COLORIZE, 2, 70, 188);
Where imagefilterhue is his custom implementation and imagefilter is the PHP GD function.

Update query for loop is not working

I have a query like this inside for loop in codeigniter. But it executes with another values. Not with the values getting through POST method
$j = $_POST['hidden'];
$inv_id = $_POST['invoice_id'];
$sum = '';
for($i = 1; $i <= $j; $i++){
$wh_quantity1 = $_POST['quantity'.$i];
//print_r($wh_quantity1);
if($wh_quantity1 ==''){
$wh_quantity = 0;
}
else{
$wh_quantity = $wh_quantity1;
}
$query = "UPDATE tb_warehouse_stocks SET wh_product_qty = wh_product_qty - $wh_quantity WHERE invoice_id = '$inv_id'";
$this->db->query($query);
$sum += $wh_quantity;
}
Why it is like that. It always updates with greater values than POST value
Put this in .htaccess file
RewriteEngine On
RewriteRule ^ http://example.com/international/university-english-access-course$ http://example.com/website/page/english-access [R=301,L]
Try this in case your dont have all post index
$j = $this->input->post('hidden');
$inv_id = $this->input->post('invoice_id');
$sum = 0;
for ($i = 1; $i <= $j; $i++) {
$wh_quantity = (int) $this->input->post('quantity' . $i);
$sum += $wh_quantity;
}
$query = "UPDATE tb_warehouse_stocks SET wh_product_qty = wh_product_qty - $sum WHERE invoice_id = '$inv_id'";
$this->db->query($query);

Resources