How to retrieve string from a 2 dimensional array [closed] - html

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
def foo(val)
{
one: [["one1", "1"]],
two: [
["two1", "1"],
["two2", "2"]],
}[val]
end
I want to retrieve "two1" from "1", how do I do that?
Note: I want to do [:two]["1"]

def foo(v1, v2)
hsh = {
'one' => [["one1", "1"]],
'two' => [ ["two1", "1"],
["two2", "2"] ],
}
hsh[v1].select{|i| i[0] == (v1 + v2) && v2 == i[1] }.first.first
end

Related

Many to many relationship using N1ql couchbase query [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
User bucket data structure
Docid : "user123456"
{
Name: utpal,
Phone: 98222333,
Age:30,
addressids:["add_123","add_1234"]
}
Address bucket
Docid : add_123
{
Name: behala,
Location: kolkata
}
Docid : add_123
{
Name: behala1,
Location: kolkata1
}
I want to Desire results
[{
Name: utpal,
Phone: 98222333,
Age:30,
addressids:["add_123","add_1234"],
address:[
{
Name: behala,
Location: kolkata
},
{
Name: behala1,
Location: kolkata1
}
]
Any one help me how to write a N1ql query for that result
INSERT INTO default VALUES("user123456" { "Name": "utpal", "Phone": "98222333", "Age":30, "addressids":["add_123","add_1234"], "type":"user"});
INSERT INTO default VALUES("add_123", { "Name": "behala", "Location": "kolkata" });
INSERT INTO default VALUES("add_1234", { "Name": "behala4", "Location": "kolkata4" });
SELECT u.*, address
FROM default AS u
LET address = (SELECT RAW a FROM default AS a USE KEYS u.addressids)
WHERE u.type = "user";
OR
SELECT u.*, address
FROM default AS u
NEST default AS address ON u.addressids
WHERE u.type = "user";

I want to create a color picker in ionic app [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
In my app I want to create a color list whenever I choose a color from that list in the next field color of my text is automatically change according to that list. I don't have any code.
here is example for you
Credit for https://stackblitz.com/#bockoblur
import
import { ColorPickerModule } from 'ngx-color-picker';
#NgModule({
bootstrap: [
AppComponent
],
declarations: [
AppComponent
],
imports: [
BrowserModule,
ColorPickerModule
]
})
.html
<input
[style.background]="colorList[0].value"
[(colorPicker)]="colorList[0].value"
[cpOKButton] = "true"
[cpOKButtonText] = "'Select'"
[cpCancelButton] = "true"
[cpSaveClickOutside] = "'false'"
[cpDisableInput]="false"
[cpAlphaChannel]="'disabled'"
[cpOutputFormat]="'hex'"
[cpPresetColors]="presetValues"
[cpAddColorButton]="true"
/>

Laravel 5 Eloquent - whereIn on join table [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I am trying to create an online directory, where, for example, people can search through the website and find all takeaways that have a specific type. For example:
"Indian",
"Chinese"
etc..
I have 3 tables:
Business
Tags
Business Tags
And my model is as follows:
class Business extends Model
{
protected $table = 'businesses';
protected $fillable = [
'business_name', 'postcode'
];
public function tags()
{
return $this->belongsToMany('App\Tags');
}
}
The issue is, whenever I come to do the search, and try to do a whereIn the issue is that it takes forever to load, in fact, it doesn't even load. For example:
$business = Business::whereHas('tags', function($tag) use ($request) {
if($request->get('terms'))
{
$tag->whereIn('tags.name', ['chinese']);
}
})->get();
So my question is this:
I have just over 10k rows of data stored inside the table. This table is split into three "Business", "Tags", "Business Tags". The process above is taking so long to complete, probably because I use the whereHas('tags') and whereIn therefore, how do I go about using the following syntax:
$business = Business::where( function ($business) use ($request) {
// Search for businesses with a specific tag, passed from request
});
Is this possible?
I'm just wild guessing here, but try to pull the condition outside of the function and don't specify the name of the table:
if($request->get('terms'))
{
$business = Business::whereHas('tags', function($tag) use ($request) {
$tag->whereIn('name', ['chinese']);
})->get();
}

Decoding JSON in Perl [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have a JSON file like this one (it is a piece of the entire JSON file):
{
id => "mgp1310",
samples => [
{
envPackage => {
data => {
diss_carb_dioxide => {
aliases => ["sediment_diss_carb_dioxide"],
definition => "concentration of dissolved carbon dioxide",
mixs => 1,
required => 0,
type => "text",
unit => "",
value => "17 mM",
},
},
id => "mge64559",
},
},
],
}
This has been decoded by module JSON, using:
use Data::Dumper;
use JSON;
open($fh, '<', 'hola.txt' );
$json_text = <$fh>;
$perl = decode_json($json_text);
print Dumper($perl);
Now I know that $perl has a hash. So I'd like to print the id of the JSON file using print $perl{"id"};. However, it prints nothing I don't know why.
I found the answer by adding use strict at my code. It threw the following error:
Global symbol "%perl" requires explicit package name at json.pl line 12.
The variable $perl is a scalar, not a hash!. Of course... I didn't thought about that. So I cannot access to the hash writing $perl{"id"}. The correct way is $perl->{id}.

execute query with cakephp [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to execute a query to get my data
how can I write this query with cakephp
select materiel_id , SUM(quantite) from paiements
GROUP BY
materiel_id
ORDER BY sum(quantite)
Thinks,
PS : I use cakephp 2.3.6
Well assuming you have the model relationship Paiement belongsTo Materiel and you are in the PaiementsController
$this->Paiement->find('all',
array(
'group' => array('Paiement.materiel_id'),
'fields' => array('Paiement.materiel_id),
'contain' => array(
'Materiel' => array(
'fields' => array(
'SUM(Paiement.quantite) AS sum'
),
'order' => array(
'sum' => 'desc'
),
), // Materiel
) // contain
) // end array
); // end find
you ca us this code
$mat=$this->Materiel->Paiement->query("
select *,materiel_id , SUM(paiements.quantite) as t from paiements ,materiels
where paiements.materiel_id=materiels.id
GROUP BY
materiel_id
ORDER BY sum(paiements.quantite) desc
");
Ajust this code for your model