qid
int64 4
19.1M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
74,654,757
|
<p>I need a formula to calculate between two date and time excluding lunch time, holidays, weekend and between 09:00 and 18:00 work hours.</p>
<p>For example, 25/07/2022 12:00 and 29/07/2022 10:00 and answer has to be 1 day, 06:00</p>
<p>Thanks in advance.</p>
<p>I had a formula but it didn't work when hours bigger than 24 hours.</p>
|
[
{
"answer_id": 74654851,
"author": "abokey",
"author_id": 16120011,
"author_profile": "https://Stackoverflow.com/users/16120011",
"pm_score": 3,
"selected": true,
"text": "abs pandas.DataFrame.sort_values out = df.sort_values(by=\"Score\", key=abs)\n print(out)\n\n Name Score\n3 maggie 0\n2 sally -5\n1 jane -10\n4 peter 15\n6 andy 25\n0 bob -30\n5 mike 50\n"
},
{
"answer_id": 74654897,
"author": "Marty_C137",
"author_id": 15417368,
"author_profile": "https://Stackoverflow.com/users/15417368",
"pm_score": 1,
"selected": false,
"text": "abs import pandas as pd\n\ndf = pd.DataFrame({'Name': ['Bob', 'Jane', 'Sally', 'Maggie', 'Peter', 'Mike', 'Andy'],\n 'Score': [-30, -10, -5, 0, 15, 50, 25]})\n\ndf.sort_values('Score', key = abs)\n df.reindex(df['Score'].abs().sort_values().index)\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74654757",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20665202/"
] |
74,654,766
|
<p>I faced an error using StoreModule.forRoot() in angular project with NgRX.
I will attach a picture of my error if anyone can help with a solution for it.</p>
<p>I was trying to implement reducers in angular using ngrx/store but I faced a problem while importing it in app.module. <a href="https://i.stack.imgur.com/fSL7J.png" rel="nofollow noreferrer">Image of error</a></p>
|
[
{
"answer_id": 74654851,
"author": "abokey",
"author_id": 16120011,
"author_profile": "https://Stackoverflow.com/users/16120011",
"pm_score": 3,
"selected": true,
"text": "abs pandas.DataFrame.sort_values out = df.sort_values(by=\"Score\", key=abs)\n print(out)\n\n Name Score\n3 maggie 0\n2 sally -5\n1 jane -10\n4 peter 15\n6 andy 25\n0 bob -30\n5 mike 50\n"
},
{
"answer_id": 74654897,
"author": "Marty_C137",
"author_id": 15417368,
"author_profile": "https://Stackoverflow.com/users/15417368",
"pm_score": 1,
"selected": false,
"text": "abs import pandas as pd\n\ndf = pd.DataFrame({'Name': ['Bob', 'Jane', 'Sally', 'Maggie', 'Peter', 'Mike', 'Andy'],\n 'Score': [-30, -10, -5, 0, 15, 50, 25]})\n\ndf.sort_values('Score', key = abs)\n df.reindex(df['Score'].abs().sort_values().index)\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74654766",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20665566/"
] |
74,654,775
|
<p>`i want to show event on my fullcalendar by filtring by id_service</p>
<p>here is my concontroller, i convert the event to array and get them by callendrier`</p>
<pre><code>> public function callendrier($id_service)
{
$services= Service::all();
if($id_service==0){
$conge = Conge::all();
}else{
$conge = Conge::where('serv_id','=',$id_service)->get();
}
return $conge;
// $this->eventsToArray(Conge::all());
}
public function eventsToArray($conges)
{
$eventArray = [];
foreach($conges as $conge){
$data = [
'id' =>$conge->id,
"title" => $conge->employe->nom_emp,
"type" =>$conge->typeconge->type,
"dure_conge" => $conge->dure_conge,
"start" => $conge->start_date,
"end" => $conge->end_date ,
"remplacant" => $conge->remplacant,
"solde_conge" => $conge->solde_conge,
"color"=>$conge->color,
"employes"=>$conge->employe_id,
"id_service"=>$conge->employe->poste->serv_id,
"textColor" => "white"
];
array_push($eventArray,$data);
}
return response()->json($eventArray);
}
</code></pre>
<p>and i dont know how to get only the event id_service that i selectes on my dropdown ,please any help</p>
<pre><code>
$(document).ready(function() {
var calendarEl = document.getElementById('fcalendar')
let id_service = document.querySelector("#select_service");
var calendar = new FullCalendar.Calendar(calendarEl, {
//events : '/callendrier',
events: function(fetchInfo, successCallback, failureCallback) {
var id_service = $('#select_service').val();
console.log(id_service)
$.ajax({
type:"GET",
url:"{{url('/callendrier')}}"+ (id_service != "" ? '/' + id_service : ""),
}).done(function(data) {
successCallback(data); //use the supplied callback function to return the event data to fullCalendar
}).fail(function(jqXHR, textStatus, errorThrown) {
failureCallback(jqXHR);
});
},
calendar.render();
$('#select_service').change(function() {
calendar.refetchEvents();
//console.log(id_service)
});
```
</code></pre>
|
[
{
"answer_id": 74654851,
"author": "abokey",
"author_id": 16120011,
"author_profile": "https://Stackoverflow.com/users/16120011",
"pm_score": 3,
"selected": true,
"text": "abs pandas.DataFrame.sort_values out = df.sort_values(by=\"Score\", key=abs)\n print(out)\n\n Name Score\n3 maggie 0\n2 sally -5\n1 jane -10\n4 peter 15\n6 andy 25\n0 bob -30\n5 mike 50\n"
},
{
"answer_id": 74654897,
"author": "Marty_C137",
"author_id": 15417368,
"author_profile": "https://Stackoverflow.com/users/15417368",
"pm_score": 1,
"selected": false,
"text": "abs import pandas as pd\n\ndf = pd.DataFrame({'Name': ['Bob', 'Jane', 'Sally', 'Maggie', 'Peter', 'Mike', 'Andy'],\n 'Score': [-30, -10, -5, 0, 15, 50, 25]})\n\ndf.sort_values('Score', key = abs)\n df.reindex(df['Score'].abs().sort_values().index)\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74654775",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20546281/"
] |
74,654,788
|
<p>I have this format of json</p>
<pre><code>{
"Toyota": ["Vitz", "Corolla"],
"Mazda": ["Demio", "SUV"],
"Mitsubishi": ["FH", "FRR"]
}
</code></pre>
<p>That i wish to return. In my code i have this</p>
<pre><code> public function all_makes_and_models(){
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: X-Requested-With");
/**
{
"Toyota": ["Vitz", "Corolla"],
"Mazda": ["Demio", "SUV"],
"Mitsubishi": ["FH", "FRR"]
}
*/
$car_makes = array("Honda", "Mazda", "Nissan", "Subaru", "Toyota", "Acura", "Alfa Romeo", "Aston Martin", "Audi", "BAW", "Bentley", "BJC", "BMW", "Brabus", "Brilliance", "Buick", "Cadillac", "Changan", "Chery", "Chevrolet", "Chrysler", "Citroen", "Dacia", "Daewoo", "DAF", "Daihatsu", "Daimler", "Datsun", "Dodge", "Dongfeng", "Faw", "Ferrari", "Fiat", "Ford", "Foton", "GAC", "Geely", "Genesis", "Ginaf", "GMC", "Gonow", "Great Wall", "Haima", "Higer", "Hino", "Holden", "Hummer", "Hyundai", "Infiniti", "International", "Isuzu", "Iveco", "IVM", "JAC", "Jaguar", "Jeep", "Jetour", "JMC", "Joylong", "Kia", "King Long", "Lada", "Lamborghini", "Lancia", "Land Rover", "Lexus", "Lifan", "Lincoln", "Lotus", "Mahindra", "MAN", "Maserati", "McLaren", "Mercedes-Benz", "Mercury", "MG", "Mini", "Mitsubishi", "Mobius", "Morris", "Nord", "Oldsmobile", "Opel", "Peugeot", "Piaggio", "Polaris", "Pontiac", "Porsche", "Proton", "Renault", "Rolls-Royce", "Rover", "Saab", "Samsung", "Sany", "Saturn", "Scion", "Seat", "Secodi", "Simba", "Sinotruk", "Skoda", "SkyGo", "SMA", "Smart", "SsangYong", "Suzuki", "T King", "Tata", "Triumph", "TVS", "Vauxhall", "Vector", "Venturi", "Volkswagen", "Volvo", "Zotye", "ZX Auto");
$ca = [];
$keyvalues = array();
$car_make = 0;
foreach ($car_makes as $car_make) {
$query = $this->db->query("select valuex from key_value_pairs where parent='$car_make'");
$row = $query->row();
$rs = 0;
foreach ($query->result() as $row)
{
$rs = $row->valuex;
//array_push($ca,$rs);
$keyvalues[$rs] = $rs;
//echo $obj;
}
echo '<pre>';
//print_r($obj);
echo '</pre>';
}
</code></pre>
<p>My code loops through an array that holds all car makes and fetches model in a table that holds all models. I only provide the car make as parent in my query and all car models are returned.</p>
<p>My table looks like this.<a href="https://i.stack.imgur.com/wSVe5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wSVe5.png" alt="enter image description here" /></a></p>
<p>I get a very long arrays and not the comma separated list of models.</p>
<p>How can i fix this?.</p>
|
[
{
"answer_id": 74655131,
"author": "O. Jones",
"author_id": 205608,
"author_profile": "https://Stackoverflow.com/users/205608",
"pm_score": 2,
"selected": true,
"text": "$data_structure = [\n 'Toyota' => ['Vitz', 'Corolla'],\n 'Mazda' => ['Demio', 'SUV'],\n 'Mitsubishi' => ['FH', 'FRR'],\n];\n$json = json_encode( (object) $data_structure );\n make model $data_structure = []; /* empty top-level array */\n$query = $this->db->query('select make, model from key_value_pairs');\nforeach ($query->result() as $row) {\n if (! array_key_exists ($row->make, $data_structure ) {\n /* create an entry for this row if none already exists */\n $data_structure[ $row->make ] = [];\n }\n /* append the model name to the array */\n $data_structure [ $row->make ] [] = $row->model;\n}\n$json = json_encode( (object) $data_structure;\n"
},
{
"answer_id": 74655134,
"author": "Abdusalam mohamed",
"author_id": 12252645,
"author_profile": "https://Stackoverflow.com/users/12252645",
"pm_score": 0,
"selected": false,
"text": "public function all_makes_and_models(){\n \n header('Access-Control-Allow-Origin: *');\n header('Access-Control-Allow-Methods: GET, POST');\n header(\"Access-Control-Allow-Headers: X-Requested-With\");\n \n /**\n {\n \"Toyota\": [\"Vitz\", \"Corolla\"],\n \"Mazda\": [\"Demio\", \"SUV\"],\n \"Mitsubishi\": [\"FH\", \"FRR\"]\n }\n */\n \n \n $car_makes = array(\"Honda\", \"Mazda\", \"Nissan\", \"Subaru\", \"Toyota\", \"Acura\", \"Alfa Romeo\", \"Aston Martin\", \"Audi\", \"BAW\", \"Bentley\", \"BJC\", \"BMW\", \"Brabus\", \"Brilliance\", \"Buick\", \"Cadillac\", \"Changan\", \"Chery\", \"Chevrolet\", \"Chrysler\", \"Citroen\", \"Dacia\", \"Daewoo\", \"DAF\", \"Daihatsu\", \"Daimler\", \"Datsun\", \"Dodge\", \"Dongfeng\", \"Faw\", \"Ferrari\", \"Fiat\", \"Ford\", \"Foton\", \"GAC\", \"Geely\", \"Genesis\", \"Ginaf\", \"GMC\", \"Gonow\", \"Great Wall\", \"Haima\", \"Higer\", \"Hino\", \"Holden\", \"Hummer\", \"Hyundai\", \"Infiniti\", \"International\", \"Isuzu\", \"Iveco\", \"IVM\", \"JAC\", \"Jaguar\", \"Jeep\", \"Jetour\", \"JMC\", \"Joylong\", \"Kia\", \"King Long\", \"Lada\", \"Lamborghini\", \"Lancia\", \"Land Rover\", \"Lexus\", \"Lifan\", \"Lincoln\", \"Lotus\", \"Mahindra\", \"MAN\", \"Maserati\", \"McLaren\", \"Mercedes-Benz\", \"Mercury\", \"MG\", \"Mini\", \"Mitsubishi\", \"Mobius\", \"Morris\", \"Nord\", \"Oldsmobile\", \"Opel\", \"Peugeot\", \"Piaggio\", \"Polaris\", \"Pontiac\", \"Porsche\", \"Proton\", \"Renault\", \"Rolls-Royce\", \"Rover\", \"Saab\", \"Samsung\", \"Sany\", \"Saturn\", \"Scion\", \"Seat\", \"Secodi\", \"Simba\", \"Sinotruk\", \"Skoda\", \"SkyGo\", \"SMA\", \"Smart\", \"SsangYong\", \"Suzuki\", \"T King\", \"Tata\", \"Triumph\", \"TVS\", \"Vauxhall\", \"Vector\", \"Venturi\", \"Volkswagen\", \"Volvo\", \"Zotye\", \"ZX Auto\");\n- // $ca = []\n+ $ca = array();\n...\n foreach ($query->result() as $row)\n {\n- //$rs = $row->valuex;\n- //array_push($ca,$rs);\n \n- //$keyvalues[$rs] = $rs;\n \n- //echo $obj;\n+ array_push($ca[$car_make], $row->valuex)\n\n }\n \n echo '<pre>';\n print_r($ca);\n echo '</pre>';\n }\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74654788",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/492293/"
] |
74,654,795
|
<p>I have the following dataset:</p>
<pre><code>id test date
1 A 2000-01-01
1 B 2000-01-01
1 C 2000-01-08
2 A 2000-01-01
2 A 2000-01-01
2 B 2000-01-08
3 A 2000-01-01
3 C 2000-01-01
3 B 2000-01-08
4 A 2000-01-01
4 B 2000-01-01
4 C 2000-01-01
5 A 2000-01-01
5 B 2000-01-01
5 C 2000-01-01
</code></pre>
<p>I would love to create a matrix figure with the count of how many individuals got a test taken on the same day.</p>
<p>For example:</p>
<p><a href="https://i.stack.imgur.com/nWyLc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nWyLc.png" alt="enter image description here" /></a></p>
<p>Since we can see that 1 time (for one individual, id=1) test A and B were taken on the day; also for one individual (id = 3) test A and B were taken on the same day; and for two individuals (id=4 and 5) the three tests were taken on the same day.</p>
<p>So far I am doing the following:</p>
<pre><code>df_tests = df.groupby(['id', 'date']).value_counts().reset_index(name='count')
df_tests_unique = df_tests[df_tests_re.duplicated(subset=['id','date'], keep=False)]
df_tests_unique = df_tests_unique[["id", "date", "test"]]
</code></pre>
<p>So the only thing left is to count the number of times the different tests ocur within the same date</p>
|
[
{
"answer_id": 74655131,
"author": "O. Jones",
"author_id": 205608,
"author_profile": "https://Stackoverflow.com/users/205608",
"pm_score": 2,
"selected": true,
"text": "$data_structure = [\n 'Toyota' => ['Vitz', 'Corolla'],\n 'Mazda' => ['Demio', 'SUV'],\n 'Mitsubishi' => ['FH', 'FRR'],\n];\n$json = json_encode( (object) $data_structure );\n make model $data_structure = []; /* empty top-level array */\n$query = $this->db->query('select make, model from key_value_pairs');\nforeach ($query->result() as $row) {\n if (! array_key_exists ($row->make, $data_structure ) {\n /* create an entry for this row if none already exists */\n $data_structure[ $row->make ] = [];\n }\n /* append the model name to the array */\n $data_structure [ $row->make ] [] = $row->model;\n}\n$json = json_encode( (object) $data_structure;\n"
},
{
"answer_id": 74655134,
"author": "Abdusalam mohamed",
"author_id": 12252645,
"author_profile": "https://Stackoverflow.com/users/12252645",
"pm_score": 0,
"selected": false,
"text": "public function all_makes_and_models(){\n \n header('Access-Control-Allow-Origin: *');\n header('Access-Control-Allow-Methods: GET, POST');\n header(\"Access-Control-Allow-Headers: X-Requested-With\");\n \n /**\n {\n \"Toyota\": [\"Vitz\", \"Corolla\"],\n \"Mazda\": [\"Demio\", \"SUV\"],\n \"Mitsubishi\": [\"FH\", \"FRR\"]\n }\n */\n \n \n $car_makes = array(\"Honda\", \"Mazda\", \"Nissan\", \"Subaru\", \"Toyota\", \"Acura\", \"Alfa Romeo\", \"Aston Martin\", \"Audi\", \"BAW\", \"Bentley\", \"BJC\", \"BMW\", \"Brabus\", \"Brilliance\", \"Buick\", \"Cadillac\", \"Changan\", \"Chery\", \"Chevrolet\", \"Chrysler\", \"Citroen\", \"Dacia\", \"Daewoo\", \"DAF\", \"Daihatsu\", \"Daimler\", \"Datsun\", \"Dodge\", \"Dongfeng\", \"Faw\", \"Ferrari\", \"Fiat\", \"Ford\", \"Foton\", \"GAC\", \"Geely\", \"Genesis\", \"Ginaf\", \"GMC\", \"Gonow\", \"Great Wall\", \"Haima\", \"Higer\", \"Hino\", \"Holden\", \"Hummer\", \"Hyundai\", \"Infiniti\", \"International\", \"Isuzu\", \"Iveco\", \"IVM\", \"JAC\", \"Jaguar\", \"Jeep\", \"Jetour\", \"JMC\", \"Joylong\", \"Kia\", \"King Long\", \"Lada\", \"Lamborghini\", \"Lancia\", \"Land Rover\", \"Lexus\", \"Lifan\", \"Lincoln\", \"Lotus\", \"Mahindra\", \"MAN\", \"Maserati\", \"McLaren\", \"Mercedes-Benz\", \"Mercury\", \"MG\", \"Mini\", \"Mitsubishi\", \"Mobius\", \"Morris\", \"Nord\", \"Oldsmobile\", \"Opel\", \"Peugeot\", \"Piaggio\", \"Polaris\", \"Pontiac\", \"Porsche\", \"Proton\", \"Renault\", \"Rolls-Royce\", \"Rover\", \"Saab\", \"Samsung\", \"Sany\", \"Saturn\", \"Scion\", \"Seat\", \"Secodi\", \"Simba\", \"Sinotruk\", \"Skoda\", \"SkyGo\", \"SMA\", \"Smart\", \"SsangYong\", \"Suzuki\", \"T King\", \"Tata\", \"Triumph\", \"TVS\", \"Vauxhall\", \"Vector\", \"Venturi\", \"Volkswagen\", \"Volvo\", \"Zotye\", \"ZX Auto\");\n- // $ca = []\n+ $ca = array();\n...\n foreach ($query->result() as $row)\n {\n- //$rs = $row->valuex;\n- //array_push($ca,$rs);\n \n- //$keyvalues[$rs] = $rs;\n \n- //echo $obj;\n+ array_push($ca[$car_make], $row->valuex)\n\n }\n \n echo '<pre>';\n print_r($ca);\n echo '</pre>';\n }\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74654795",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5510540/"
] |
74,654,931
|
<p>I have a view that has context data and it extends base.html but as I want the context data to be displayed in all templates that extend from base.html and not only the view with the context data I am doing custom template tags with the context inside but I get an error.</p>
<p>view with and without context data:</p>
<pre><code>class HomeView(ListView):
model = Product
context_object_name='products'
template_name = 'main/home.html'
paginate_by = 25
class HomeView(ListView):
model = Product
context_object_name='products'
template_name = 'main/home.html'
paginate_by = 25
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
categories = Category.objects.all()
news = News.objects.all()
context.update({
'categories' : categories,
'news' : news,
})
return context
</code></pre>
<p>base.html with and without the custom tag</p>
<pre><code>{% news %}
{% for new in news %}
<p>{{ new.title }}</p>
{% endfor %}
</code></pre>
<p>The custom tag file templatetags/news.py</p>
<pre><code>from django import template
from support.models import News
register = template.Library()
@register.inclusion_tag('news.html', takes_context=True)
def news(context):
return {
'news': News.objects.order_by("-date_posted")[0:25],
}
</code></pre>
<p>The custom tag file templatetags/news.html</p>
<pre><code>{% for new in news %}
<p>{{ new.title }}</p>
{% endfor %}
</code></pre>
<p>File structure:</p>
<p>Project</p>
<ul>
<li><p>main</p>
<ul>
<li><p>templates/main</p>
<ul>
<li>base.html</li>
</ul>
</li>
<li><p>templatetags</p>
<ul>
<li>news.py</li>
<li>news.html</li>
</ul>
</li>
<li><p>models.py</p>
</li>
<li><p>urls.py</p>
</li>
<li><p>views.py
...</p>
</li>
</ul>
</li>
<li><p>project</p>
<ul>
<li>settings.py
...</li>
</ul>
<p>...</p>
</li>
</ul>
|
[
{
"answer_id": 74655131,
"author": "O. Jones",
"author_id": 205608,
"author_profile": "https://Stackoverflow.com/users/205608",
"pm_score": 2,
"selected": true,
"text": "$data_structure = [\n 'Toyota' => ['Vitz', 'Corolla'],\n 'Mazda' => ['Demio', 'SUV'],\n 'Mitsubishi' => ['FH', 'FRR'],\n];\n$json = json_encode( (object) $data_structure );\n make model $data_structure = []; /* empty top-level array */\n$query = $this->db->query('select make, model from key_value_pairs');\nforeach ($query->result() as $row) {\n if (! array_key_exists ($row->make, $data_structure ) {\n /* create an entry for this row if none already exists */\n $data_structure[ $row->make ] = [];\n }\n /* append the model name to the array */\n $data_structure [ $row->make ] [] = $row->model;\n}\n$json = json_encode( (object) $data_structure;\n"
},
{
"answer_id": 74655134,
"author": "Abdusalam mohamed",
"author_id": 12252645,
"author_profile": "https://Stackoverflow.com/users/12252645",
"pm_score": 0,
"selected": false,
"text": "public function all_makes_and_models(){\n \n header('Access-Control-Allow-Origin: *');\n header('Access-Control-Allow-Methods: GET, POST');\n header(\"Access-Control-Allow-Headers: X-Requested-With\");\n \n /**\n {\n \"Toyota\": [\"Vitz\", \"Corolla\"],\n \"Mazda\": [\"Demio\", \"SUV\"],\n \"Mitsubishi\": [\"FH\", \"FRR\"]\n }\n */\n \n \n $car_makes = array(\"Honda\", \"Mazda\", \"Nissan\", \"Subaru\", \"Toyota\", \"Acura\", \"Alfa Romeo\", \"Aston Martin\", \"Audi\", \"BAW\", \"Bentley\", \"BJC\", \"BMW\", \"Brabus\", \"Brilliance\", \"Buick\", \"Cadillac\", \"Changan\", \"Chery\", \"Chevrolet\", \"Chrysler\", \"Citroen\", \"Dacia\", \"Daewoo\", \"DAF\", \"Daihatsu\", \"Daimler\", \"Datsun\", \"Dodge\", \"Dongfeng\", \"Faw\", \"Ferrari\", \"Fiat\", \"Ford\", \"Foton\", \"GAC\", \"Geely\", \"Genesis\", \"Ginaf\", \"GMC\", \"Gonow\", \"Great Wall\", \"Haima\", \"Higer\", \"Hino\", \"Holden\", \"Hummer\", \"Hyundai\", \"Infiniti\", \"International\", \"Isuzu\", \"Iveco\", \"IVM\", \"JAC\", \"Jaguar\", \"Jeep\", \"Jetour\", \"JMC\", \"Joylong\", \"Kia\", \"King Long\", \"Lada\", \"Lamborghini\", \"Lancia\", \"Land Rover\", \"Lexus\", \"Lifan\", \"Lincoln\", \"Lotus\", \"Mahindra\", \"MAN\", \"Maserati\", \"McLaren\", \"Mercedes-Benz\", \"Mercury\", \"MG\", \"Mini\", \"Mitsubishi\", \"Mobius\", \"Morris\", \"Nord\", \"Oldsmobile\", \"Opel\", \"Peugeot\", \"Piaggio\", \"Polaris\", \"Pontiac\", \"Porsche\", \"Proton\", \"Renault\", \"Rolls-Royce\", \"Rover\", \"Saab\", \"Samsung\", \"Sany\", \"Saturn\", \"Scion\", \"Seat\", \"Secodi\", \"Simba\", \"Sinotruk\", \"Skoda\", \"SkyGo\", \"SMA\", \"Smart\", \"SsangYong\", \"Suzuki\", \"T King\", \"Tata\", \"Triumph\", \"TVS\", \"Vauxhall\", \"Vector\", \"Venturi\", \"Volkswagen\", \"Volvo\", \"Zotye\", \"ZX Auto\");\n- // $ca = []\n+ $ca = array();\n...\n foreach ($query->result() as $row)\n {\n- //$rs = $row->valuex;\n- //array_push($ca,$rs);\n \n- //$keyvalues[$rs] = $rs;\n \n- //echo $obj;\n+ array_push($ca[$car_make], $row->valuex)\n\n }\n \n echo '<pre>';\n print_r($ca);\n echo '</pre>';\n }\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74654931",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19881162/"
] |
74,654,963
|
<p>I've seen follow code and i think that it is a wrong way to cache tempview in Spark. What do you think?</p>
<pre><code>spark.sql(
s"""
|...
""".stripMargin).createOrReplaceTempView(s"temp_view")
spark.table(s"temp_view").cache()
</code></pre>
<p>For my opinion, this code caches DataFrame that I create by <code>spark.table("temp_view")</code>, but not original temp view.</p>
<p>Am I right?</p>
|
[
{
"answer_id": 74655131,
"author": "O. Jones",
"author_id": 205608,
"author_profile": "https://Stackoverflow.com/users/205608",
"pm_score": 2,
"selected": true,
"text": "$data_structure = [\n 'Toyota' => ['Vitz', 'Corolla'],\n 'Mazda' => ['Demio', 'SUV'],\n 'Mitsubishi' => ['FH', 'FRR'],\n];\n$json = json_encode( (object) $data_structure );\n make model $data_structure = []; /* empty top-level array */\n$query = $this->db->query('select make, model from key_value_pairs');\nforeach ($query->result() as $row) {\n if (! array_key_exists ($row->make, $data_structure ) {\n /* create an entry for this row if none already exists */\n $data_structure[ $row->make ] = [];\n }\n /* append the model name to the array */\n $data_structure [ $row->make ] [] = $row->model;\n}\n$json = json_encode( (object) $data_structure;\n"
},
{
"answer_id": 74655134,
"author": "Abdusalam mohamed",
"author_id": 12252645,
"author_profile": "https://Stackoverflow.com/users/12252645",
"pm_score": 0,
"selected": false,
"text": "public function all_makes_and_models(){\n \n header('Access-Control-Allow-Origin: *');\n header('Access-Control-Allow-Methods: GET, POST');\n header(\"Access-Control-Allow-Headers: X-Requested-With\");\n \n /**\n {\n \"Toyota\": [\"Vitz\", \"Corolla\"],\n \"Mazda\": [\"Demio\", \"SUV\"],\n \"Mitsubishi\": [\"FH\", \"FRR\"]\n }\n */\n \n \n $car_makes = array(\"Honda\", \"Mazda\", \"Nissan\", \"Subaru\", \"Toyota\", \"Acura\", \"Alfa Romeo\", \"Aston Martin\", \"Audi\", \"BAW\", \"Bentley\", \"BJC\", \"BMW\", \"Brabus\", \"Brilliance\", \"Buick\", \"Cadillac\", \"Changan\", \"Chery\", \"Chevrolet\", \"Chrysler\", \"Citroen\", \"Dacia\", \"Daewoo\", \"DAF\", \"Daihatsu\", \"Daimler\", \"Datsun\", \"Dodge\", \"Dongfeng\", \"Faw\", \"Ferrari\", \"Fiat\", \"Ford\", \"Foton\", \"GAC\", \"Geely\", \"Genesis\", \"Ginaf\", \"GMC\", \"Gonow\", \"Great Wall\", \"Haima\", \"Higer\", \"Hino\", \"Holden\", \"Hummer\", \"Hyundai\", \"Infiniti\", \"International\", \"Isuzu\", \"Iveco\", \"IVM\", \"JAC\", \"Jaguar\", \"Jeep\", \"Jetour\", \"JMC\", \"Joylong\", \"Kia\", \"King Long\", \"Lada\", \"Lamborghini\", \"Lancia\", \"Land Rover\", \"Lexus\", \"Lifan\", \"Lincoln\", \"Lotus\", \"Mahindra\", \"MAN\", \"Maserati\", \"McLaren\", \"Mercedes-Benz\", \"Mercury\", \"MG\", \"Mini\", \"Mitsubishi\", \"Mobius\", \"Morris\", \"Nord\", \"Oldsmobile\", \"Opel\", \"Peugeot\", \"Piaggio\", \"Polaris\", \"Pontiac\", \"Porsche\", \"Proton\", \"Renault\", \"Rolls-Royce\", \"Rover\", \"Saab\", \"Samsung\", \"Sany\", \"Saturn\", \"Scion\", \"Seat\", \"Secodi\", \"Simba\", \"Sinotruk\", \"Skoda\", \"SkyGo\", \"SMA\", \"Smart\", \"SsangYong\", \"Suzuki\", \"T King\", \"Tata\", \"Triumph\", \"TVS\", \"Vauxhall\", \"Vector\", \"Venturi\", \"Volkswagen\", \"Volvo\", \"Zotye\", \"ZX Auto\");\n- // $ca = []\n+ $ca = array();\n...\n foreach ($query->result() as $row)\n {\n- //$rs = $row->valuex;\n- //array_push($ca,$rs);\n \n- //$keyvalues[$rs] = $rs;\n \n- //echo $obj;\n+ array_push($ca[$car_make], $row->valuex)\n\n }\n \n echo '<pre>';\n print_r($ca);\n echo '</pre>';\n }\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74654963",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11653949/"
] |
74,654,996
|
<p>I am calling one function through <code>setInterval</code> but function go to infinite loop and my applicaiton get stuck. It's happen it on android, Could someone please help me how to resolve this issue.</p>
<p>Thanks</p>
<pre><code> useEffect(() => {
const interval = setInterval(() => {
sendCoordinate(location);
}, 180000);
return () => clearInterval(interval);
}, [location]);
</code></pre>
<p><strong>A function that I am calling</strong></p>
<pre><code>const sendCoordinate = async (locParms) => {
console.log("@2 it working3", checkDayStatus, location);
if (checkDayStatus === "Started") {
let data = {
lat:
locParms !== null
? locParms && locParms.lat
: location && location.lat,
lng:
locParms !== null
? locParms && locParms.lng
: location && location.lng,
dispatcher_id: 1,
truck_id: 1,
};
return await LocationAPI.sendLocationFeed(data);
}
};
</code></pre>
|
[
{
"answer_id": 74655131,
"author": "O. Jones",
"author_id": 205608,
"author_profile": "https://Stackoverflow.com/users/205608",
"pm_score": 2,
"selected": true,
"text": "$data_structure = [\n 'Toyota' => ['Vitz', 'Corolla'],\n 'Mazda' => ['Demio', 'SUV'],\n 'Mitsubishi' => ['FH', 'FRR'],\n];\n$json = json_encode( (object) $data_structure );\n make model $data_structure = []; /* empty top-level array */\n$query = $this->db->query('select make, model from key_value_pairs');\nforeach ($query->result() as $row) {\n if (! array_key_exists ($row->make, $data_structure ) {\n /* create an entry for this row if none already exists */\n $data_structure[ $row->make ] = [];\n }\n /* append the model name to the array */\n $data_structure [ $row->make ] [] = $row->model;\n}\n$json = json_encode( (object) $data_structure;\n"
},
{
"answer_id": 74655134,
"author": "Abdusalam mohamed",
"author_id": 12252645,
"author_profile": "https://Stackoverflow.com/users/12252645",
"pm_score": 0,
"selected": false,
"text": "public function all_makes_and_models(){\n \n header('Access-Control-Allow-Origin: *');\n header('Access-Control-Allow-Methods: GET, POST');\n header(\"Access-Control-Allow-Headers: X-Requested-With\");\n \n /**\n {\n \"Toyota\": [\"Vitz\", \"Corolla\"],\n \"Mazda\": [\"Demio\", \"SUV\"],\n \"Mitsubishi\": [\"FH\", \"FRR\"]\n }\n */\n \n \n $car_makes = array(\"Honda\", \"Mazda\", \"Nissan\", \"Subaru\", \"Toyota\", \"Acura\", \"Alfa Romeo\", \"Aston Martin\", \"Audi\", \"BAW\", \"Bentley\", \"BJC\", \"BMW\", \"Brabus\", \"Brilliance\", \"Buick\", \"Cadillac\", \"Changan\", \"Chery\", \"Chevrolet\", \"Chrysler\", \"Citroen\", \"Dacia\", \"Daewoo\", \"DAF\", \"Daihatsu\", \"Daimler\", \"Datsun\", \"Dodge\", \"Dongfeng\", \"Faw\", \"Ferrari\", \"Fiat\", \"Ford\", \"Foton\", \"GAC\", \"Geely\", \"Genesis\", \"Ginaf\", \"GMC\", \"Gonow\", \"Great Wall\", \"Haima\", \"Higer\", \"Hino\", \"Holden\", \"Hummer\", \"Hyundai\", \"Infiniti\", \"International\", \"Isuzu\", \"Iveco\", \"IVM\", \"JAC\", \"Jaguar\", \"Jeep\", \"Jetour\", \"JMC\", \"Joylong\", \"Kia\", \"King Long\", \"Lada\", \"Lamborghini\", \"Lancia\", \"Land Rover\", \"Lexus\", \"Lifan\", \"Lincoln\", \"Lotus\", \"Mahindra\", \"MAN\", \"Maserati\", \"McLaren\", \"Mercedes-Benz\", \"Mercury\", \"MG\", \"Mini\", \"Mitsubishi\", \"Mobius\", \"Morris\", \"Nord\", \"Oldsmobile\", \"Opel\", \"Peugeot\", \"Piaggio\", \"Polaris\", \"Pontiac\", \"Porsche\", \"Proton\", \"Renault\", \"Rolls-Royce\", \"Rover\", \"Saab\", \"Samsung\", \"Sany\", \"Saturn\", \"Scion\", \"Seat\", \"Secodi\", \"Simba\", \"Sinotruk\", \"Skoda\", \"SkyGo\", \"SMA\", \"Smart\", \"SsangYong\", \"Suzuki\", \"T King\", \"Tata\", \"Triumph\", \"TVS\", \"Vauxhall\", \"Vector\", \"Venturi\", \"Volkswagen\", \"Volvo\", \"Zotye\", \"ZX Auto\");\n- // $ca = []\n+ $ca = array();\n...\n foreach ($query->result() as $row)\n {\n- //$rs = $row->valuex;\n- //array_push($ca,$rs);\n \n- //$keyvalues[$rs] = $rs;\n \n- //echo $obj;\n+ array_push($ca[$car_make], $row->valuex)\n\n }\n \n echo '<pre>';\n print_r($ca);\n echo '</pre>';\n }\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74654996",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20588409/"
] |
74,655,009
|
<p>So I'm trying to install yasm on Windows 11 with Chocolatey, but an error occurs, does anyone know how to solve this error?</p>
<pre><code>PS C:\WINDOWS\system32> choco install yasm
Chocolatey v1.2.0
Installing the following packages:
yasm
By installing, you accept licenses for the packages.
Progress: Downloading yasm 1.2.0... 100%
yasm v1.2.0
yasm package files install completed. Performing other installation steps.
The package yasm wants to run 'chocolateyInstall.ps1'.
Note: If you don't run this script, the installation will fail.
Note: To confirm automatically next time, use '-y' or consider:
choco feature enable -n allowGlobalConfirmation
Do you want to run the script?([Y]es/[A]ll - yes to all/[N]o/[P]rint): Y
WARNING: Url has SSL/TLS available, switching to HTTPS for download
Downloading yasm 64 bit
from 'https://www.tortall.net/projects/yasm/releases/yasm-1.2.0-win64.exe'
Progress: 100% - Completed download of C:\ProgramData\chocolatey\lib\yasm\tools\yasm.exe (779.5 KB).
Download of yasm.exe (779.5 KB) completed.
C:\ProgramData\chocolatey\lib\yasm\tools\yasm.exe
ERROR: The term 'Write-ChocolateyFailure' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
The install of yasm was NOT successful.
Error while running 'C:\ProgramData\chocolatey\lib\yasm\tools\chocolateyInstall.ps1'.
See log for details.
Chocolatey installed 0/1 packages. 1 packages failed.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
Failures
- yasm (exited -1) - Error while running 'C:\ProgramData\chocolatey\lib\yasm\tools\chocolateyInstall.ps1'.
See log for details.
</code></pre>
<p>I couldn't find a solution on the internet, so I asked here.</p>
|
[
{
"answer_id": 74655131,
"author": "O. Jones",
"author_id": 205608,
"author_profile": "https://Stackoverflow.com/users/205608",
"pm_score": 2,
"selected": true,
"text": "$data_structure = [\n 'Toyota' => ['Vitz', 'Corolla'],\n 'Mazda' => ['Demio', 'SUV'],\n 'Mitsubishi' => ['FH', 'FRR'],\n];\n$json = json_encode( (object) $data_structure );\n make model $data_structure = []; /* empty top-level array */\n$query = $this->db->query('select make, model from key_value_pairs');\nforeach ($query->result() as $row) {\n if (! array_key_exists ($row->make, $data_structure ) {\n /* create an entry for this row if none already exists */\n $data_structure[ $row->make ] = [];\n }\n /* append the model name to the array */\n $data_structure [ $row->make ] [] = $row->model;\n}\n$json = json_encode( (object) $data_structure;\n"
},
{
"answer_id": 74655134,
"author": "Abdusalam mohamed",
"author_id": 12252645,
"author_profile": "https://Stackoverflow.com/users/12252645",
"pm_score": 0,
"selected": false,
"text": "public function all_makes_and_models(){\n \n header('Access-Control-Allow-Origin: *');\n header('Access-Control-Allow-Methods: GET, POST');\n header(\"Access-Control-Allow-Headers: X-Requested-With\");\n \n /**\n {\n \"Toyota\": [\"Vitz\", \"Corolla\"],\n \"Mazda\": [\"Demio\", \"SUV\"],\n \"Mitsubishi\": [\"FH\", \"FRR\"]\n }\n */\n \n \n $car_makes = array(\"Honda\", \"Mazda\", \"Nissan\", \"Subaru\", \"Toyota\", \"Acura\", \"Alfa Romeo\", \"Aston Martin\", \"Audi\", \"BAW\", \"Bentley\", \"BJC\", \"BMW\", \"Brabus\", \"Brilliance\", \"Buick\", \"Cadillac\", \"Changan\", \"Chery\", \"Chevrolet\", \"Chrysler\", \"Citroen\", \"Dacia\", \"Daewoo\", \"DAF\", \"Daihatsu\", \"Daimler\", \"Datsun\", \"Dodge\", \"Dongfeng\", \"Faw\", \"Ferrari\", \"Fiat\", \"Ford\", \"Foton\", \"GAC\", \"Geely\", \"Genesis\", \"Ginaf\", \"GMC\", \"Gonow\", \"Great Wall\", \"Haima\", \"Higer\", \"Hino\", \"Holden\", \"Hummer\", \"Hyundai\", \"Infiniti\", \"International\", \"Isuzu\", \"Iveco\", \"IVM\", \"JAC\", \"Jaguar\", \"Jeep\", \"Jetour\", \"JMC\", \"Joylong\", \"Kia\", \"King Long\", \"Lada\", \"Lamborghini\", \"Lancia\", \"Land Rover\", \"Lexus\", \"Lifan\", \"Lincoln\", \"Lotus\", \"Mahindra\", \"MAN\", \"Maserati\", \"McLaren\", \"Mercedes-Benz\", \"Mercury\", \"MG\", \"Mini\", \"Mitsubishi\", \"Mobius\", \"Morris\", \"Nord\", \"Oldsmobile\", \"Opel\", \"Peugeot\", \"Piaggio\", \"Polaris\", \"Pontiac\", \"Porsche\", \"Proton\", \"Renault\", \"Rolls-Royce\", \"Rover\", \"Saab\", \"Samsung\", \"Sany\", \"Saturn\", \"Scion\", \"Seat\", \"Secodi\", \"Simba\", \"Sinotruk\", \"Skoda\", \"SkyGo\", \"SMA\", \"Smart\", \"SsangYong\", \"Suzuki\", \"T King\", \"Tata\", \"Triumph\", \"TVS\", \"Vauxhall\", \"Vector\", \"Venturi\", \"Volkswagen\", \"Volvo\", \"Zotye\", \"ZX Auto\");\n- // $ca = []\n+ $ca = array();\n...\n foreach ($query->result() as $row)\n {\n- //$rs = $row->valuex;\n- //array_push($ca,$rs);\n \n- //$keyvalues[$rs] = $rs;\n \n- //echo $obj;\n+ array_push($ca[$car_make], $row->valuex)\n\n }\n \n echo '<pre>';\n print_r($ca);\n echo '</pre>';\n }\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655009",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20146868/"
] |
74,655,073
|
<p>I wonder if there is an effective (without loops) method of joining two lists by names of their elements.
I checked <a href="https://stackoverflow.com/q/36665492/5043424">here</a> but this did not help me as well as tried to access names from <code>sapply()</code> as on the answer from <a href="https://stackoverflow.com/q/36665492/5043424">here</a>.</p>
<p>Say I have the following lists:</p>
<pre><code>mylist1 <- list(region1 = 1:3, region2 = 5:7)
> mylist1
$region1
[1] 1 2 3
$region2
[1] 5 6 7
</code></pre>
<p>and</p>
<pre><code>mylist2 <- list(region1 = "#E8C506", region2 = "#F3B508")
$region1
[1] "#E8C506"
$region2
[1] "#F3B508"
</code></pre>
<p>How can I get joined list by element names:</p>
<pre><code>mylist3 <- list(region1 = list(1:3, "#E8C506"), region2 = list(5:7, "#F3B508"))
> mylist3
$region1
$region1[[1]]
[1] 1 2 3
$region1[[2]]
[1] "#E8C506"
$region2
$region2[[1]]
[1] 5 6 7
$region2[[2]]
[1] "#F3B508"
</code></pre>
|
[
{
"answer_id": 74655181,
"author": "harre",
"author_id": 4786466,
"author_profile": "https://Stackoverflow.com/users/4786466",
"pm_score": 3,
"selected": true,
"text": "list c base keys <- unique(c(names(mylist1), names(mylist2)))\nsetNames(mapply(list, mylist1[keys], mylist2[keys], SIMPLIFY = FALSE), keys)\n purrr library(purrr)\n\ncat_lists <- function(list1, list2) { \n\n keys <- unique(c(names(list1), names(list2)))\n map2(list1[keys], list2[keys], list) |>\n set_names(keys) \n\n}\n\nreduce(list(mylist1, mylist2), cat_lists)\n $region1\n$region1[[1]]\n[1] 1 2 3\n\n$region1[[2]]\n[1] \"#E8C506\"\n\n\n$region2\n$region2[[1]]\n[1] 5 6 7\n\n$region2[[2]]\n[1] \"#F3B508\"\n"
},
{
"answer_id": 74655197,
"author": "chris jude",
"author_id": 14579051,
"author_profile": "https://Stackoverflow.com/users/14579051",
"pm_score": 1,
"selected": false,
"text": "list12 <- mapply(list, mylist1 , mylist2 , SIMPLIFY=FALSE)\n"
},
{
"answer_id": 74655244,
"author": "Ritchie Sacramento",
"author_id": 2835261,
"author_profile": "https://Stackoverflow.com/users/2835261",
"pm_score": 2,
"selected": false,
"text": "purrr::transpose() library(purrr)\n\ntranspose(list(mylist1, mylist2))\n\n$region1\n$region1[[1]]\n[1] 1 2 3\n\n$region1[[2]]\n[1] \"#E8C506\"\n\n\n$region2\n$region2[[1]]\n[1] 5 6 7\n\n$region2[[2]]\n[1] \"#F3B508\"\n tranpose() mylist3 <- list(region1 = 1:3, region2 = 5:7, region3 = 5:7)\nmylist4 <- list(region1 = \"#E8C506\", region2 = \"#F3B508\", region4 = \"#F00008\")\n\nl <- list(mylist3, mylist4)\nl_names <- unique(unlist(lapply(l, names)))\nmylist3[l_names] <- mylist3[l_names]\n\ntranspose(list(mylist3, mylist4))\n\n$region1\n$region1[[1]]\n[1] 1 2 3\n\n$region1[[2]]\n[1] \"#E8C506\"\n\n\n$region2\n$region2[[1]]\n[1] 5 6 7\n\n$region2[[2]]\n[1] \"#F3B508\"\n\n\n$region3\n$region3[[1]]\n[1] 5 6 7\n\n$region3[[2]]\nNULL\n\n\n$region4\n$region4[[1]]\nNULL\n\n$region4[[2]]\n[1] \"#F00008\"\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655073",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5043424/"
] |
74,655,075
|
<p>I am building a Rails 5.2 app.
In this app I got three objects:</p>
<p><strong>User</strong></p>
<ul>
<li>Id</li>
<li>Firstname</li>
<li>Lastname</li>
</ul>
<p><strong>Conversation</strong></p>
<ul>
<li>Id</li>
<li>Entity_type</li>
<li>Entity_subtype</li>
</ul>
<p><strong>Assignment</strong></p>
<ul>
<li>Id</li>
<li>User_id</li>
<li>Assignable_id (ID of Conversation)</li>
<li>Assignable_type (Class name of Conversation)</li>
</ul>
<p>One or more Users are connected to a Conversation through Assignments.
I am trying to create a query that checks if two Users are having a direct message Conversation or I need to create a new one automatically.</p>
<p>I have this code and it "works" (I get no error) but it returns a Conversation even though only one of the Users are involved in a Conversation. But I need it to only return a Conversation if Both Users share the Same Conversation, ie they are talking to each other.</p>
<pre><code>Conversation.where(entity_type: "conversation", entity_subtype: "direct").joins(:assignments).where(:assignments => {:user_id => ["cdd3c6be-ac78-46f2-a7ae-7f2299b6fedb", "32117e53-9b2f-49c6-8cc8-3a9eb9003a2e"] })
</code></pre>
|
[
{
"answer_id": 74656875,
"author": "dileep nandanam",
"author_id": 1547872,
"author_profile": "https://Stackoverflow.com/users/1547872",
"pm_score": 1,
"selected": false,
"text": "user_ids = [\"cdd3c6be-ac78-46f2-a7ae-7f2299b6fedb\", \"32117e53-9b2f-49c6-8cc8-3a9eb9003a2e\"]\n\nConversation\n .where(entity_type: \"conversation\", entity_subtype: \"direct\")\n .joins(\"LEFT JOIN assignments as1 ON assignments.assignable_id = conversations.id AND assignments.assignable_type = 'Conversation'\")\n .joins(\"LEFT JOIN assignments as2 ON assignments.assignable_id = conversations.id AND assignments.assignable_type = 'Conversation'\")\n .where('as1.user_id = as2.user_id')\n .where('as1.user_id = ? AND as2.user_id = ?', user_ids[0], user_ids[1])\n"
},
{
"answer_id": 74656969,
"author": "max",
"author_id": 544825,
"author_profile": "https://Stackoverflow.com/users/544825",
"pm_score": 3,
"selected": true,
"text": "class Conversion < ActiveRecord::Base\n def self.between(*users)\n joins(:assignments)\n .group(:id)\n .where(assignments: { user_id: users })\n .having(Assignment.arel_table[:id].count.eq(users.length))\n end\nend\n .eq .gteq Assignment.arel_table[Arel.star]"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655075",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/339067/"
] |
74,655,092
|
<p>I have a templated class, say:</p>
<pre class="lang-cpp prettyprint-override"><code>template <class C, int I>
class A {
A() {};
someMethod(){...};
};
</code></pre>
<p>Now, let's say I have several objects of this class used in my code with different template parameters (classes B,C, and D are some defined classes):</p>
<pre><code>A<B, 1> object1;
A<C, 2> object2;
A<D, 3> object3;
</code></pre>
<p>What I would like to have is a function that returns one of these three objects based on some logic:</p>
<pre><code>A getObject(){
if(condition1)
return object1;
else if(condition2)
return object2;
else
return object3;
}
</code></pre>
<p>However, when I try to compile this, I get <code>error: invalid use of template-name ‘A’ without an argument list</code>, which makes sense, but I don't know which arguments should I provide?
For instance, if I put</p>
<pre><code>A<B, 1> getObject(){
return object1;
}
</code></pre>
<p>then I can only return <code>object1</code>, but not <code>object2</code> or <code>object3</code>.</p>
<p>Ultimately, my goal is to have something like:</p>
<pre><code>A obj = getObject();
...
lot's of code where obj.someMethod() get's called a lot
...
</code></pre>
|
[
{
"answer_id": 74655349,
"author": "463035818_is_not_a_number",
"author_id": 4117728,
"author_profile": "https://Stackoverflow.com/users/4117728",
"pm_score": 3,
"selected": true,
"text": "A<B,1> A<B,2> A<B,3> Foo Bar Moo any variant class A_base {\n virtual void someMethod() = 0;\n virtual ~A() {}\n};\n\ntemplate <class C, int I>\nclass A : public A_base {\n A() {}\n void someMethod() override {/*...*/}\n};\n\nstd::unique_ptr<A_base> getObject() {\n //...\n}\n condition getObject"
},
{
"answer_id": 74655432,
"author": "Rulle",
"author_id": 1008794,
"author_profile": "https://Stackoverflow.com/users/1008794",
"pm_score": 1,
"selected": false,
"text": "A A<B, 1> A<C, 2> A<D, 3> A template <typename F>\nvoid getObject(int i, F f) {\n if (i == 1) {\n f(object1);\n } else if (i == 2) {\n f(object2);\n } else if (i == 3) {\n f(object3);\n }\n}\n getObject(3, [](auto x) {\n std::cout << \"Call someMethod: \" << x.someMethod() << std::endl;\n });\n auto x operator()"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655092",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11617772/"
] |
74,655,103
|
<p>A sequence of data about applicants nameList of type Entrant is given. Each element of the sequence includes the fields School number, Year of entering, Last name. Get data (list of YearSchoolStat values) about the number of different schools that applicants graduated from for each year present in the source data. The YearSchoolStat type includes the Year of entering, Number of Schools fields. The list of YearSchoolStat values must be sorted in ascending order of the number of schools, and for matching values, in ascending order of the year number. Example of data provided and expected results:</p>
<pre><code> nameList: new[]
{
new Entrant {LastName = "Name", SchoolNumber = 12, Year = 2019},
new Entrant {LastName = "Name", SchoolNumber = 12, Year = 2019},
new Entrant {LastName = "Name", SchoolNumber = 13, Year = 2019},
new Entrant {LastName = "Name", SchoolNumber = 14, Year = 2019},
new Entrant {LastName = "Name", SchoolNumber = 15, Year = 2019},
new Entrant {LastName = "Name", SchoolNumber = 12, Year = 2018},
new Entrant {LastName = "Name", SchoolNumber = 12, Year = 2018},
new Entrant {LastName = "Name", SchoolNumber = 13, Year = 2018},
new Entrant {LastName = "Name", SchoolNumber = 12, Year = 2017},
new Entrant {LastName = "Name", SchoolNumber = 12, Year = 2017}
},
expected: new[]
{
new YearSchoolStat {NumberOfSchools = 1, Year = 2017},
new YearSchoolStat {NumberOfSchools = 2, Year = 2018},
new YearSchoolStat {NumberOfSchools = 4, Year = 2019}
});
</code></pre>
<p>I'm trying to group by SchoolNumber and Year and then for the number of schools I want to use something like Count() but it's not permitted.</p>
<pre><code>var result = nameList.GroupBy(c => new
{
c.SchoolNumber,
c.Year,
}).Select(ss => new YearSchoolStat()
{
Year = ss.Key.Year,
NumberOfSchools = ss.Key.SchoolNumber
});
</code></pre>
<p>What is wrong with my approach and what else I should try?</p>
|
[
{
"answer_id": 74655230,
"author": "Roman Ryzhiy",
"author_id": 7592390,
"author_profile": "https://Stackoverflow.com/users/7592390",
"pm_score": 1,
"selected": true,
"text": "var result = nameList\n .GroupBy(c => c.Year)\n .Select(ss => new YearSchoolStat()\n {\n Year = ss.Key,\n NumberOfSchools = ss.Count() // Here is the magic\n });\n"
},
{
"answer_id": 74655380,
"author": "Mehmet Topçu",
"author_id": 7404680,
"author_profile": "https://Stackoverflow.com/users/7404680",
"pm_score": 2,
"selected": false,
"text": "{NumberOfSchools = 1, Year = 2017},\n{NumberOfSchools = 2, Year = 2018},\n{NumberOfSchools = 4, Year = 2019}\n var result = nameList.GroupBy(c => new\n {\n c.Year, c.SchoolNumber\n }).GroupBy(c => new\n {\n c.Key.Year\n }).Select(ss => new YearSchoolStat()\n {\n Year = ss.Key.Year,\n NumberOfSchools = ss.Count()\n }); \n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655103",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20569938/"
] |
74,655,125
|
<p>I am a new learner to Java; I want to run a class method inside a function thats not within the class scope inside VSC. However, my compiler tells me I have to remove the last curly braces from the class and require to instantiate the function as a method inside the class.</p>
<p>How do I use these in a dependent way?</p>
<p>For example:</p>
<pre><code>import java.lang.Integer;
public class sortArray{
public static void reorder(int[] T, int pos, int min){
int i = 1;
//int[] temp = new int[T.length];
for( i = 1; i < T.length; i++){
pos = i;
min = T[i];
for(int j = i+1; j < T.length; i++){
if(Integer.compare(T[j], min) < 0){
pos=j;
min=T[j];
T[pos] = T[i];
T[i] = min; } }}}}
public static void read(){
// run the class inside here
}
</code></pre>
<p>I come from a python background so best I explain from that background and correct me on the difference.</p>
<p>For example:</p>
<pre><code>class sortArray:
....
def read():
array = sortArray()
reorder = array.reorder([1, 2, 3], 1, 1)
return reorder
</code></pre>
|
[
{
"answer_id": 74655230,
"author": "Roman Ryzhiy",
"author_id": 7592390,
"author_profile": "https://Stackoverflow.com/users/7592390",
"pm_score": 1,
"selected": true,
"text": "var result = nameList\n .GroupBy(c => c.Year)\n .Select(ss => new YearSchoolStat()\n {\n Year = ss.Key,\n NumberOfSchools = ss.Count() // Here is the magic\n });\n"
},
{
"answer_id": 74655380,
"author": "Mehmet Topçu",
"author_id": 7404680,
"author_profile": "https://Stackoverflow.com/users/7404680",
"pm_score": 2,
"selected": false,
"text": "{NumberOfSchools = 1, Year = 2017},\n{NumberOfSchools = 2, Year = 2018},\n{NumberOfSchools = 4, Year = 2019}\n var result = nameList.GroupBy(c => new\n {\n c.Year, c.SchoolNumber\n }).GroupBy(c => new\n {\n c.Key.Year\n }).Select(ss => new YearSchoolStat()\n {\n Year = ss.Key.Year,\n NumberOfSchools = ss.Count()\n }); \n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655125",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18248287/"
] |
74,655,135
|
<p>I am using <a href="https://camelot-py.readthedocs.io/en/master/" rel="nofollow noreferrer">Camelot</a> to extract tables from PDF files. While this works very well, it extracts the text only, it does not extract the hyperlinks that are embedded in the tables.</p>
<p>Is there a way of using Camelot or a similar package to extract table text and hyperlinks embedded within tables?</p>
<p>Thanks!</p>
|
[
{
"answer_id": 74655230,
"author": "Roman Ryzhiy",
"author_id": 7592390,
"author_profile": "https://Stackoverflow.com/users/7592390",
"pm_score": 1,
"selected": true,
"text": "var result = nameList\n .GroupBy(c => c.Year)\n .Select(ss => new YearSchoolStat()\n {\n Year = ss.Key,\n NumberOfSchools = ss.Count() // Here is the magic\n });\n"
},
{
"answer_id": 74655380,
"author": "Mehmet Topçu",
"author_id": 7404680,
"author_profile": "https://Stackoverflow.com/users/7404680",
"pm_score": 2,
"selected": false,
"text": "{NumberOfSchools = 1, Year = 2017},\n{NumberOfSchools = 2, Year = 2018},\n{NumberOfSchools = 4, Year = 2019}\n var result = nameList.GroupBy(c => new\n {\n c.Year, c.SchoolNumber\n }).GroupBy(c => new\n {\n c.Key.Year\n }).Select(ss => new YearSchoolStat()\n {\n Year = ss.Key.Year,\n NumberOfSchools = ss.Count()\n }); \n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655135",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10744269/"
] |
74,655,138
|
<p>I have this list:</p>
<pre class="lang-dart prettyprint-override"><code>List<dynamic> activityDays = [];
</code></pre>
<p>And this code:</p>
<pre><code>getItems(AsyncSnapshot<QuerySnapshot> snapshot) {
if (widget.user.uid.isNotEmpty) {
// ignore: missing_return
snapshot.data.documents.map<Column>((f) {
if (f.documentID == widget.currentList.keys.elementAt(widget.i)) {
f.data.forEach((a, b) {
if (a == "activities") {
List<dynamic> markMap = f.data['activities'];
for (var element in markMap) {
activityDays.add(element['days']);
}
}
});
}
}).toList();
</code></pre>
<p><a href="https://i.stack.imgur.com/pk0TC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pk0TC.png" alt="enter image description here" /></a></p>
<p>And printing the list gives the result:
<strong>[[M, T, L], [T, T, L]]</strong></p>
<p>But when I am trying to get an item from the list it gives me error:
<strong>type 'List<Object?>' is not a subtype of type 'List'</strong></p>
<p>I am using it like this:</p>
<pre class="lang-dart prettyprint-override"><code>GroupedCheckbox(
itemList: activityDays.elementAt(i),
checkedItemList: checkedItemList,
onChanged: (itemList) {
setState(() {
selectedItemList = itemList;
print('SELECTED ITEM LIST $itemList');
});
},
orientation: CheckboxOrientation.VERTICAL,
checkColor: Colors.blue,
activeColor: Colors.red,
),
</code></pre>
<p>What am I doing wrong?</p>
|
[
{
"answer_id": 74655230,
"author": "Roman Ryzhiy",
"author_id": 7592390,
"author_profile": "https://Stackoverflow.com/users/7592390",
"pm_score": 1,
"selected": true,
"text": "var result = nameList\n .GroupBy(c => c.Year)\n .Select(ss => new YearSchoolStat()\n {\n Year = ss.Key,\n NumberOfSchools = ss.Count() // Here is the magic\n });\n"
},
{
"answer_id": 74655380,
"author": "Mehmet Topçu",
"author_id": 7404680,
"author_profile": "https://Stackoverflow.com/users/7404680",
"pm_score": 2,
"selected": false,
"text": "{NumberOfSchools = 1, Year = 2017},\n{NumberOfSchools = 2, Year = 2018},\n{NumberOfSchools = 4, Year = 2019}\n var result = nameList.GroupBy(c => new\n {\n c.Year, c.SchoolNumber\n }).GroupBy(c => new\n {\n c.Key.Year\n }).Select(ss => new YearSchoolStat()\n {\n Year = ss.Key.Year,\n NumberOfSchools = ss.Count()\n }); \n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655138",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4517263/"
] |
74,655,141
|
<p>I have a c# program that converts/re-interpret unmanaged type to <code>ulong</code> on x64 machine:</p>
<pre><code>public static unsafe ulong ToUInt64<T>(T value) where T : unmanaged
{
if(sizeof(T) > sizeof(ulong))
throw new InvalidOperationException("Can't convert this type to UInt64");
return *(ulong*)&value;
}
</code></pre>
<p>Usage:</p>
<pre><code>int a = 123;
ulong b = ToUInt64(a);
Console.WriteLine(b); // returns 123 as expected.
</code></pre>
<p>However, I'm not sure if this is 100% safe.
Namely, will the runtime always allocate 8 bytes and zero the memory if a variable have a smaller size? Can I get <code>AccessViolationException</code> or read some garbage memory into the ulong under some situation?</p>
|
[
{
"answer_id": 74655597,
"author": "shingo",
"author_id": 6196568,
"author_profile": "https://Stackoverflow.com/users/6196568",
"pm_score": 2,
"selected": true,
"text": "static void Main()\n{\n var j = Test(0x12345678);\n ulong b = ToUInt64((byte)123);\n Console.WriteLine(b); // returns 123 as expected.\n Console.WriteLine(j);\n}\n\npublic unsafe static short Test(int value)\n{\n return (short)(value - 1);\n}\n\npublic static unsafe ulong ToUInt64<T>(T value) where T : unmanaged\n{\n return *(ulong*)&value;\n}\n 00007FFDD6148D64 mov dword ptr [rsp+24h],7Bh\n00007FFDD6148D6C mov rcx,qword ptr [rsp+24h]\n"
},
{
"answer_id": 74666378,
"author": "Sardelka",
"author_id": 19458156,
"author_profile": "https://Stackoverflow.com/users/19458156",
"pm_score": 0,
"selected": false,
"text": "int* a = stackalloc int[2];\na[0] = a[1] = 123;\nConsole.WriteLine(*(ulong*)&a[0]); // 528280977531\n public static unsafe ulong ToUInt64<T>(T value) where T : unmanaged\n{\n if (sizeof(T) > sizeof(TResult))\n throw new InvalidCastException(\"Can't cast from data type with larger size\");\n ulong result = 0;\n *(T*)&result = value;\n return result;\n}\n public static unsafe TResult UnmanagedCast<T,TResult>(T value) where T : unmanaged where TResult : unmanaged\n{\n if (sizeof(T) > sizeof(TResult))\n throw new InvalidCastException(\"Can't cast from data type with larger size\");\n TResult result = default;\n *(T*)&result = value;\n return result;\n}\n UnmanagedCast<int,ulong>(123)\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655141",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19458156/"
] |
74,655,168
|
<p>I have a column with timestamps formatted like this printing one row it looks like this for example:</p>
<pre><code>"2022-09-21 02:02:03 UTC"
</code></pre>
<p>There are many rows that have the same timestamp, but I want another column with the first timestamp after a specific times based on a vector that looks like this:</p>
<pre><code>start_1 <- strptime("07:15:00, format= "%H:%M:%S")
start_2 <- strptime("09:15:00, format= "%H:%M:%S")
</code></pre>
<p>Based on my start_1 timestamp I want to check in my df below which is the first timestamp after start_1 and mark that one in another column called start_datetime.</p>
<p>I only want to mark the first timestamp after the start in my dataset, this is crucial for what I am trying to do, since many of the rows have exactly the same timestamp.</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: left;">Datetime</th>
<th style="text-align: center;">start_datetime</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">2022-09-21 07:02:03</td>
<td style="text-align: center;">NA</td>
</tr>
<tr>
<td style="text-align: left;">2022-09-21 07:02:03</td>
<td style="text-align: center;">NA</td>
</tr>
<tr>
<td style="text-align: left;">2022-09-21 07:14:03</td>
<td style="text-align: center;">NA</td>
</tr>
<tr>
<td style="text-align: left;">2022-09-21 07:16:03</td>
<td style="text-align: center;">07:16</td>
</tr>
<tr>
<td style="text-align: left;">2022-09-21 07:16:03</td>
<td style="text-align: center;">NA</td>
</tr>
<tr>
<td style="text-align: left;">2022-09-21 09:19:03</td>
<td style="text-align: center;">09:19</td>
</tr>
</tbody>
</table>
</div>
<p>I've explored multiple options, but so far I've been struggling to find a solution.</p>
|
[
{
"answer_id": 74655597,
"author": "shingo",
"author_id": 6196568,
"author_profile": "https://Stackoverflow.com/users/6196568",
"pm_score": 2,
"selected": true,
"text": "static void Main()\n{\n var j = Test(0x12345678);\n ulong b = ToUInt64((byte)123);\n Console.WriteLine(b); // returns 123 as expected.\n Console.WriteLine(j);\n}\n\npublic unsafe static short Test(int value)\n{\n return (short)(value - 1);\n}\n\npublic static unsafe ulong ToUInt64<T>(T value) where T : unmanaged\n{\n return *(ulong*)&value;\n}\n 00007FFDD6148D64 mov dword ptr [rsp+24h],7Bh\n00007FFDD6148D6C mov rcx,qword ptr [rsp+24h]\n"
},
{
"answer_id": 74666378,
"author": "Sardelka",
"author_id": 19458156,
"author_profile": "https://Stackoverflow.com/users/19458156",
"pm_score": 0,
"selected": false,
"text": "int* a = stackalloc int[2];\na[0] = a[1] = 123;\nConsole.WriteLine(*(ulong*)&a[0]); // 528280977531\n public static unsafe ulong ToUInt64<T>(T value) where T : unmanaged\n{\n if (sizeof(T) > sizeof(TResult))\n throw new InvalidCastException(\"Can't cast from data type with larger size\");\n ulong result = 0;\n *(T*)&result = value;\n return result;\n}\n public static unsafe TResult UnmanagedCast<T,TResult>(T value) where T : unmanaged where TResult : unmanaged\n{\n if (sizeof(T) > sizeof(TResult))\n throw new InvalidCastException(\"Can't cast from data type with larger size\");\n TResult result = default;\n *(T*)&result = value;\n return result;\n}\n UnmanagedCast<int,ulong>(123)\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655168",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17143533/"
] |
74,655,184
|
<p>I have a simple function to return True or False when a condition is met. But the return statement is not functioning as I expected. Could anyone help me out to point out the mistake I am making.</p>
<pre><code>graph = {
'f': ['g', 'i'],
'g': ['h'],
'h': [],
'i': ['g', 'k'],
'j': ['i'],
'k': []
}
def hasPath(graph,source,des):
arr = graph[source]
if des in arr:
print('Yes')
return True
for i in arr:
hasPath(graph,i,des)
return False
print(hasPath(graph,'f','k'))
</code></pre>
<p>This code return False but prints the statment Yes. I am not sure why return statement is not being executed after the Print statement.</p>
|
[
{
"answer_id": 74655341,
"author": "Agni",
"author_id": 8106804,
"author_profile": "https://Stackoverflow.com/users/8106804",
"pm_score": 3,
"selected": true,
"text": "hasPath arr des arr print return False False hasPath return True arr hasPath def hasPath(graph, source, des):\n arr = graph[source]\n if des in arr:\n print('Yes')\n return True\n for i in arr:\n if hasPath(graph, i, des):\n return True\n return False\n hasPath des arr False print(hasPath(graph, 'f', 'k')) Yes True"
},
{
"answer_id": 74655379,
"author": "user56700",
"author_id": 11355926,
"author_profile": "https://Stackoverflow.com/users/11355926",
"pm_score": 1,
"selected": false,
"text": "graph = {\n'f': ['g', 'i'],\n'g': ['h'],\n'h': [],\n'i': ['g', 'k'],\n'j': ['i'],\n'k': []\n}\n\ndef hasPath(graph,source,des):\n arr = graph[source]\n if des in arr:\n print('Yes')\n return True\n for i in arr:\n if hasPath(graph,i,des): return True\n return False\n\nprint(hasPath(graph,'f','k'))\n Yes\nTrue\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655184",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15051878/"
] |
74,655,193
|
<p>I have a dictionary with lists as values and i want to concatenate lists of certain keys to one and store it in another dictionary.</p>
<p>Right now i always do this:</p>
<pre><code>plot_history = {}
for key in history.keys():
plot_key = key[3:]
if plot_key in scores:
if plot_key in plot_history.keys():
plot_history[plot_key].extend(history[key])
else:
plot_history[plot_key] = history[key]
</code></pre>
<p>Example for history:</p>
<pre><code>{'tl_loss': [1.3987799882888794, 1.0936943292617798], 'tl_categorical_accuracy': [0.31684982776641846, 0.3901098966598511], 'tl_val_loss': [1.0042442083358765, 0.7404149174690247], 'tl_val_categorical_accuracy': [0.3589743673801422, 0.5256410241127014], 'ft_loss': [1.6525564193725586, 1.1816378831863403], 'ft_categorical_accuracy': [0.5370370149612427, 0.4157509207725525], 'ft_val_loss': [0.9936744570732117, 1.1621183156967163], 'ft_val_categorical_accuracy': [0.36538460850715637, 0.3910256326198578]}
</code></pre>
<p>Example for scores: ["loss", "val_loss"]</p>
<p>And i try to get this:</p>
<pre><code>{'loss': [1.3987799882888794, 1.0936943292617798, 1.6525564193725586, 1.1816378831863403], 'val_loss': [1.0042442083358765, 0.7404149174690247, 0.9936744570732117, 1.1621183156967163]}
</code></pre>
<p>But i wonder if there's a more elegant way.
Thank you for any suggestions.</p>
|
[
{
"answer_id": 74655391,
"author": "RJ Adriaansen",
"author_id": 11380795,
"author_profile": "https://Stackoverflow.com/users/11380795",
"pm_score": 2,
"selected": true,
"text": "plot_history = {score: [history[f\"tl_{score}\"], history[f\"ft_{score}\"]] for score in scores}\n"
},
{
"answer_id": 74655471,
"author": "Tzane",
"author_id": 14536215,
"author_profile": "https://Stackoverflow.com/users/14536215",
"pm_score": 0,
"selected": false,
"text": "defaultdict from collections import defaultdict\n\nplot_history_dd = defaultdict(list)\nfor key in history.keys():\n plot_key = key[3:]\n if plot_key in scores:\n plot_history_dd[plot_key].extend(history[key])\n\n# Convert to dict for convenience\nplot_history_dd = dict(plot_history_dd)\nprint(plot_history_dd)\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655193",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20665761/"
] |
74,655,223
|
<p>I´m using flutter version 3.4.0 with cloud_firestore version ^4.1.0 and I´m getting this error:
`Execution failed for task ':app:processDebugMainManifest'</p>
<blockquote>
<p>Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in library [:cloud_firestore]`</p>
</blockquote>
<p>How should I change version of the minSdk from 16 to 19?</p>
<p>This is my defaultConfig:
`</p>
<pre><code> defaultConfig {
applicationId "com.example.example"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
</code></pre>
<p>`</p>
|
[
{
"answer_id": 74655391,
"author": "RJ Adriaansen",
"author_id": 11380795,
"author_profile": "https://Stackoverflow.com/users/11380795",
"pm_score": 2,
"selected": true,
"text": "plot_history = {score: [history[f\"tl_{score}\"], history[f\"ft_{score}\"]] for score in scores}\n"
},
{
"answer_id": 74655471,
"author": "Tzane",
"author_id": 14536215,
"author_profile": "https://Stackoverflow.com/users/14536215",
"pm_score": 0,
"selected": false,
"text": "defaultdict from collections import defaultdict\n\nplot_history_dd = defaultdict(list)\nfor key in history.keys():\n plot_key = key[3:]\n if plot_key in scores:\n plot_history_dd[plot_key].extend(history[key])\n\n# Convert to dict for convenience\nplot_history_dd = dict(plot_history_dd)\nprint(plot_history_dd)\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655223",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14448339/"
] |
74,655,251
|
<p>I am designing a string based game where the real time positions of characters are represented as a <em>string</em> as follows:
<code> -----A-----o-----</code>
I am changing the position of the character "A" based upon user keyboard inputs
eg:
updated position:
<code> --------A--o-----</code></p>
<p>I don't want to print the <em>string</em> line by line as It gets updated instead I want to modify it every time in the same place when being output in command line, as the constraint I am working with is :</p>
<p>The entire game map should run on a single line on the command line -
changing the state of the game should not spawn a new line every time.</p>
|
[
{
"answer_id": 74655391,
"author": "RJ Adriaansen",
"author_id": 11380795,
"author_profile": "https://Stackoverflow.com/users/11380795",
"pm_score": 2,
"selected": true,
"text": "plot_history = {score: [history[f\"tl_{score}\"], history[f\"ft_{score}\"]] for score in scores}\n"
},
{
"answer_id": 74655471,
"author": "Tzane",
"author_id": 14536215,
"author_profile": "https://Stackoverflow.com/users/14536215",
"pm_score": 0,
"selected": false,
"text": "defaultdict from collections import defaultdict\n\nplot_history_dd = defaultdict(list)\nfor key in history.keys():\n plot_key = key[3:]\n if plot_key in scores:\n plot_history_dd[plot_key].extend(history[key])\n\n# Convert to dict for convenience\nplot_history_dd = dict(plot_history_dd)\nprint(plot_history_dd)\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655251",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20615351/"
] |
74,655,261
|
<p>I use PostgreSQL</p>
<p>I can run a single query per day, but it will take a long time to go through every day.</p>
<p>The "zone" and "reader" also changes, so to run single queries every time will keep me up until late.
If at best I can only change the "reader" and "zone" every time it would help. The main "PAIN" I have, is to change the dates every time. It will be from 2022 11 18 18:00 to 2022 12 01 19:00.</p>
<p>P.S - I'm new to SQL, please be gentle :)</p>
<p>My current query:</p>
<pre><code>select * from vw_tracking_resource_events
where "when_enter_dt_timezone" between '2022 11 18 18:00:00' and '2022 11 18 19:00:00'
and "zone" = '085 Level'
and "site" = 'MK'
and "reader" = 'RV Shaft'
and "group" = 'Lamp'
</code></pre>
|
[
{
"answer_id": 74655391,
"author": "RJ Adriaansen",
"author_id": 11380795,
"author_profile": "https://Stackoverflow.com/users/11380795",
"pm_score": 2,
"selected": true,
"text": "plot_history = {score: [history[f\"tl_{score}\"], history[f\"ft_{score}\"]] for score in scores}\n"
},
{
"answer_id": 74655471,
"author": "Tzane",
"author_id": 14536215,
"author_profile": "https://Stackoverflow.com/users/14536215",
"pm_score": 0,
"selected": false,
"text": "defaultdict from collections import defaultdict\n\nplot_history_dd = defaultdict(list)\nfor key in history.keys():\n plot_key = key[3:]\n if plot_key in scores:\n plot_history_dd[plot_key].extend(history[key])\n\n# Convert to dict for convenience\nplot_history_dd = dict(plot_history_dd)\nprint(plot_history_dd)\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655261",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20665852/"
] |
74,655,327
|
<p>On my website, I show some products with a condition - if the product has a <code>test</code> tag:</p>
<pre><code>{% if product.tags contains 'test' %}
// render product
{% endif %}
</code></pre>
<p>And this way I get only some products, but the native product filter still displays the count of all products. I'll check it this way:</p>
<pre><code>{% for filter in collection.filters %}
{% for value in filter.values %}
{{ value.count }},
{% endfor %}
{% endfor %}
</code></pre>
<p>And like I said, I get the full amount of products. But I want to get only the number of products that I displayed by condition. Can you please tell me how to do this? Thank you!</p>
|
[
{
"answer_id": 74655391,
"author": "RJ Adriaansen",
"author_id": 11380795,
"author_profile": "https://Stackoverflow.com/users/11380795",
"pm_score": 2,
"selected": true,
"text": "plot_history = {score: [history[f\"tl_{score}\"], history[f\"ft_{score}\"]] for score in scores}\n"
},
{
"answer_id": 74655471,
"author": "Tzane",
"author_id": 14536215,
"author_profile": "https://Stackoverflow.com/users/14536215",
"pm_score": 0,
"selected": false,
"text": "defaultdict from collections import defaultdict\n\nplot_history_dd = defaultdict(list)\nfor key in history.keys():\n plot_key = key[3:]\n if plot_key in scores:\n plot_history_dd[plot_key].extend(history[key])\n\n# Convert to dict for convenience\nplot_history_dd = dict(plot_history_dd)\nprint(plot_history_dd)\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655327",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13573444/"
] |
74,655,357
|
<p>I want to do a search in my Database, that gives me the id of all fields, that a given string would contain. So if I have the string "a, b, c" and the fields a and b i want them to be shown. Is there an easy way to do it with SQL? My mind seems to be stuck right now.</p>
<p>I could use the LIKE operator on every possible substring of my string or just compare strings without sql, but I'm hoping for an easier, better solution.</p>
<p>For example:
if I have my table like this:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>id</th>
<th>substring</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>'hello'</td>
</tr>
<tr>
<td>2</td>
<td>'two'</td>
</tr>
<tr>
<td>3</td>
<td>'test'</td>
</tr>
</tbody>
</table>
</div>
<p>And an input-string like: "hello, this is a test"</p>
<p>I want to get the information, that my input sentence contains the substrings with the ids 1 and 3</p>
|
[
{
"answer_id": 74655391,
"author": "RJ Adriaansen",
"author_id": 11380795,
"author_profile": "https://Stackoverflow.com/users/11380795",
"pm_score": 2,
"selected": true,
"text": "plot_history = {score: [history[f\"tl_{score}\"], history[f\"ft_{score}\"]] for score in scores}\n"
},
{
"answer_id": 74655471,
"author": "Tzane",
"author_id": 14536215,
"author_profile": "https://Stackoverflow.com/users/14536215",
"pm_score": 0,
"selected": false,
"text": "defaultdict from collections import defaultdict\n\nplot_history_dd = defaultdict(list)\nfor key in history.keys():\n plot_key = key[3:]\n if plot_key in scores:\n plot_history_dd[plot_key].extend(history[key])\n\n# Convert to dict for convenience\nplot_history_dd = dict(plot_history_dd)\nprint(plot_history_dd)\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655357",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17020331/"
] |
74,655,384
|
<p>i need to delete the object real-time from frontend as well as backend my, The object gets deleted from the backend instantly but it do not reflects in the frontend till the page is refreshed</p>
<p>//delete component</p>
<pre><code>deleteStory(id : string){
console.log(id)
this.storyapiService.deleteStory(id).subscribe();
}
</code></pre>
<p>service.ts</p>
<pre><code>deleteStory(id: string): Observable<number>{
return this.http.delete<number>(this.API_URL +id);
}
</code></pre>
<p>//html</p>
<pre><code><button class="btn btn-primary" (click)="deleteStory(story.id)" style="margin-left:5px">Delete </button>
</code></pre>
|
[
{
"answer_id": 74656713,
"author": "dacx",
"author_id": 11264793,
"author_profile": "https://Stackoverflow.com/users/11264793",
"pm_score": 0,
"selected": false,
"text": "deleteStory()"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655384",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20622036/"
] |
74,655,392
|
<p>suppose i have a dataframe</p>
<blockquote>
<p>df = pd.DataFrame({"age" : [0, 5, 10, 15, 20], "income": [5, 13, 23, 18, 12]})</p>
<pre><code> age income
0 0 5
1 5 13
2 10 23
3 15 18
4 20 12
</code></pre>
</blockquote>
<p>i want to iterate through df["income"] and calculate the sumproduct as follows (example for age 15): 18+23*<em>(15-10)+13*(15-5)+5</em>*(15-0) = 338.</p>
<p>more generic: income[3] + income[2] * ( age[3] - age[2] ) + income[1] * ( age[3] - age[1] ) + income[0] * (age[3] - age[0] )</p>
<p>I am struggling to formulate the age relative to the current iteration of age ( age[x] - age[y] ) in a generic way to use in a list comprehension or formula.</p>
<p>edit: the actual operation I want to apply is</p>
<p><code>income[3 ] + income[2]* interest ** ( age[3] - age[2] ) + income[1]*interest ** (age[3] - age[1] ...</code></p>
<pre><code>exampe from above: 18+23*1.03 ** (15-10)+13*1.03 ** (15-5)+5*1.03 **(15-0) = 69,92
</code></pre>
<p>interest = 1.03</p>
<p>ANSWERED thanks to jezrael & mozway</p>
|
[
{
"answer_id": 74655585,
"author": "AschenAI",
"author_id": 20665111,
"author_profile": "https://Stackoverflow.com/users/20665111",
"pm_score": 0,
"selected": false,
"text": "sumproducts = [income[x] + income[x+1] * (age[x] - age[x+1]) + income[x+2] * (age[x] - age[x+2]) + income[x+3] * (age[x] - age[x+3]) for x in range(len(df[\"age\"]))]\n def calculate_sumproduct(row):\n x = row[\"age\"]\n income = row[\"income\"]\n return income[x] + income[x+1] * (age[x] - age[x+1]) + income[x+2] * (age[x] - age[x+2]) + income[x+3] * (age[x] - age[x+3])\n\nsumproducts = df.apply(calculate_sumproduct, axis=1)\n df[\"sumproduct\"] = sumproducts\n"
},
{
"answer_id": 74655677,
"author": "jezrael",
"author_id": 2901002,
"author_profile": "https://Stackoverflow.com/users/2901002",
"pm_score": 2,
"selected": false,
"text": "Numpy df = pd.DataFrame({\"age\" : [0, 5, 10, 15, 20], \"income\": [5, 13, 23, 18, 12]})\n\ninterest = 1.03\nage = df['age'].to_numpy()\n arr = interest ** (age[:, None] - age ) \nprint (arr)\n[[1. 0.86260878 0.74409391 0.64186195 0.55367575]\n [1.15927407 1. 0.86260878 0.74409391 0.64186195]\n [1.34391638 1.15927407 1. 0.86260878 0.74409391]\n [1.55796742 1.34391638 1.15927407 1. 0.86260878]\n [1.80611123 1.55796742 1.34391638 1.15927407 1. ]]\n arr = np.where(np.triu(np.ones(arr.shape, dtype=bool)), 0, arr)\nprint (arr)\n[[0. 0. 0. 0. 0. ]\n [1.15927407 0. 0. 0. 0. ]\n [1.34391638 1.15927407 0. 0. 0. ]\n [1.55796742 1.34391638 1.15927407 0. 0. ]\n [1.80611123 1.55796742 1.34391638 1.15927407 0. ]]\n np.fill_diagonal(arr, 1)\nprint (arr)\n[[1. 0. 0. 0. 0. ]\n [1.15927407 1. 0. 0. 0. ]\n [1.34391638 1.15927407 1. 0. 0. ]\n [1.55796742 1.34391638 1.15927407 1. 0. ]\n [1.80611123 1.55796742 1.34391638 1.15927407 1. ]]\n print (arr * df['income'].to_numpy())\n[[ 5. 0. 0. 0. 0. ]\n [ 5.79637037 13. 0. 0. 0. ]\n [ 6.7195819 15.07056297 23. 0. 0. ]\n [ 7.78983708 17.47091293 26.66330371 18. 0. ]\n [ 9.03055617 20.25357642 30.91007672 20.86693334 12. ]]\n\n\ndf['new'] = (arr * df['income'].to_numpy()).sum(axis=1)\nprint (df) age income new\n0 0 5 5.000000\n1 5 13 18.796370\n2 10 23 44.790145\n3 15 18 69.924054\n4 20 12 93.061143\n apply df = pd.DataFrame({\"age\" : [0, 5, 10, 15, 20], \"income\": [5, 13, 23, 18, 12]})\ndf = pd.concat([df] * 1000, ignore_index=True)\n\n\nIn [292]: %%timeit\n ...: age = df['age'].to_numpy()\n ...: \n ...: arr = interest ** (age[:, None] - age ) \n ...: arr = np.where(np.triu(np.ones(arr.shape, dtype=bool)), 0, arr)\n ...: np.fill_diagonal(arr, 1)\n ...: df['new'] = (arr * df['income'].to_numpy()).sum(axis=1)\n ...: \n1.39 s ± 69.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n\nIn [293]: %%timeit\n ...: df['sumproduct'] = (df['age'].expanding().apply(lambda x: sum(df.loc[:x.index[-1], 'income'] * interest**(x.iloc[-1]-x))))\n ...: \n5.13 s ± 411 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
},
{
"answer_id": 74655769,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 2,
"selected": true,
"text": "18+(18+23+13+5)*15-(23+13+5)*(10+5+0) 18+(18+23+13+5)*15-(23+13+5)*(10+5+0) sumproduct(n) = (income\n + (n-1)*sum(age[:n-1]*income[:n-1])\n - sum(age[:n-1]*income[:n-1])\n )\n df['sumproduct'] = (df['income']\n .add(df['age'].mul(df['income'].cumsum().shift(fill_value=0)))\n .sub(df['age'].mul(df['income']).cumsum().shift(fill_value=0))\n)\n age income sumproduct\n0 0 5 5\n1 5 13 38\n2 10 23 138\n3 15 18 338\n4 20 12 627\n expanding df['sumproduct'] = (df['age'].expanding()\n .apply(lambda x: sum(df.loc[:x.index[-1], 'income'] * interest**(x.iloc[-1]-x)))\n)\n age income sumproduct\n0 0 5 5.000000\n1 5 13 18.796370\n2 10 23 44.790145\n3 15 18 69.924054\n4 20 12 93.061143\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655392",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20339178/"
] |
74,655,399
|
<p>Using the below SQL but getting error in case statement inside where clause.</p>
<pre><code>create procedure MyProcedure
@ApprovalFilter as nvarchar(50),
@BothPendingAndApproved as nvarchar(50)
Select
*
from
myTable
Where
data = "A"
and
case @BothPendingAndApproved
when 'Both' then ApprovalStatus <> 'Rejected'
when 'Specific' then ApprovalStatus like @ApprovalFilter
end
and
Data2="B"
End
</code></pre>
<p>Why this part is failing?</p>
<pre><code> case @BothPendingAndApproved
when 'Both' then ApprovalStatus <> 'Rejected'
when 'Specific' then ApprovalStatus like @ApprovalFilter
end
</code></pre>
|
[
{
"answer_id": 74655585,
"author": "AschenAI",
"author_id": 20665111,
"author_profile": "https://Stackoverflow.com/users/20665111",
"pm_score": 0,
"selected": false,
"text": "sumproducts = [income[x] + income[x+1] * (age[x] - age[x+1]) + income[x+2] * (age[x] - age[x+2]) + income[x+3] * (age[x] - age[x+3]) for x in range(len(df[\"age\"]))]\n def calculate_sumproduct(row):\n x = row[\"age\"]\n income = row[\"income\"]\n return income[x] + income[x+1] * (age[x] - age[x+1]) + income[x+2] * (age[x] - age[x+2]) + income[x+3] * (age[x] - age[x+3])\n\nsumproducts = df.apply(calculate_sumproduct, axis=1)\n df[\"sumproduct\"] = sumproducts\n"
},
{
"answer_id": 74655677,
"author": "jezrael",
"author_id": 2901002,
"author_profile": "https://Stackoverflow.com/users/2901002",
"pm_score": 2,
"selected": false,
"text": "Numpy df = pd.DataFrame({\"age\" : [0, 5, 10, 15, 20], \"income\": [5, 13, 23, 18, 12]})\n\ninterest = 1.03\nage = df['age'].to_numpy()\n arr = interest ** (age[:, None] - age ) \nprint (arr)\n[[1. 0.86260878 0.74409391 0.64186195 0.55367575]\n [1.15927407 1. 0.86260878 0.74409391 0.64186195]\n [1.34391638 1.15927407 1. 0.86260878 0.74409391]\n [1.55796742 1.34391638 1.15927407 1. 0.86260878]\n [1.80611123 1.55796742 1.34391638 1.15927407 1. ]]\n arr = np.where(np.triu(np.ones(arr.shape, dtype=bool)), 0, arr)\nprint (arr)\n[[0. 0. 0. 0. 0. ]\n [1.15927407 0. 0. 0. 0. ]\n [1.34391638 1.15927407 0. 0. 0. ]\n [1.55796742 1.34391638 1.15927407 0. 0. ]\n [1.80611123 1.55796742 1.34391638 1.15927407 0. ]]\n np.fill_diagonal(arr, 1)\nprint (arr)\n[[1. 0. 0. 0. 0. ]\n [1.15927407 1. 0. 0. 0. ]\n [1.34391638 1.15927407 1. 0. 0. ]\n [1.55796742 1.34391638 1.15927407 1. 0. ]\n [1.80611123 1.55796742 1.34391638 1.15927407 1. ]]\n print (arr * df['income'].to_numpy())\n[[ 5. 0. 0. 0. 0. ]\n [ 5.79637037 13. 0. 0. 0. ]\n [ 6.7195819 15.07056297 23. 0. 0. ]\n [ 7.78983708 17.47091293 26.66330371 18. 0. ]\n [ 9.03055617 20.25357642 30.91007672 20.86693334 12. ]]\n\n\ndf['new'] = (arr * df['income'].to_numpy()).sum(axis=1)\nprint (df) age income new\n0 0 5 5.000000\n1 5 13 18.796370\n2 10 23 44.790145\n3 15 18 69.924054\n4 20 12 93.061143\n apply df = pd.DataFrame({\"age\" : [0, 5, 10, 15, 20], \"income\": [5, 13, 23, 18, 12]})\ndf = pd.concat([df] * 1000, ignore_index=True)\n\n\nIn [292]: %%timeit\n ...: age = df['age'].to_numpy()\n ...: \n ...: arr = interest ** (age[:, None] - age ) \n ...: arr = np.where(np.triu(np.ones(arr.shape, dtype=bool)), 0, arr)\n ...: np.fill_diagonal(arr, 1)\n ...: df['new'] = (arr * df['income'].to_numpy()).sum(axis=1)\n ...: \n1.39 s ± 69.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n\nIn [293]: %%timeit\n ...: df['sumproduct'] = (df['age'].expanding().apply(lambda x: sum(df.loc[:x.index[-1], 'income'] * interest**(x.iloc[-1]-x))))\n ...: \n5.13 s ± 411 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
},
{
"answer_id": 74655769,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 2,
"selected": true,
"text": "18+(18+23+13+5)*15-(23+13+5)*(10+5+0) 18+(18+23+13+5)*15-(23+13+5)*(10+5+0) sumproduct(n) = (income\n + (n-1)*sum(age[:n-1]*income[:n-1])\n - sum(age[:n-1]*income[:n-1])\n )\n df['sumproduct'] = (df['income']\n .add(df['age'].mul(df['income'].cumsum().shift(fill_value=0)))\n .sub(df['age'].mul(df['income']).cumsum().shift(fill_value=0))\n)\n age income sumproduct\n0 0 5 5\n1 5 13 38\n2 10 23 138\n3 15 18 338\n4 20 12 627\n expanding df['sumproduct'] = (df['age'].expanding()\n .apply(lambda x: sum(df.loc[:x.index[-1], 'income'] * interest**(x.iloc[-1]-x)))\n)\n age income sumproduct\n0 0 5 5.000000\n1 5 13 18.796370\n2 10 23 44.790145\n3 15 18 69.924054\n4 20 12 93.061143\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4025652/"
] |
74,655,428
|
<p>I'm woriking on a site, and trying to make a sidebar in which I put my image before some text in</p>
<pre><code><a> </a> tags
</code></pre>
<p>I've made a new empty project to test if I messed up something in my previous one, but no Even in a new empty one background image won't show itself
here is the code:</p>
<pre><code><a href='#' title='Građevinski radovi'><span style="background-image: url('./Ikonice/GRADJEVINA.svg')"></span><span class='Title'>Gradjevinski radovi</span></a>
</code></pre>
<p>I am working in VS CODE and using "Live Server" extension, saw somewhere on here that might cause a problem, so I opened html noramally without live server, still no luck.</p>
<p><a href="https://i.stack.imgur.com/PL12m.png" rel="nofollow noreferrer">Image of the project</a></p>
<p>WHAT I TRIED:</p>
<p>I tried putting two dots ".." before the first "/, also tried putting the image in the same folder as "index.html", and not in the "ikonice" folder, but it won't work. Also tried changing</p>
<pre><code>backgroung-image: url
to
background: url
</code></pre>
|
[
{
"answer_id": 74655504,
"author": "Salketer",
"author_id": 1620194,
"author_profile": "https://Stackoverflow.com/users/1620194",
"pm_score": 3,
"selected": true,
"text": "<span style=\"background:red;\"></span>\n\n<span style=\"background:lightblue;\">Test</span> display:inline-block display:block"
},
{
"answer_id": 74655622,
"author": "Stacks Queue",
"author_id": 14820590,
"author_profile": "https://Stackoverflow.com/users/14820590",
"pm_score": 0,
"selected": false,
"text": "<a href=\"#\"> \n <span style=\"background-image: url('https://picsum.photos/300/200.jpg')\">LOREMLOREM</span>\n <span class='Title'>Gradjevinski radovi</span>\n</a> span <a href=\"#\"> \n <span style=\"background-image: url('https://picsum.photos/300/200.jpg')\"></span>\n <span class='Title'>Gradjevinski radovi</span>\n</a> span background-image"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655428",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20585137/"
] |
74,655,458
|
<p>I could not comprehend in Kafka documentation is what is the exact need of partitioning a topic? What is the issue if it were only one topic with no partition (or one partition only).</p>
|
[
{
"answer_id": 74655504,
"author": "Salketer",
"author_id": 1620194,
"author_profile": "https://Stackoverflow.com/users/1620194",
"pm_score": 3,
"selected": true,
"text": "<span style=\"background:red;\"></span>\n\n<span style=\"background:lightblue;\">Test</span> display:inline-block display:block"
},
{
"answer_id": 74655622,
"author": "Stacks Queue",
"author_id": 14820590,
"author_profile": "https://Stackoverflow.com/users/14820590",
"pm_score": 0,
"selected": false,
"text": "<a href=\"#\"> \n <span style=\"background-image: url('https://picsum.photos/300/200.jpg')\">LOREMLOREM</span>\n <span class='Title'>Gradjevinski radovi</span>\n</a> span <a href=\"#\"> \n <span style=\"background-image: url('https://picsum.photos/300/200.jpg')\"></span>\n <span class='Title'>Gradjevinski radovi</span>\n</a> span background-image"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655458",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20135226/"
] |
74,655,545
|
<p>I have object CartItem and Product.
I need to make one List<> from these 2 objects.</p>
<p>Tried:
<code>List<(CartItem,Product)> product = new List<(CartItem,Product)>();</code></p>
<p>Code:</p>
<pre><code> public async Task<IActionResult> Index()
{
var username = User.Identity.Name;
if (username == null)
{
return Login();
}
var user = _context.Users.FirstOrDefault(x => x.Email == username);
List<CartItem> cart = _context.ShoppingCartItems.Where(s => s.IDuser.Equals(user.Id)).ToList();
List<Product> product = new List<Product>();
foreach (var item in cart)
{
product.Add(_context.Product.FirstOrDefault(x => x.id == item.ProductId));
}
return View(user);
}
</code></pre>
|
[
{
"answer_id": 74655641,
"author": "Ascyt",
"author_id": 16234971,
"author_profile": "https://Stackoverflow.com/users/16234971",
"pm_score": 0,
"selected": false,
"text": "struct EntireProduct\n{\n CartItem cartItem;\n Product product;\n}\n List<EntireProduct> product = new List<EntireProduct>();\n"
},
{
"answer_id": 74655675,
"author": "Panagiotis Kanavos",
"author_id": 134204,
"author_profile": "https://Stackoverflow.com/users/134204",
"pm_score": 3,
"selected": true,
"text": "CartItem Product User var cart=_context.ShoppingCartItems\n .Include(i=>i.Product)\n .Where(s=>s.User.Email==userName)\n .ToList();\n User Product CartItem.Product List<(CartItem,Product)> List<Product> // PLEASE don't do it this way\nvar dontUseThis = new List<(CartItem,Product?)>();\nforeach (var item in cart)\n{\n var product=_context.Product.FirstOrDefault(x => x.id == item.ProductId);\n dontUseThis.Add((item,product));\n}\n WHERE product.ID IN (....) var productIds=cart.Select(c=>c.ProductId);\n\nvar products=_context.Product\n .Where(p=>productIds.Contains(p.Id))\n .ToList();\n\nvar dontUseThis = products.Join(cart, \n p => p.Id, \n c => c.ProductId, \n (c, p) => (c,p))\n .ToList();\n"
},
{
"answer_id": 74655811,
"author": "mshsayem",
"author_id": 152349,
"author_profile": "https://Stackoverflow.com/users/152349",
"pm_score": 1,
"selected": false,
"text": "List<CartItem> cartItems; // assuming you already have this\nList<Product> products; // assuming you already have this\n\n// The combination part\nvar result = from p in products\n join ci in cartItems on p.Id = ci.ProductId // Find out how product and cartItem relates\n select new (p,ci);\n\n// Need List?\nvar resultingList = result.ToList();\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655545",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20261764/"
] |
74,655,549
|
<p>Here I have this code:</p>
<p>N = int(input())</p>
<p>Tmp=n</p>
<p>While tmp>0 :</p>
<p>Print(n)</p>
<p>Tmp-=1</p>
<p>But for ex: when I have:</p>
<p>3</p>
<p>2</p>
<p>1</p>
<p>0</p>
<p>As entered nums, it just prints:</p>
<p>3</p>
<p>3</p>
<p>3</p>
<p>But I need to print:</p>
<p>3</p>
<p>3</p>
<p>3</p>
<p>2</p>
<p>2</p>
<p>1</p>
<pre><code>Here I have this code:
N = int(input())
Tmp=n
While tmp>0 :
Print(n)
Tmp-=1
</code></pre>
<p>But there is a problem!bc it just prints</p>
<p>3</p>
<p>3</p>
<p>3</p>
<p>Instead of:</p>
<p>3</p>
<p>3</p>
<p>3</p>
<p>2</p>
<p>2</p>
<p>1</p>
|
[
{
"answer_id": 74655587,
"author": "rymanso",
"author_id": 6716421,
"author_profile": "https://Stackoverflow.com/users/6716421",
"pm_score": 1,
"selected": false,
"text": "print(tmp) print(n) n = int(input())\n\ntmp=n\n\nwhile tmp > 0:\n for _ in range(tmp)\n print(tmp)\n tmp -= 1\n\n"
},
{
"answer_id": 74656208,
"author": "Arifa Chan",
"author_id": 19574157,
"author_profile": "https://Stackoverflow.com/users/19574157",
"pm_score": 0,
"selected": false,
"text": "if tmp n tmp n n = int(input('input : '))\ntmp = n\nwhile tmp > 0:\n print(n)\n tmp -= 1\n if tmp == 0:\n n -= 1\n tmp = n\n # input : 3\n# 3\n# 3\n# 3\n# 2\n# 2\n# 1\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655549",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17721501/"
] |
74,655,565
|
<p>I have a table "products" with a column called "store_id".
This table has a lot af products from many stores.
I need to select 4 random products from 4 specific stores (id: 1, 34, 45, 100).
How can I do that?</p>
<p>I've tried to like this:</p>
<pre><code>SELECT * FROM products WHERE store_id IN (1, 34, 45, 100)
</code></pre>
<p>But that query returns duplicated records (by store_id).
I need the following result:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>store_id</th>
<th>title</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>title a</td>
</tr>
<tr>
<td>34</td>
<td>title b</td>
</tr>
<tr>
<td>45</td>
<td>title c</td>
</tr>
<tr>
<td>100</td>
<td>title d</td>
</tr>
</tbody>
</table>
</div>
|
[
{
"answer_id": 74655587,
"author": "rymanso",
"author_id": 6716421,
"author_profile": "https://Stackoverflow.com/users/6716421",
"pm_score": 1,
"selected": false,
"text": "print(tmp) print(n) n = int(input())\n\ntmp=n\n\nwhile tmp > 0:\n for _ in range(tmp)\n print(tmp)\n tmp -= 1\n\n"
},
{
"answer_id": 74656208,
"author": "Arifa Chan",
"author_id": 19574157,
"author_profile": "https://Stackoverflow.com/users/19574157",
"pm_score": 0,
"selected": false,
"text": "if tmp n tmp n n = int(input('input : '))\ntmp = n\nwhile tmp > 0:\n print(n)\n tmp -= 1\n if tmp == 0:\n n -= 1\n tmp = n\n # input : 3\n# 3\n# 3\n# 3\n# 2\n# 2\n# 1\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655565",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17171093/"
] |
74,655,574
|
<p>I have a column called DOB which has dates formatted 31.07.1983 for example.</p>
<p>My data frame is named users_pd.</p>
<p>I want to add a column that has the current age of the customer based off the existing DOB column.</p>
<p>from datetime import date, timedelta</p>
<p>users_pd["Age"] = (date.today() - users_pd["DOB"] // timedelta(days=365.2425))</p>
<p>I get the error</p>
<pre><code>TypeError: Invalid dtype object for __floordiv__
</code></pre>
|
[
{
"answer_id": 74655587,
"author": "rymanso",
"author_id": 6716421,
"author_profile": "https://Stackoverflow.com/users/6716421",
"pm_score": 1,
"selected": false,
"text": "print(tmp) print(n) n = int(input())\n\ntmp=n\n\nwhile tmp > 0:\n for _ in range(tmp)\n print(tmp)\n tmp -= 1\n\n"
},
{
"answer_id": 74656208,
"author": "Arifa Chan",
"author_id": 19574157,
"author_profile": "https://Stackoverflow.com/users/19574157",
"pm_score": 0,
"selected": false,
"text": "if tmp n tmp n n = int(input('input : '))\ntmp = n\nwhile tmp > 0:\n print(n)\n tmp -= 1\n if tmp == 0:\n n -= 1\n tmp = n\n # input : 3\n# 3\n# 3\n# 3\n# 2\n# 2\n# 1\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655574",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20408318/"
] |
74,655,607
|
<p>I have a file that does dangerous jobs and must be used as CLI with <code>node</code> command directly. How can I be sure no developer ever imports it as module with <code>import 'file.js'</code> syntax in current project?</p>
|
[
{
"answer_id": 74655587,
"author": "rymanso",
"author_id": 6716421,
"author_profile": "https://Stackoverflow.com/users/6716421",
"pm_score": 1,
"selected": false,
"text": "print(tmp) print(n) n = int(input())\n\ntmp=n\n\nwhile tmp > 0:\n for _ in range(tmp)\n print(tmp)\n tmp -= 1\n\n"
},
{
"answer_id": 74656208,
"author": "Arifa Chan",
"author_id": 19574157,
"author_profile": "https://Stackoverflow.com/users/19574157",
"pm_score": 0,
"selected": false,
"text": "if tmp n tmp n n = int(input('input : '))\ntmp = n\nwhile tmp > 0:\n print(n)\n tmp -= 1\n if tmp == 0:\n n -= 1\n tmp = n\n # input : 3\n# 3\n# 3\n# 3\n# 2\n# 2\n# 1\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655607",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13689893/"
] |
74,655,650
|
<p>How to loop through an array of object got similar key and different value for Example if,</p>
<pre><code>arrayOfObjects = [
{ parent: 'relatedParty', child: 'role === CEO', andOr = '&&' }
{ parent: 'relatedParty', child: 'name === Arun' , andOr = '||'}
{ parent: 'relatedParty', child: ' id === 123', andOr = '&&' }
{ parent: 'cusotm', child: 'contact === DAP', andOr = '||' }
{ parent: 'custom', child: 'team==dap', andOr = '&&' }
{ parent: 'multiple', child: 'key ===keys', andOr = '||' }
{ parent: 'multiple', child: 'value=== values', andOr = '&&' }
].
</code></pre>
<p>im stuck in a position where how can i iterate through this and get output like if
first object of parent is === second object, then I want them to add into an array and finally those values should be inside another array</p>
<pre><code>[[role === CEO && name === Arun && id === 123 &&], [contact === DAP || team==dap && ],[ key ===keys || value=== values &&]]
</code></pre>
|
[
{
"answer_id": 74655587,
"author": "rymanso",
"author_id": 6716421,
"author_profile": "https://Stackoverflow.com/users/6716421",
"pm_score": 1,
"selected": false,
"text": "print(tmp) print(n) n = int(input())\n\ntmp=n\n\nwhile tmp > 0:\n for _ in range(tmp)\n print(tmp)\n tmp -= 1\n\n"
},
{
"answer_id": 74656208,
"author": "Arifa Chan",
"author_id": 19574157,
"author_profile": "https://Stackoverflow.com/users/19574157",
"pm_score": 0,
"selected": false,
"text": "if tmp n tmp n n = int(input('input : '))\ntmp = n\nwhile tmp > 0:\n print(n)\n tmp -= 1\n if tmp == 0:\n n -= 1\n tmp = n\n # input : 3\n# 3\n# 3\n# 3\n# 2\n# 2\n# 1\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655650",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19423607/"
] |
74,655,653
|
<p>How to incorporate proof aspects into the specification so that every function and procedure has a Post aspect and, if required, a Pre aspect that outlines the proper behaviour of the code below:</p>
<pre><code>package Stack with SPARK_Mode is
pragma Elaborate_Body;
Stack_Size : constant := 100;
type Pointer_Range is range 0 .. Stack_Size;
subtype Index_Range is Pointer_Range range 1 .. Stack_Size;
type Vector is array(Index_Range) of Integer;
S: Vector;
Pointer: Pointer_Range;
function isEmpty return Boolean;
procedure Push(X : in Integer)
with
Global => (In_out => (S, Pointer)),
Depends => (S => (S, Pointer, X),
Pointer => Pointer);
procedure Pop(X : out Integer)
with
Global => (input => S, in_out => Pointer),
Depends => (Pointer => Pointer,
X => (S, Pointer));
end Stack;
</code></pre>
|
[
{
"answer_id": 74655587,
"author": "rymanso",
"author_id": 6716421,
"author_profile": "https://Stackoverflow.com/users/6716421",
"pm_score": 1,
"selected": false,
"text": "print(tmp) print(n) n = int(input())\n\ntmp=n\n\nwhile tmp > 0:\n for _ in range(tmp)\n print(tmp)\n tmp -= 1\n\n"
},
{
"answer_id": 74656208,
"author": "Arifa Chan",
"author_id": 19574157,
"author_profile": "https://Stackoverflow.com/users/19574157",
"pm_score": 0,
"selected": false,
"text": "if tmp n tmp n n = int(input('input : '))\ntmp = n\nwhile tmp > 0:\n print(n)\n tmp -= 1\n if tmp == 0:\n n -= 1\n tmp = n\n # input : 3\n# 3\n# 3\n# 3\n# 2\n# 2\n# 1\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655653",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20261045/"
] |
74,655,661
|
<p>I need to convert this javascript code to jquery. How to do it?</p>
<pre class="lang-js prettyprint-override"><code>import lightGallery from "https://cdn.skypack.dev/lightgallery@2.0.0-beta.4";
import lgThumbnail from "https://cdn.skypack.dev/lightgallery@2.0.0-beta.4/plugins/thumbnail";
const $galleryContainer = document.getElementById("gallery-container");
const lg = lightGallery($galleryContainer, {
speed: 500,
plugins: [lgThumbnail],
enableDrag: false,
enableSwipe: false
});
lg.outer.on("click", (e) => {
const $item = lg.outer.find(".lg-current .lg-image");
if (
e.target.classList.contains("lg-image") ||
$item.get().contains(e.target)
) {
lg.goToNextSlide();
}
});
</code></pre>
<p>I tried to find an online converter. I managed to find a huge bunch of converters from jQuery to JS, but I need the opposite</p>
|
[
{
"answer_id": 74655587,
"author": "rymanso",
"author_id": 6716421,
"author_profile": "https://Stackoverflow.com/users/6716421",
"pm_score": 1,
"selected": false,
"text": "print(tmp) print(n) n = int(input())\n\ntmp=n\n\nwhile tmp > 0:\n for _ in range(tmp)\n print(tmp)\n tmp -= 1\n\n"
},
{
"answer_id": 74656208,
"author": "Arifa Chan",
"author_id": 19574157,
"author_profile": "https://Stackoverflow.com/users/19574157",
"pm_score": 0,
"selected": false,
"text": "if tmp n tmp n n = int(input('input : '))\ntmp = n\nwhile tmp > 0:\n print(n)\n tmp -= 1\n if tmp == 0:\n n -= 1\n tmp = n\n # input : 3\n# 3\n# 3\n# 3\n# 2\n# 2\n# 1\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655661",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18764312/"
] |
74,655,670
|
<p>A friend asked me for a way to untrack a file from a time point on for the future - but being able to git checkup to a state where the file was still tracked by git.
Aim is to keep the file locally but prevent for future commits</p>
<p>I googled in the past for this - and read several stackoverflow answers to similar problems.</p>
<p>But it seems that there is no good way to achieve this.</p>
<p>It seems that the tracking status of files is globally controlled. Is there a way to keep the tracking status locally controlled (meaning can be changed from commit to commit)?</p>
|
[
{
"answer_id": 74655904,
"author": "Brandon Kauffman",
"author_id": 14256876,
"author_profile": "https://Stackoverflow.com/users/14256876",
"pm_score": 1,
"selected": false,
"text": "git rm file_name"
},
{
"answer_id": 74656163,
"author": "matt",
"author_id": 341994,
"author_profile": "https://Stackoverflow.com/users/341994",
"pm_score": 2,
"selected": false,
"text": "git add git rm .gitignore git add . git status"
},
{
"answer_id": 74661128,
"author": "torek",
"author_id": 1256452,
"author_profile": "https://Stackoverflow.com/users/1256452",
"pm_score": 3,
"selected": true,
"text": "git checkout git switch --force .gitignore .gitignore"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655670",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9690090/"
] |
74,655,676
|
<p>I am trying to get sprite from Image in Unity but I am facing an issue. I am using this code:</p>
<pre><code>void Start () {
Sprite sprite = this.gameObject.GetComponent<Image> ().sprite;
if (sprite == null) {
Debug.Log ("NULL");
} else {
Debug.Log ("NOT NULL");
}
}
</code></pre>
<p>If the sprite is empty, it does not recognize as "null". Why? and how to fix it?</p>
|
[
{
"answer_id": 74655904,
"author": "Brandon Kauffman",
"author_id": 14256876,
"author_profile": "https://Stackoverflow.com/users/14256876",
"pm_score": 1,
"selected": false,
"text": "git rm file_name"
},
{
"answer_id": 74656163,
"author": "matt",
"author_id": 341994,
"author_profile": "https://Stackoverflow.com/users/341994",
"pm_score": 2,
"selected": false,
"text": "git add git rm .gitignore git add . git status"
},
{
"answer_id": 74661128,
"author": "torek",
"author_id": 1256452,
"author_profile": "https://Stackoverflow.com/users/1256452",
"pm_score": 3,
"selected": true,
"text": "git checkout git switch --force .gitignore .gitignore"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655676",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17561671/"
] |
74,655,686
|
<p>I'm currently learning the flexbox CSS concept, and I'm trying to create a navbar with it.</p>
<p>I want to make my search bar like
<a href="https://i.stack.imgur.com/cRAAG.png" rel="nofollow noreferrer">this</a></p>
<p>And this is the picture of what I'm working on
<a href="https://i.stack.imgur.com/N0Oub.png" rel="nofollow noreferrer">here</a></p>
<p>This is my html code</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>@font-face {
font-family: "campton-bold";
src: url(fonts/campton-cufonfonts/CamptonBold.otf) format("opentype");
}
@font-face {
font-family: "campton-light";
src: url(fonts/campton-cufonfonts/CamptonLight.otf) format("opentype");
}
@font-face {
font-family: "campton-medium";
src: url(fonts/campton-cufonfonts/CamptonMedium.otf) format("opentype");
}
* {
margin: 0;
padding: 0;
}
a img {
width: 40px;
}
nav {
background-color: #003466;
display: flex;
justify-content: space-around;
padding: 10px 0;
height: 50px;
align-items: center;
}
nav .btn-icon {
display: flex;
width: 20%;
justify-content: space-around;
/* background-color: black; */
}
nav .btn-icon a img {
transition: transform 0.2s;
}
nav .btn-icon a img:hover {
transform: scale(1.1);
}
.search-bar {
display: flex;
justify-content: center;
}
nav .search-bar input {
border-radius: 20px;
height: 35px;
width: 370px;
padding: 0 15px;
box-sizing: border-box;
font-family: campton-light;
outline: none;
border: none;
font-size: 15px;
}
nav .search-bar a {
text-decoration: none;
display: flex;
color: black;
align-items: center;
font-size: 20px;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css" />
<nav>
<div class="search-bar">
<input type="text" placeholder="Search" name="search" />
<a href="#"><i class="fa fa-search"></i></a>
</div>
<div class="btn-icon">
<div class="msg-icon">
<a href="#"><img src="img/message-01.png" alt="message" /></a>
</div>
<div class="upload-icon">
<a href="#"><img src="img/upload-01.png" alt="upload" /></a>
</div>
<div class="notif-icon">
<a href="#"><img src="img/bell-01.png" alt="notification" /></a>
</div>
<div class="btn-profile">
<a href="#"><img src="img/profile-01.png" alt="profile" /></a>
</div>
</div>
</nav></code></pre>
</div>
</div>
</p>
<p>I hope you can help me, thank you</p>
|
[
{
"answer_id": 74655774,
"author": "Jaswinder Kaur",
"author_id": 15258737,
"author_profile": "https://Stackoverflow.com/users/15258737",
"pm_score": 3,
"selected": true,
"text": ".search-bar {\n background: #fff;\n border-radius: 50px;\n padding-right: 17px;\n}\n.fa.fa-search {\ncolor: #003466;\n}\n@font-face {\n font-family: \"campton-bold\";\n src: url(fonts/campton-cufonfonts/CamptonBold.otf) format(\"opentype\");\n}\n\n@font-face {\n font-family: \"campton-light\";\n src: url(fonts/campton-cufonfonts/CamptonLight.otf) format(\"opentype\");\n}\n\n@font-face {\n font-family: \"campton-medium\";\n src: url(fonts/campton-cufonfonts/CamptonMedium.otf) format(\"opentype\");\n}\n\n* {\n margin: 0;\n padding: 0;\n}\n\n\na img {\n width: 40px;\n}\n\nnav {\n background-color: #003466;\n display: flex;\n justify-content: space-around;\n padding: 10px 0;\n height: 50px;\n align-items: center;\n}\n\nnav .btn-icon {\n display: flex;\n width: 20%;\n justify-content: space-around;\n /* background-color: black; */\n}\n\nnav .btn-icon a img {\n transition: transform 0.2s;\n}\n\nnav .btn-icon a img:hover {\n transform: scale(1.1);\n}\n\n.search-bar {\n display: flex;\n justify-content: center;\n}\n\nnav .search-bar input {\n border-radius: 20px;\n height: 35px;\n width: 370px;\n padding: 0 15px;\n box-sizing: border-box;\n font-family: campton-light;\n outline: none;\n border: none;\n font-size: 15px;\n}\n\nnav .search-bar a {\n text-decoration: none;\n display: flex;\n color: black;\n align-items: center;\n font-size: 20px;\n} <!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>Document</title>\n <link rel=\"stylesheet\" href=\"style2.css\" />\n <link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css\" />\n </head>\n <body>\n <nav>\n\n <div class=\"search-bar\">\n <input type=\"text\" placeholder=\"Search\" name=\"search\" />\n <a href=\"#\"><i class=\"fa fa-search\"></i></a>\n </div>\n\n <div class=\"btn-icon\">\n <div class=\"msg-icon\">\n <a href=\"#\"><img src=\"img/message-01.png\" alt=\"message\" /></a>\n </div>\n\n <div class=\"upload-icon\">\n <a href=\"#\"><img src=\"img/upload-01.png\" alt=\"upload\" /></a>\n </div>\n\n <div class=\"notif-icon\">\n <a href=\"#\"><img src=\"img/bell-01.png\" alt=\"notification\" /></a>\n </div>\n\n <div class=\"btn-profile\">\n <a href=\"#\"><img src=\"img/profile-01.png\" alt=\"profile\" /></a>\n </div>\n </div>\n </nav>\n </body>\n</html> .search-bar {\n position: relative;\n}\n.fa.fa-search {\n position: absolute;\n z-index: 999;\n right: 10px;\n}\n"
},
{
"answer_id": 74655784,
"author": "TrueStoryShort",
"author_id": 20117831,
"author_profile": "https://Stackoverflow.com/users/20117831",
"pm_score": 0,
"selected": false,
"text": ".search-bar {\n position: relative; //the child will orientate on this parent\n\n}\n.search-bar a { // this a tag should include your image\n position: absolute; //so the a tag sits on top of the input\n bottom: 0; // distance from bottom (parent div)\n top: 0; // distance from top (parent div)\n right: 0.5rem; // distance from right (parent div)\n}\n"
},
{
"answer_id": 74656188,
"author": "NAZIR HUSSAIN",
"author_id": 20587701,
"author_profile": "https://Stackoverflow.com/users/20587701",
"pm_score": 0,
"selected": false,
"text": "here is working example\n\nI just wrapped input and icon into label tag and changed some styles\n @font-face {\n font-family: \"campton-bold\";\n src: url(fonts/campton-cufonfonts/CamptonBold.otf) format(\"opentype\");\n}\n\n@font-face {\n font-family: \"campton-light\";\n src: url(fonts/campton-cufonfonts/CamptonLight.otf) format(\"opentype\");\n}\n\n@font-face {\n font-family: \"campton-medium\";\n src: url(fonts/campton-cufonfonts/CamptonMedium.otf) format(\"opentype\");\n}\n\n* {\n margin: 0;\n padding: 0;\n}\n\na img {\n width: 40px;\n}\n\nnav {\n background-color: #003466;\n display: flex;\n justify-content: space-around;\n padding: 10px 0;\n height: 50px;\n align-items: center;\n}\n\nnav .btn-icon {\n display: flex;\n width: 20%;\n justify-content: space-around;\n /* background-color: black; */\n}\n\nnav .btn-icon a img {\n transition: transform 0.2s;\n}\n\nnav .btn-icon a img:hover {\n transform: scale(1.1);\n}\n\n.search-bar {\n display: flex;\n justify-content:space-between;\n}\n\nnav .search-bar {\n border-radius: 20px;\n height: 35px;\n width: 370px;\n padding: 0 15px;\n box-sizing: border-box;\n outline: none;\n border: none;\n font-size: 15px;\n background: white;\n}\n nav .search-bar input {\n all:unset;\n width:100%;\n}\n\nnav .search-bar a {\n text-decoration: none;\n display: flex;\n color: black;\n align-items: center;\n font-size: 20px;\n} <link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css\" />\n\n<nav>\n <label for=\"ii\" class=\"search-bar\">\n <input type=\"text\" id=\"ii\" placeholder=\"Search\" name=\"search\" />\n <a href=\"#\"><i class=\"fa fa-search\"></i></a>\n </label>\n\n <div class=\"btn-icon\">\n <div class=\"msg-icon\">\n <a href=\"#\"><img src=\"img/message-01.png\" alt=\"message\" /></a>\n </div>\n\n <div class=\"upload-icon\">\n <a href=\"#\"><img src=\"img/upload-01.png\" alt=\"upload\" /></a>\n </div>\n\n <div class=\"notif-icon\">\n <a href=\"#\"><img src=\"img/bell-01.png\" alt=\"notification\" /></a>\n </div>\n\n <div class=\"btn-profile\">\n <a href=\"#\"><img src=\"img/profile-01.png\" alt=\"profile\" /></a>\n </div>\n </div>\n</nav>"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655686",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20665984/"
] |
74,655,705
|
<p>I am having trouble adding the Ports field in <code>ServiceSpec</code>. What am I doing wrong?</p>
<pre class="lang-golang prettyprint-override"><code>import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
port := corev1.ServicePort{}
port.Port = 8443
ports := make(corev1.ServicePort, 1)
service := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "test-webhook-admissions",
Namespace: "test",
Labels: map[string]string{
"app.kubernetes.io/instance": "test",
"app.kubernetes.io/name": "test",
"control-plane": "controller-manager",
},
},
Spec: corev1.ServiceSpec{
Ports: ports, // Not working
Selector: nil,
//ClusterIP: "",
},
}
</code></pre>
|
[
{
"answer_id": 74655774,
"author": "Jaswinder Kaur",
"author_id": 15258737,
"author_profile": "https://Stackoverflow.com/users/15258737",
"pm_score": 3,
"selected": true,
"text": ".search-bar {\n background: #fff;\n border-radius: 50px;\n padding-right: 17px;\n}\n.fa.fa-search {\ncolor: #003466;\n}\n@font-face {\n font-family: \"campton-bold\";\n src: url(fonts/campton-cufonfonts/CamptonBold.otf) format(\"opentype\");\n}\n\n@font-face {\n font-family: \"campton-light\";\n src: url(fonts/campton-cufonfonts/CamptonLight.otf) format(\"opentype\");\n}\n\n@font-face {\n font-family: \"campton-medium\";\n src: url(fonts/campton-cufonfonts/CamptonMedium.otf) format(\"opentype\");\n}\n\n* {\n margin: 0;\n padding: 0;\n}\n\n\na img {\n width: 40px;\n}\n\nnav {\n background-color: #003466;\n display: flex;\n justify-content: space-around;\n padding: 10px 0;\n height: 50px;\n align-items: center;\n}\n\nnav .btn-icon {\n display: flex;\n width: 20%;\n justify-content: space-around;\n /* background-color: black; */\n}\n\nnav .btn-icon a img {\n transition: transform 0.2s;\n}\n\nnav .btn-icon a img:hover {\n transform: scale(1.1);\n}\n\n.search-bar {\n display: flex;\n justify-content: center;\n}\n\nnav .search-bar input {\n border-radius: 20px;\n height: 35px;\n width: 370px;\n padding: 0 15px;\n box-sizing: border-box;\n font-family: campton-light;\n outline: none;\n border: none;\n font-size: 15px;\n}\n\nnav .search-bar a {\n text-decoration: none;\n display: flex;\n color: black;\n align-items: center;\n font-size: 20px;\n} <!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>Document</title>\n <link rel=\"stylesheet\" href=\"style2.css\" />\n <link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css\" />\n </head>\n <body>\n <nav>\n\n <div class=\"search-bar\">\n <input type=\"text\" placeholder=\"Search\" name=\"search\" />\n <a href=\"#\"><i class=\"fa fa-search\"></i></a>\n </div>\n\n <div class=\"btn-icon\">\n <div class=\"msg-icon\">\n <a href=\"#\"><img src=\"img/message-01.png\" alt=\"message\" /></a>\n </div>\n\n <div class=\"upload-icon\">\n <a href=\"#\"><img src=\"img/upload-01.png\" alt=\"upload\" /></a>\n </div>\n\n <div class=\"notif-icon\">\n <a href=\"#\"><img src=\"img/bell-01.png\" alt=\"notification\" /></a>\n </div>\n\n <div class=\"btn-profile\">\n <a href=\"#\"><img src=\"img/profile-01.png\" alt=\"profile\" /></a>\n </div>\n </div>\n </nav>\n </body>\n</html> .search-bar {\n position: relative;\n}\n.fa.fa-search {\n position: absolute;\n z-index: 999;\n right: 10px;\n}\n"
},
{
"answer_id": 74655784,
"author": "TrueStoryShort",
"author_id": 20117831,
"author_profile": "https://Stackoverflow.com/users/20117831",
"pm_score": 0,
"selected": false,
"text": ".search-bar {\n position: relative; //the child will orientate on this parent\n\n}\n.search-bar a { // this a tag should include your image\n position: absolute; //so the a tag sits on top of the input\n bottom: 0; // distance from bottom (parent div)\n top: 0; // distance from top (parent div)\n right: 0.5rem; // distance from right (parent div)\n}\n"
},
{
"answer_id": 74656188,
"author": "NAZIR HUSSAIN",
"author_id": 20587701,
"author_profile": "https://Stackoverflow.com/users/20587701",
"pm_score": 0,
"selected": false,
"text": "here is working example\n\nI just wrapped input and icon into label tag and changed some styles\n @font-face {\n font-family: \"campton-bold\";\n src: url(fonts/campton-cufonfonts/CamptonBold.otf) format(\"opentype\");\n}\n\n@font-face {\n font-family: \"campton-light\";\n src: url(fonts/campton-cufonfonts/CamptonLight.otf) format(\"opentype\");\n}\n\n@font-face {\n font-family: \"campton-medium\";\n src: url(fonts/campton-cufonfonts/CamptonMedium.otf) format(\"opentype\");\n}\n\n* {\n margin: 0;\n padding: 0;\n}\n\na img {\n width: 40px;\n}\n\nnav {\n background-color: #003466;\n display: flex;\n justify-content: space-around;\n padding: 10px 0;\n height: 50px;\n align-items: center;\n}\n\nnav .btn-icon {\n display: flex;\n width: 20%;\n justify-content: space-around;\n /* background-color: black; */\n}\n\nnav .btn-icon a img {\n transition: transform 0.2s;\n}\n\nnav .btn-icon a img:hover {\n transform: scale(1.1);\n}\n\n.search-bar {\n display: flex;\n justify-content:space-between;\n}\n\nnav .search-bar {\n border-radius: 20px;\n height: 35px;\n width: 370px;\n padding: 0 15px;\n box-sizing: border-box;\n outline: none;\n border: none;\n font-size: 15px;\n background: white;\n}\n nav .search-bar input {\n all:unset;\n width:100%;\n}\n\nnav .search-bar a {\n text-decoration: none;\n display: flex;\n color: black;\n align-items: center;\n font-size: 20px;\n} <link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css\" />\n\n<nav>\n <label for=\"ii\" class=\"search-bar\">\n <input type=\"text\" id=\"ii\" placeholder=\"Search\" name=\"search\" />\n <a href=\"#\"><i class=\"fa fa-search\"></i></a>\n </label>\n\n <div class=\"btn-icon\">\n <div class=\"msg-icon\">\n <a href=\"#\"><img src=\"img/message-01.png\" alt=\"message\" /></a>\n </div>\n\n <div class=\"upload-icon\">\n <a href=\"#\"><img src=\"img/upload-01.png\" alt=\"upload\" /></a>\n </div>\n\n <div class=\"notif-icon\">\n <a href=\"#\"><img src=\"img/bell-01.png\" alt=\"notification\" /></a>\n </div>\n\n <div class=\"btn-profile\">\n <a href=\"#\"><img src=\"img/profile-01.png\" alt=\"profile\" /></a>\n </div>\n </div>\n</nav>"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655705",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3263650/"
] |
74,655,715
|
<p>If I pass in "largest countries" as an argument, I want it to return the respective string in the condition and all the countries in this array ["China", "India", "USA"].
If I pass in "best fruits" as an argument, I want it to return the respective string in the condition and all the fruits in this array ["Apples", "Bananas"].</p>
<p>My code doesn't do that. It returns just one country, the first one or just one fruit, the first one. How do i get it to return all the items in the respective arrays?</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>let sentenceC = document.getElementById("constructed")
function generateSentence(desc, arr) {
for (let i = 0; i < arr.length; i++) {
if (desc === "largest countries") {
return `The 3 ${desc} are ${arr[i]}, `
} else if (desc === "best fruits") {
return `The 2 ${desc} are ${arr[i]}, `
}
}
}
sentenceC.innerHTML = generateSentence("largest countries", ["China", "India", "USA"])</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><p id="constructed"></p></code></pre>
</div>
</div>
</p>
|
[
{
"answer_id": 74655772,
"author": "David",
"author_id": 328193,
"author_profile": "https://Stackoverflow.com/users/328193",
"pm_score": 2,
"selected": false,
"text": "Array.prototype.join let sentenceC = document.getElementById(\"constructed\")\n\nfunction generateSentence(desc, arr) {\n if (desc === \"largest countries\") {\n return `The 3 ${desc} are ${arr.join(', ')}`\n } else if (desc === \"best fruits\") {\n return `The 2 ${desc} are ${arr.join(', ')}`\n }\n}\nsentenceC.innerHTML = generateSentence(\"largest countries\", [\"China\", \"India\", \"USA\"]) <p id=\"constructed\"></p> if let sentenceC = document.getElementById(\"constructed\")\n\nfunction generateSentence(desc, arr) {\n return `The ${arr.length} ${desc} are ${arr.join(', ')}`\n}\nsentenceC.innerHTML = generateSentence(\"largest countries\", [\"China\", \"India\", \"USA\"]) <p id=\"constructed\"></p>"
},
{
"answer_id": 74655777,
"author": "Vugar Taghiyev",
"author_id": 17408994,
"author_profile": "https://Stackoverflow.com/users/17408994",
"pm_score": 1,
"selected": false,
"text": "function generateSentence(desc, arr){\n if(desc === \"largest countries\"){\n return `The 3 ${desc} are ${arr.join(\",\")}, `\n } else if (desc === \"best fruits\"){\n return `The 2 ${desc} are ${arr.join(\",\")}, `\n }\n}"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655715",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18722715/"
] |
74,655,734
|
<p>I have an array of items.
<code>const inputArray = ["a","b","c","d","e","f"]</code></p>
<p>I want to determine whether the entries are coming from an odd pair or an even pair. It should look something like this:</p>
<pre><code>doesEntryComeFromOddPair(inputArray[0]) -> true
doesEntryComeFromOddPair(inputArray[1]) -> true
doesEntryComeFromOddPair(inputArray[2]) -> false // it's the 3rd item in the array so it's pair 2
doesEntryComeFromOddPair(inputArray[3]) -> false // it's the 4th item in the array so it's pair 2
doesEntryComeFromOddPair(inputArray[4]) -> true // it's the 5th item in the array so it's pair 3
doesEntryComeFromOddPair(inputArray[5]) -> true // it's the 6th item in the array so it's pair 3
</code></pre>
<p>I tried to chunk the array into array of pairs of entries but this way I lose the benefit of having one-level deep array.</p>
|
[
{
"answer_id": 74655772,
"author": "David",
"author_id": 328193,
"author_profile": "https://Stackoverflow.com/users/328193",
"pm_score": 2,
"selected": false,
"text": "Array.prototype.join let sentenceC = document.getElementById(\"constructed\")\n\nfunction generateSentence(desc, arr) {\n if (desc === \"largest countries\") {\n return `The 3 ${desc} are ${arr.join(', ')}`\n } else if (desc === \"best fruits\") {\n return `The 2 ${desc} are ${arr.join(', ')}`\n }\n}\nsentenceC.innerHTML = generateSentence(\"largest countries\", [\"China\", \"India\", \"USA\"]) <p id=\"constructed\"></p> if let sentenceC = document.getElementById(\"constructed\")\n\nfunction generateSentence(desc, arr) {\n return `The ${arr.length} ${desc} are ${arr.join(', ')}`\n}\nsentenceC.innerHTML = generateSentence(\"largest countries\", [\"China\", \"India\", \"USA\"]) <p id=\"constructed\"></p>"
},
{
"answer_id": 74655777,
"author": "Vugar Taghiyev",
"author_id": 17408994,
"author_profile": "https://Stackoverflow.com/users/17408994",
"pm_score": 1,
"selected": false,
"text": "function generateSentence(desc, arr){\n if(desc === \"largest countries\"){\n return `The 3 ${desc} are ${arr.join(\",\")}, `\n } else if (desc === \"best fruits\"){\n return `The 2 ${desc} are ${arr.join(\",\")}, `\n }\n}"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655734",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19248527/"
] |
74,655,743
|
<p>I would like to use node (in my backend) to convert a large PDF with many (hundreds!) of pages to individual jpgs to store them in a database for further purposes.</p>
<p>For this I have chosen the npm package "gm" which uses "graphicsmagick" in the background.</p>
<p>I have encountered several big issues. For example, node seems to be unable to "digest" a large number of pages at a time. Since "gm" is synchronous, it does not wait but tries to start to convert all pages almost instantly which "freezes" my node application, i.e., it never stops working and it does not produce any pages. If I limit the number of pages to, say, 20, it works perfectly.</p>
<p>I could not find any documentation for "gm" or "graphicsmagick" providing "best practices" for converting (large) pdfs.</p>
<p>The 2 most relevant questions that I have are:</p>
<p>a) Is there a way to tell "graphicsmagick" to produce an individual jpg file for each pdf page? "imagemagick", for example, is doing this "out of the box". To be more specific</p>
<pre><code>convert -density 300 test.pdf test.jpg
</code></pre>
<p>would produce files like "test-0.jpg", "test-1.jpg", "test-2.jpg", and so on while</p>
<pre><code>gm convert -density 300 test.pdf test.jpg
</code></pre>
<p>only produces one jpg file (the first page of the pdf).</p>
<p>b) Is there a way with "gm" to reuse the same "Buffer" to produce jpg images? I assume that calling "gm" with a big buffer (of > 100MB) hundreds of times is not the best way to do it</p>
<p>Here is the code that I am using right now:</p>
<pre class="lang-ts prettyprint-override"><code>import gm from 'gm';
import fs from 'fs';
// Create "Buffer" to be used by "gm"
const buf = fs.readFileSync('test.pdf');
// Identify number of pages in pdf
gm(buf, 'test.pdf').identify((err: any, value: gm.ImageInfo) => {
if (err) {
console.log('err');
} else {
const actualArray: string[] = value.Format.toString().split(',');
let numPages: number = actualArray.length;
// Loop through all pages and produce desired output
for (let currentPage: number = 0; currentPage < numPages; currentPage++) {
gm(buf, `test.pdf[${currentPage}]`)
.density(150, 150)
.quality(90)
.write(`test${currentPage}.jpg`, (err: any) => {
if (err) console.log(err);
});
}
}
});
</code></pre>
<p>This approach</p>
<ul>
<li>does not work with large pdfs (at least not on my machine)</li>
<li>is very slow (presumably because it calls "gm" hundreds of times almost instantly with a "Buffer" of > 100MB)</li>
</ul>
<p>Is there a "best practice" approach to do this right? Any hint will be highly appreciated!</p>
|
[
{
"answer_id": 74655772,
"author": "David",
"author_id": 328193,
"author_profile": "https://Stackoverflow.com/users/328193",
"pm_score": 2,
"selected": false,
"text": "Array.prototype.join let sentenceC = document.getElementById(\"constructed\")\n\nfunction generateSentence(desc, arr) {\n if (desc === \"largest countries\") {\n return `The 3 ${desc} are ${arr.join(', ')}`\n } else if (desc === \"best fruits\") {\n return `The 2 ${desc} are ${arr.join(', ')}`\n }\n}\nsentenceC.innerHTML = generateSentence(\"largest countries\", [\"China\", \"India\", \"USA\"]) <p id=\"constructed\"></p> if let sentenceC = document.getElementById(\"constructed\")\n\nfunction generateSentence(desc, arr) {\n return `The ${arr.length} ${desc} are ${arr.join(', ')}`\n}\nsentenceC.innerHTML = generateSentence(\"largest countries\", [\"China\", \"India\", \"USA\"]) <p id=\"constructed\"></p>"
},
{
"answer_id": 74655777,
"author": "Vugar Taghiyev",
"author_id": 17408994,
"author_profile": "https://Stackoverflow.com/users/17408994",
"pm_score": 1,
"selected": false,
"text": "function generateSentence(desc, arr){\n if(desc === \"largest countries\"){\n return `The 3 ${desc} are ${arr.join(\",\")}, `\n } else if (desc === \"best fruits\"){\n return `The 2 ${desc} are ${arr.join(\",\")}, `\n }\n}"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655743",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15791388/"
] |
74,655,748
|
<p>I have string(nvarchar) from db data and I would like to transfer it to numbers only. I was searching on Google for solution but I didnt find anything. I found something similiar here on StackOverflow but everything was removing characters only from left side, but if there is any character on right side or between numbers it wont work.</p>
<p>Solution I found but is not working:</p>
<pre><code>select substring(XX,
PatIndex('%[0-9]%', XX),
len(XX))
</code></pre>
<p>For example I have text: '4710000 text' so this substring returns me same text I putted inside of it which is again '4710000 text'. Is there any other way how to do that? Without creating functions or using IFs, begins, variables (@text etc.).</p>
|
[
{
"answer_id": 74656107,
"author": "Stu",
"author_id": 15332650,
"author_profile": "https://Stackoverflow.com/users/15332650",
"pm_score": 0,
"selected": false,
"text": "select Replace(Translate('4710000 text', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', Replicate('*', 26)), '*', '');\n 26"
},
{
"answer_id": 74659135,
"author": "Gary_W",
"author_id": 2543416,
"author_profile": "https://Stackoverflow.com/users/2543416",
"pm_score": 1,
"selected": false,
"text": "with tbl(str) as (\n select '4710000 text'\n)\nSELECT\n (SELECT CAST(CAST((\n SELECT SUBSTRING(str, Number, 1)\n FROM master..spt_values\n WHERE Type='p' AND Number <= LEN(str) AND\n SUBSTRING(str, Number, 1) LIKE '[0-9]' FOR XML Path(''))\n AS xml) AS varchar(MAX)))\nFROM\n tbl\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655748",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17654495/"
] |
74,655,756
|
<p>I have a numpy array of pixel data, something like</p>
<pre><code>0 0 0 0 0 0 0
0 1 3 4 6 1 0
0 2 3 5 2 1 0
0 1 0 0 1 0 0
0 0 0 0 0 0 0
</code></pre>
<p>I would like to get a new array which excludes any outer rows/columns with zeroes, so I just end up with only the non-zero values (that works for any given array) i.e.</p>
<pre><code>1 3 4 6 1
2 3 5 2 1
</code></pre>
<p>So far all I've managed to get is</p>
<pre><code>1 3 4 6 1
2 3 5 2 1
1 0 0 1 0
</code></pre>
<p>using np.argwhere to find the "min" and "max" non-zero values, but this still includes rows/columns with zero and non-zero values in.</p>
<p><a href="https://file.io/VuWLayuqxyeg" rel="nofollow noreferrer">My actual array:</a></p>
<pre><code>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1872 1803 1731 1766 1816 1843 1706 1768 1815 1741 1846 1857 1731 1745 1842 1720 1769 1853 1764 1776 1816 1773 1793 1767 1830 1791 1835 1823 1762 1832 1763 1762 1779 1901 1872 1819 1862 1802 1726 1788 1847 1785 1796 1773 1800 1742 1873 1830 1869 1832 1809 1861 1702 1808 1709 1774 1765 0 0
0 0 1937 1746 1790 1750 1862 1898 1770 1727 1868 1895 1761 1800 1814 1826 1836 1774 1847 1868 1837 1746 1809 1869 1818 1760 1940 1844 1845 1833 1815 1872 1773 1816 1769 1860 1841 1856 1857 1779 1779 1822 1781 1778 1858 1727 1816 1835 1835 1864 1793 1781 1908 1820 1803 1838 1685 1814 1756 0 0
0 0 1754 1895 1806 1818 1829 1733 1865 1903 1764 1850 1847 1913 1856 1757 1782 1826 1818 1875 1843 1777 1716 1825 1761 1842 1843 1925 1791 1879 1887 1873 1789 1769 1805 1915 1825 1829 1817 1840 1882 1762 1840 1878 1830 1862 1789 1884 1798 1802 1847 1875 1825 1773 1803 1850 1817 1885 1792 0 0
0 0 1773 1830 1797 1878 1758 1897 1813 1836 1835 1960 1841 1807 1788 1799 1839 1834 1792 1855 1785 1912 1824 1845 1831 1902 1879 1869 1793 1901 1801 1881 1871 1786 1851 1879 1822 1829 1951 1873 1778 1769 1941 1805 1826 1892 1869 1783 1895 1799 1800 1973 1829 1869 1903 1858 1806 1837 1817 0 0
0 0 1828 1858 1793 1833 1894 1832 1763 1892 1786 1893 1883 1846 1828 1821 1875 1864 1778 1863 1832 1801 1798 1871 1753 1899 1892 1901 1907 1877 1756 1865 1899 1874 1841 1775 1838 1817 1864 1798 1843 1803 1853 1878 1831 1855 1803 1816 1885 1818 1882 1859 1790 1892 1826 1906 1842 1831 1754 0 0
0 0 1811 1831 1837 1828 1792 1768 1818 1797 1766 1924 1849 1921 1881 1795 1883 1954 1811 1804 2006 1849 1841 1808 1867 1918 1755 1765 1881 1852 1930 1848 1807 1876 1776 1790 1849 1855 1942 1871 1908 1822 1810 1794 1889 1780 1857 1879 1845 1858 1901 1839 1744 1743 1811 1853 1841 1854 1864 0 0
0 0 1880 1888 1874 1878 1888 1868 1852 1887 1875 1874 1892 1828 1842 1822 1789 1870 1829 1841 1864 1859 1846 1776 1799 1875 1875 1811 1873 1837 1921 1917 1777 1840 1872 1816 1878 1890 1821 1925 1810 1945 1884 1845 1859 1843 1806 1894 1886 1886 1885 1931 1761 1819 1889 1765 1891 1896 1824 0 0
0 0 1856 1827 1826 1882 1786 1852 1820 1880 1912 1795 1854 1868 1899 1855 1886 1894 1891 1907 1907 1713 1800 1922 1831 1814 1894 1851 1927 1879 1881 1884 1932 1904 1807 1839 1851 1885 1889 1913 1878 1754 1930 1905 1915 1825 1901 1870 1839 1867 1897 1862 1843 1836 1774 1764 1838 1829 1876 0 0
0 0 1858 1840 1897 1884 1861 1910 1860 1879 1882 1860 1831 1828 1846 1820 1889 1830 1852 1880 1842 1917 1872 1839 1820 1888 1871 1838 1817 1939 1905 1890 1832 1925 1780 1862 1793 1887 1836 1846 1852 1939 1922 1874 1865 1890 1864 1863 1918 1819 1861 1851 1854 1886 1898 1888 1796 1917 1754 0 0
0 0 1891 1852 1926 1803 1863 1814 1849 1857 1870 1882 1979 1786 1880 1820 1812 1863 1922 1916 1851 1879 1827 1859 1913 1843 1852 1823 1812 1891 1932 1887 1883 1975 1769 1831 1859 1954 1780 1829 1853 1754 1832 1733 1886 1800 1808 1879 1821 1934 1897 1822 1941 1863 1818 1826 1883 1894 1928 0 0
0 0 1829 1820 1899 1869 1864 1863 1895 1923 1839 1804 1884 1835 1859 1872 1825 1841 1817 1817 1832 1882 1878 1854 1867 1917 1843 1928 1949 1859 1929 1938 1826 1808 1823 1872 1865 1811 1908 1848 1861 1926 1799 1825 1799 1859 1957 1848 1863 1846 1806 1934 1845 1899 1827 1881 1836 1806 1798 0 0
0 0 1794 1914 1880 1892 1849 1862 1819 1927 1873 1886 1857 1907 1840 1897 1857 1867 1925 1972 1871 1975 1854 1843 1856 1872 1875 1927 1819 1905 1948 1881 1904 1832 1863 1854 1811 1869 1797 1946 1805 1779 1824 1919 1886 1817 1845 1844 1909 1885 1900 1826 1867 1817 1833 1870 1888 1879 1875 0 0
0 0 1930 1857 1851 1862 1907 1924 1838 1833 1858 1847 1892 1788 1902 1786 1880 1818 1896 1938 1953 1952 1903 1723 1867 1955 1859 1869 1890 1830 1864 1837 1806 1827 1872 1868 1907 1977 1878 1895 1786 1892 1897 1872 1927 1807 1854 1865 1911 1957 1816 1833 1904 1897 1764 1895 1854 1800 1825 0 0
0 0 1889 1837 1887 1885 1865 1863 1779 1883 1815 1807 1856 1788 1857 1842 1812 1838 1949 1887 1909 1843 1848 1901 1812 1890 1882 1873 1835 1870 1855 1846 1811 1899 1855 1826 1916 1781 1887 1882 1887 1826 1848 1855 1804 1859 1827 1802 1884 1920 1920 1876 1839 1835 1822 1868 1844 1796 1813 0 0
0 0 1845 1883 1857 1790 1738 1915 1963 1899 1878 1890 1813 1779 1836 1832 1895 1863 1874 1899 1946 1851 1967 1816 1860 1860 1793 1852 1917 1904 1879 1911 1747 1939 1938 1849 1917 1894 1845 1895 1877 1903 1870 1868 1878 1857 1921 1858 1843 1800 1930 1820 1752 1827 1885 1927 1902 1842 1857 0 0
0 0 1916 1898 1929 1884 1981 1866 1940 1978 1848 1903 1935 1843 1817 1944 1871 1862 1917 1876 1920 1921 1789 1881 1938 1793 1906 1912 1854 1904 1855 1901 1877 1814 1894 1907 1894 1828 1839 1980 1805 1878 1861 1808 1885 1854 1958 1863 1756 1922 1898 1808 1822 1864 1916 1855 1919 1896 1857 0 0
0 0 1961 1800 1897 1857 1791 1823 1925 1827 1894 1911 1836 1826 1888 1854 1753 1841 1900 1859 1807 1910 1902 1908 1902 1920 1901 1951 1944 1920 1897 1889 1880 1873 1836 1886 1930 1856 1984 1935 1834 1926 1868 1932 1876 1891 1796 1814 1807 1824 1852 1888 1870 1911 1834 1845 1854 1863 1818 0 0
0 0 1885 1947 1836 1886 1803 1982 1901 1939 1930 1876 1832 1888 1886 1855 1845 1910 1877 1836 1910 1888 1904 1905 1859 1899 1834 1879 1893 1861 1896 1931 1855 1890 1964 1939 1798 1894 1844 1913 1906 1920 1873 1807 1875 1837 1900 1904 1919 1845 1895 1844 1793 1855 1926 1786 1917 1834 1898 0 0
0 0 1863 1856 1776 1925 1943 1875 1903 1858 1878 1865 1877 1821 1892 1914 1907 1863 1779 1879 1939 1893 1867 1846 1940 1910 1927 1920 1920 1934 1788 1851 1937 1943 1906 1853 1954 1910 1892 1857 1878 1853 1887 1876 1915 1819 1820 1933 1813 1848 1867 1866 1949 1905 1832 1876 1786 1918 1822 0 0
0 0 1897 1880 1904 1942 1886 1894 1887 1946 1881 1855 1924 1866 1905 1846 1960 1854 1878 1979 1908 1933 1868 1920 1938 1805 1882 1879 1850 1862 1889 1872 1900 1903 1856 1862 1862 1959 1886 1856 1910 1912 1847 1939 1884 1885 1798 1885 1825 1903 1837 1900 1825 1837 1845 1807 1890 1843 1834 0 0
0 0 1879 1896 1898 1980 1844 1889 2013 1938 1950 1877 1849 1916 1879 1871 1946 1916 1890 1945 1942 1934 1914 1821 1902 1938 1878 1906 1823 1927 1912 1948 1932 1927 1859 1819 1933 1927 1915 1789 1970 1930 1931 1831 1856 1890 1831 1852 1863 1884 1821 1842 1861 1843 1751 1872 1790 1852 1819 0 0
0 0 1884 1974 1825 1888 1932 1843 1911 1899 1905 1845 1847 1920 1883 1934 1879 1869 1792 2024 1882 1944 1850 1913 1899 1799 1899 1927 1849 1935 1880 1874 1888 1881 1870 1829 1908 1841 1957 1892 2001 1999 1941 1959 1917 1913 1893 1849 1908 1853 1928 1868 1784 1881 1871 1844 1754 1849 1907 0 0
0 0 1890 1898 1845 1922 1950 1938 1868 1915 1907 1858 1825 1867 1933 1921 1933 1820 1865 1851 1947 1903 1869 1871 1837 1941 1892 1833 1817 1856 1863 1884 1909 1875 1904 1943 1916 2001 1887 1858 1837 1875 1846 1824 1913 1831 1891 1901 1818 1908 1921 1864 1898 1869 1829 1733 1815 1824 1861 0 0
0 0 1902 1934 1894 1839 1894 1869 1962 1809 1891 1865 1957 1950 1926 1861 1954 1876 1782 1883 1959 1852 1849 1891 1887 1756 1861 1905 1894 1913 1831 1828 1906 1875 1981 1887 1990 1922 1825 1995 1831 1852 1864 1922 1878 1895 1897 1819 1851 1873 1799 1901 1810 1880 1922 1875 1858 1841 1881 0 0
0 0 1852 1867 1940 1858 1867 1888 1863 1839 1851 1885 1875 1928 1903 1913 1858 1838 1819 1818 1744 1850 1856 1884 1861 1846 1896 1891 1894 1946 1911 1888 1865 1849 1777 1893 2010 1931 1832 1901 1817 1900 1869 1863 1825 1848 1885 1893 1875 1843 1884 1819 1950 1899 1926 1837 1819 1876 1873 0 0
0 0 1872 1871 1884 1844 1847 1935 1859 1858 1894 1866 1930 1741 1919 1854 1855 1866 1833 1860 1875 1852 1976 1835 1811 1994 1897 1833 1891 1904 1938 1906 1802 1875 1861 1835 1939 1870 1877 1972 1949 1880 1881 1795 1792 1764 1945 1978 1875 1887 1861 1890 1832 1794 1873 1919 1797 1876 1842 0 0
0 0 1897 1884 1845 1842 1878 1918 1835 1866 1868 1858 1908 1900 1868 1756 1841 1746 1842 1891 1852 1889 1869 1886 1802 1902 1859 1935 1978 1880 1918 1865 1779 1889 1824 1781 1902 1890 1836 1833 1908 1865 1916 1916 1902 1796 1878 1858 1825 1914 1921 1829 1848 1862 1863 1847 1847 1831 1888 0 0
0 0 1856 1933 1882 1948 1882 2003 1938 1901 1856 1755 1834 1868 1861 1768 1863 1841 1814 1896 1859 1871 1860 1908 1912 1893 1896 1968 1863 1938 1920 1828 1952 1854 1867 1913 1764 1893 1876 1892 1901 1813 1890 1916 1915 1887 1836 1812 1798 1846 1867 1846 1866 1787 1915 1898 1911 1717 1873 0 0
0 0 1877 1885 1868 1858 1932 1949 1835 1849 1898 1867 1911 1902 1926 1859 1818 1941 1836 1816 1940 1908 1886 1818 1899 1948 1870 1845 1887 1925 1891 1823 1885 1844 1795 1886 1879 1865 1841 1830 1902 1946 1803 1889 1893 1856 1816 1853 1813 1851 1897 1852 1827 1918 1834 1859 1738 1808 1796 0 0
0 0 1838 1839 1997 1844 1855 1867 1953 1898 1876 1865 1882 1808 1857 1856 1850 1832 1892 1802 1858 1882 1896 1925 1840 1905 1895 1838 1865 1922 1904 1843 1958 1890 1907 1796 1858 1871 1906 1815 1888 1870 1902 1717 1868 1823 1888 1905 1821 1812 1928 1867 1787 1826 1821 1905 1839 1747 1755 0 0
0 0 1870 1868 1899 1915 1873 1841 1938 1918 1897 1902 1846 1887 1750 1868 1841 1828 1928 1852 1876 1905 1859 1838 1931 1871 1920 1779 1836 1897 1863 1937 1895 1934 1940 1872 1890 1893 1852 1874 1860 1857 1874 1903 1826 1873 1877 1833 1922 1847 1832 1874 1914 1829 1846 1863 1829 1913 1816 0 0
0 0 1887 1888 1924 1880 1818 1878 1842 1908 1947 1914 1848 1867 1868 1891 1874 1872 1900 1828 1905 1865 1925 1965 1868 1893 1864 1869 1868 1867 1863 1946 1822 1883 1863 1817 1948 1846 1843 1826 1832 1793 1825 1802 2014 1967 1832 1895 1848 1833 1914 1817 1898 1798 1910 1865 1862 1856 1855 0 0
0 0 1914 1862 1828 1924 1897 1984 1931 1925 1896 1895 1908 1933 1889 1813 1836 1921 1855 1841 1935 1917 1897 1890 1880 1904 1851 1937 1936 1920 1856 1798 1810 1819 1871 1855 1905 1832 1941 1844 1827 1855 1901 1846 1826 1762 1870 1899 1873 1853 1902 1839 1884 1841 1838 1816 1846 1860 1787 0 0
0 0 1869 1874 1867 1894 1865 1951 1865 1887 1857 1900 1839 1874 1877 1876 1845 1897 1881 1952 1832 1855 1855 1949 1889 1942 1844 1881 1937 1892 1779 1841 1893 1902 1814 1791 1858 1870 1874 1856 1814 1744 1799 1831 1839 1717 1878 1815 1846 1864 1832 1927 1808 1859 1818 1848 1828 1803 1842 0 0
0 0 1871 1884 1842 1834 1873 1884 1950 1911 1992 1847 1847 1834 1849 1809 1822 1927 1925 1835 1857 1891 1848 1833 1843 1939 1858 1871 1975 1816 1874 1915 1835 1918 1906 1902 1849 1863 1909 1798 1842 1910 1791 1843 1781 1832 1898 1889 1884 1853 1883 1855 1975 1767 1826 1761 1879 1814 1738 0 0
0 0 1886 1909 1873 1850 1908 1894 1907 1872 1837 1773 1847 1926 1884 1882 1831 1832 1942 1897 1844 1950 1886 1978 1947 1815 1843 1785 1886 1914 1911 1883 1824 1873 1934 1943 1831 1906 1813 1820 1831 1870 1824 1875 1866 1913 1800 1818 1930 1860 1808 1884 1834 1921 1717 1812 1816 1947 1829 0 0
0 0 1860 1893 1883 1843 1923 1853 1834 1858 1922 1944 1942 1839 1813 1852 1889 1945 1902 1977 1929 1881 1850 1967 1844 1877 1970 1850 1941 1897 1814 1894 1841 1837 1821 1866 1777 1805 1851 1889 1838 1843 1853 1776 1907 1909 1846 1781 1775 1876 1941 1851 1849 1854 1813 1885 1912 1887 1776 0 0
0 0 1819 1896 1911 1936 1887 1847 1874 1894 1855 1869 1843 1864 1921 1883 1875 1926 1866 1923 1886 1889 1844 1896 2002 1944 1909 1858 1927 1870 1882 1886 1899 1894 1809 1904 1786 1920 1908 1888 1901 1859 1857 1793 1880 1828 1809 1839 1905 1893 1849 1920 1837 1868 1910 1850 1873 1900 1721 0 0
0 0 1861 1895 1819 1865 1741 1797 1832 1849 1901 1869 1870 1811 1786 1910 1936 1961 1907 1899 1949 1863 1845 1885 1881 1831 1884 1937 1860 1906 1873 1838 1859 1898 1924 1863 1902 1881 1851 1880 1945 1851 1929 1846 1843 1879 1774 1826 1788 1871 1918 1780 1825 1853 1782 1852 1861 1867 1844 0 0
0 0 1822 1867 1806 1745 1942 1836 1841 1861 1787 1867 1947 1906 1826 1822 1935 1787 1879 1920 1830 1928 1879 1837 1921 1923 1855 1932 1844 1841 1917 1928 1865 1915 1873 1839 1846 1910 1896 1903 1911 1838 1857 1905 1870 1811 1899 1874 1860 1822 1935 1757 1862 1807 1856 1868 1786 1919 1887 0 0
0 0 1850 1926 1855 1766 1858 1815 1894 1861 1911 1910 1846 1861 1857 1800 1837 1784 1912 1937 1916 1942 1929 1866 1905 1916 1923 1922 1899 1838 1910 1872 1778 1849 1863 1868 1870 1828 1880 1793 1889 1937 1857 1888 1882 1946 1841 1838 1800 1819 1874 1918 1879 1895 1874 1884 1861 1761 1800 0 0
0 0 0 1782 0 0 0 0 1879 0 0 0 0 1884 0 0 0 0 0 0 0 1893 0 1932 1909 1938 0 0 0 0 0 1928 0 0 1816 0 0 1921 1887 0 0 0 0 1876 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1907 0 0 0 0 1944 0 0 0 0 1954 0 0 0 0 0 0 0 1930 0 1875 1882 1912 0 0 0 0 0 1890 0 0 1875 0 0 1873 1872 0 0 0 0 1897 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
</code></pre>
|
[
{
"answer_id": 74656220,
"author": "Jiya",
"author_id": 12017533,
"author_profile": "https://Stackoverflow.com/users/12017533",
"pm_score": 0,
"selected": false,
"text": "[[ 0 0 0 ... 0 0 0]\n [ 0 0 0 ... 0 0 0]\n [ 0 0 1872 ... 1765 0 0]\n ...\n [ 0 0 1850 ... 1800 0 0]\n [ 0 0 0 ... 0 0 0]\n [ 0 0 0 ... 0 0 0]]\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 1872 1803 1731 1766 1816 1843 1706 1768 1815 1741 1846 1857 1731 1745 1842 1720 1769 1853 1764 1776 1816 1773 1793 1767 1830 1791 1835 1823 1762 1832 1763 1762 1779 1901 1872 1819 1862 1802 1726 1788 1847 1785 1796 1773 1800 1742 1873 1830 1869 1832 1809 1861 1702 1808 1709 1774 1765 0 0\n0 0 1937 1746 1790 1750 1862 1898 1770 1727 1868 1895 1761 1800 1814 1826 1836 1774 1847 1868 1837 1746 1809 1869 1818 1760 1940 1844 1845 1833 1815 1872 1773 1816 1769 1860 1841 1856 1857 1779 1779 1822 1781 1778 1858 1727 1816 1835 1835 1864 1793 1781 1908 1820 1803 1838 1685 1814 1756 0 0\n0 0 1754 1895 1806 1818 1829 1733 1865 1903 1764 1850 1847 1913 1856 1757 1782 1826 1818 1875 1843 1777 1716 1825 1761 1842 1843 1925 1791 1879 1887 1873 1789 1769 1805 1915 1825 1829 1817 1840 1882 1762 1840 1878 1830 1862 1789 1884 1798 1802 1847 1875 1825 1773 1803 1850 1817 1885 1792 0 0\n0 0 1773 1830 1797 1878 1758 1897 1813 1836 1835 1960 1841 1807 1788 1799 1839 1834 1792 1855 1785 1912 1824 1845 1831 1902 1879 1869 1793 1901 1801 1881 1871 1786 1851 1879 1822 1829 1951 1873 1778 1769 1941 1805 1826 1892 1869 1783 1895 1799 1800 1973 1829 1869 1903 1858 1806 1837 1817 0 0\n0 0 1828 1858 1793 1833 1894 1832 1763 1892 1786 1893 1883 1846 1828 1821 1875 1864 1778 1863 1832 1801 1798 1871 1753 1899 1892 1901 1907 1877 1756 1865 1899 1874 1841 1775 1838 1817 1864 1798 1843 1803 1853 1878 1831 1855 1803 1816 1885 1818 1882 1859 1790 1892 1826 1906 1842 1831 1754 0 0\n0 0 1811 1831 1837 1828 1792 1768 1818 1797 1766 1924 1849 1921 1881 1795 1883 1954 1811 1804 2006 1849 1841 1808 1867 1918 1755 1765 1881 1852 1930 1848 1807 1876 1776 1790 1849 1855 1942 1871 1908 1822 1810 1794 1889 1780 1857 1879 1845 1858 1901 1839 1744 1743 1811 1853 1841 1854 1864 0 0\n0 0 1880 1888 1874 1878 1888 1868 1852 1887 1875 1874 1892 1828 1842 1822 1789 1870 1829 1841 1864 1859 1846 1776 1799 1875 1875 1811 1873 1837 1921 1917 1777 1840 1872 1816 1878 1890 1821 1925 1810 1945 1884 1845 1859 1843 1806 1894 1886 1886 1885 1931 1761 1819 1889 1765 1891 1896 1824 0 0\n0 0 1856 1827 1826 1882 1786 1852 1820 1880 1912 1795 1854 1868 1899 1855 1886 1894 1891 1907 1907 1713 1800 1922 1831 1814 1894 1851 1927 1879 1881 1884 1932 1904 1807 1839 1851 1885 1889 1913 1878 1754 1930 1905 1915 1825 1901 1870 1839 1867 1897 1862 1843 1836 1774 1764 1838 1829 1876 0 0\n0 0 1858 1840 1897 1884 1861 1910 1860 1879 1882 1860 1831 1828 1846 1820 1889 1830 1852 1880 1842 1917 1872 1839 1820 1888 1871 1838 1817 1939 1905 1890 1832 1925 1780 1862 1793 1887 1836 1846 1852 1939 1922 1874 1865 1890 1864 1863 1918 1819 1861 1851 1854 1886 1898 1888 1796 1917 1754 0 0\n0 0 1891 1852 1926 1803 1863 1814 1849 1857 1870 1882 1979 1786 1880 1820 1812 1863 1922 1916 1851 1879 1827 1859 1913 1843 1852 1823 1812 1891 1932 1887 1883 1975 1769 1831 1859 1954 1780 1829 1853 1754 1832 1733 1886 1800 1808 1879 1821 1934 1897 1822 1941 1863 1818 1826 1883 1894 1928 0 0\n0 0 1829 1820 1899 1869 1864 1863 1895 1923 1839 1804 1884 1835 1859 1872 1825 1841 1817 1817 1832 1882 1878 1854 1867 1917 1843 1928 1949 1859 1929 1938 1826 1808 1823 1872 1865 1811 1908 1848 1861 1926 1799 1825 1799 1859 1957 1848 1863 1846 1806 1934 1845 1899 1827 1881 1836 1806 1798 0 0\n0 0 1794 1914 1880 1892 1849 1862 1819 1927 1873 1886 1857 1907 1840 1897 1857 1867 1925 1972 1871 1975 1854 1843 1856 1872 1875 1927 1819 1905 1948 1881 1904 1832 1863 1854 1811 1869 1797 1946 1805 1779 1824 1919 1886 1817 1845 1844 1909 1885 1900 1826 1867 1817 1833 1870 1888 1879 1875 0 0\n0 0 1930 1857 1851 1862 1907 1924 1838 1833 1858 1847 1892 1788 1902 1786 1880 1818 1896 1938 1953 1952 1903 1723 1867 1955 1859 1869 1890 1830 1864 1837 1806 1827 1872 1868 1907 1977 1878 1895 1786 1892 1897 1872 1927 1807 1854 1865 1911 1957 1816 1833 1904 1897 1764 1895 1854 1800 1825 0 0\n0 0 1889 1837 1887 1885 1865 1863 1779 1883 1815 1807 1856 1788 1857 1842 1812 1838 1949 1887 1909 1843 1848 1901 1812 1890 1882 1873 1835 1870 1855 1846 1811 1899 1855 1826 1916 1781 1887 1882 1887 1826 1848 1855 1804 1859 1827 1802 1884 1920 1920 1876 1839 1835 1822 1868 1844 1796 1813 0 0\n0 0 1845 1883 1857 1790 1738 1915 1963 1899 1878 1890 1813 1779 1836 1832 1895 1863 1874 1899 1946 1851 1967 1816 1860 1860 1793 1852 1917 1904 1879 1911 1747 1939 1938 1849 1917 1894 1845 1895 1877 1903 1870 1868 1878 1857 1921 1858 1843 1800 1930 1820 1752 1827 1885 1927 1902 1842 1857 0 0\n0 0 1916 1898 1929 1884 1981 1866 1940 1978 1848 1903 1935 1843 1817 1944 1871 1862 1917 1876 1920 1921 1789 1881 1938 1793 1906 1912 1854 1904 1855 1901 1877 1814 1894 1907 1894 1828 1839 1980 1805 1878 1861 1808 1885 1854 1958 1863 1756 1922 1898 1808 1822 1864 1916 1855 1919 1896 1857 0 0\n0 0 1961 1800 1897 1857 1791 1823 1925 1827 1894 1911 1836 1826 1888 1854 1753 1841 1900 1859 1807 1910 1902 1908 1902 1920 1901 1951 1944 1920 1897 1889 1880 1873 1836 1886 1930 1856 1984 1935 1834 1926 1868 1932 1876 1891 1796 1814 1807 1824 1852 1888 1870 1911 1834 1845 1854 1863 1818 0 0\n0 0 1885 1947 1836 1886 1803 1982 1901 1939 1930 1876 1832 1888 1886 1855 1845 1910 1877 1836 1910 1888 1904 1905 1859 1899 1834 1879 1893 1861 1896 1931 1855 1890 1964 1939 1798 1894 1844 1913 1906 1920 1873 1807 1875 1837 1900 1904 1919 1845 1895 1844 1793 1855 1926 1786 1917 1834 1898 0 0\n0 0 1863 1856 1776 1925 1943 1875 1903 1858 1878 1865 1877 1821 1892 1914 1907 1863 1779 1879 1939 1893 1867 1846 1940 1910 1927 1920 1920 1934 1788 1851 1937 1943 1906 1853 1954 1910 1892 1857 1878 1853 1887 1876 1915 1819 1820 1933 1813 1848 1867 1866 1949 1905 1832 1876 1786 1918 1822 0 0\n0 0 1897 1880 1904 1942 1886 1894 1887 1946 1881 1855 1924 1866 1905 1846 1960 1854 1878 1979 1908 1933 1868 1920 1938 1805 1882 1879 1850 1862 1889 1872 1900 1903 1856 1862 1862 1959 1886 1856 1910 1912 1847 1939 1884 1885 1798 1885 1825 1903 1837 1900 1825 1837 1845 1807 1890 1843 1834 0 0\n0 0 1879 1896 1898 1980 1844 1889 2013 1938 1950 1877 1849 1916 1879 1871 1946 1916 1890 1945 1942 1934 1914 1821 1902 1938 1878 1906 1823 1927 1912 1948 1932 1927 1859 1819 1933 1927 1915 1789 1970 1930 1931 1831 1856 1890 1831 1852 1863 1884 1821 1842 1861 1843 1751 1872 1790 1852 1819 0 0\n0 0 1884 1974 1825 1888 1932 1843 1911 1899 1905 1845 1847 1920 1883 1934 1879 1869 1792 2024 1882 1944 1850 1913 1899 1799 1899 1927 1849 1935 1880 1874 1888 1881 1870 1829 1908 1841 1957 1892 2001 1999 1941 1959 1917 1913 1893 1849 1908 1853 1928 1868 1784 1881 1871 1844 1754 1849 1907 0 0\n0 0 1890 1898 1845 1922 1950 1938 1868 1915 1907 1858 1825 1867 1933 1921 1933 1820 1865 1851 1947 1903 1869 1871 1837 1941 1892 1833 1817 1856 1863 1884 1909 1875 1904 1943 1916 2001 1887 1858 1837 1875 1846 1824 1913 1831 1891 1901 1818 1908 1921 1864 1898 1869 1829 1733 1815 1824 1861 0 0\n0 0 1902 1934 1894 1839 1894 1869 1962 1809 1891 1865 1957 1950 1926 1861 1954 1876 1782 1883 1959 1852 1849 1891 1887 1756 1861 1905 1894 1913 1831 1828 1906 1875 1981 1887 1990 1922 1825 1995 1831 1852 1864 1922 1878 1895 1897 1819 1851 1873 1799 1901 1810 1880 1922 1875 1858 1841 1881 0 0\n0 0 1852 1867 1940 1858 1867 1888 1863 1839 1851 1885 1875 1928 1903 1913 1858 1838 1819 1818 1744 1850 1856 1884 1861 1846 1896 1891 1894 1946 1911 1888 1865 1849 1777 1893 2010 1931 1832 1901 1817 1900 1869 1863 1825 1848 1885 1893 1875 1843 1884 1819 1950 1899 1926 1837 1819 1876 1873 0 0\n0 0 1872 1871 1884 1844 1847 1935 1859 1858 1894 1866 1930 1741 1919 1854 1855 1866 1833 1860 1875 1852 1976 1835 1811 1994 1897 1833 1891 1904 1938 1906 1802 1875 1861 1835 1939 1870 1877 1972 1949 1880 1881 1795 1792 1764 1945 1978 1875 1887 1861 1890 1832 1794 1873 1919 1797 1876 1842 0 0\n0 0 1897 1884 1845 1842 1878 1918 1835 1866 1868 1858 1908 1900 1868 1756 1841 1746 1842 1891 1852 1889 1869 1886 1802 1902 1859 1935 1978 1880 1918 1865 1779 1889 1824 1781 1902 1890 1836 1833 1908 1865 1916 1916 1902 1796 1878 1858 1825 1914 1921 1829 1848 1862 1863 1847 1847 1831 1888 0 0\n0 0 1856 1933 1882 1948 1882 2003 1938 1901 1856 1755 1834 1868 1861 1768 1863 1841 1814 1896 1859 1871 1860 1908 1912 1893 1896 1968 1863 1938 1920 1828 1952 1854 1867 1913 1764 1893 1876 1892 1901 1813 1890 1916 1915 1887 1836 1812 1798 1846 1867 1846 1866 1787 1915 1898 1911 1717 1873 0 0\n0 0 1877 1885 1868 1858 1932 1949 1835 1849 1898 1867 1911 1902 1926 1859 1818 1941 1836 1816 1940 1908 1886 1818 1899 1948 1870 1845 1887 1925 1891 1823 1885 1844 1795 1886 1879 1865 1841 1830 1902 1946 1803 1889 1893 1856 1816 1853 1813 1851 1897 1852 1827 1918 1834 1859 1738 1808 1796 0 0\n0 0 1838 1839 1997 1844 1855 1867 1953 1898 1876 1865 1882 1808 1857 1856 1850 1832 1892 1802 1858 1882 1896 1925 1840 1905 1895 1838 1865 1922 1904 1843 1958 1890 1907 1796 1858 1871 1906 1815 1888 1870 1902 1717 1868 1823 1888 1905 1821 1812 1928 1867 1787 1826 1821 1905 1839 1747 1755 0 0\n0 0 1870 1868 1899 1915 1873 1841 1938 1918 1897 1902 1846 1887 1750 1868 1841 1828 1928 1852 1876 1905 1859 1838 1931 1871 1920 1779 1836 1897 1863 1937 1895 1934 1940 1872 1890 1893 1852 1874 1860 1857 1874 1903 1826 1873 1877 1833 1922 1847 1832 1874 1914 1829 1846 1863 1829 1913 1816 0 0\n0 0 1887 1888 1924 1880 1818 1878 1842 1908 1947 1914 1848 1867 1868 1891 1874 1872 1900 1828 1905 1865 1925 1965 1868 1893 1864 1869 1868 1867 1863 1946 1822 1883 1863 1817 1948 1846 1843 1826 1832 1793 1825 1802 2014 1967 1832 1895 1848 1833 1914 1817 1898 1798 1910 1865 1862 1856 1855 0 0\n0 0 1914 1862 1828 1924 1897 1984 1931 1925 1896 1895 1908 1933 1889 1813 1836 1921 1855 1841 1935 1917 1897 1890 1880 1904 1851 1937 1936 1920 1856 1798 1810 1819 1871 1855 1905 1832 1941 1844 1827 1855 1901 1846 1826 1762 1870 1899 1873 1853 1902 1839 1884 1841 1838 1816 1846 1860 1787 0 0\n0 0 1869 1874 1867 1894 1865 1951 1865 1887 1857 1900 1839 1874 1877 1876 1845 1897 1881 1952 1832 1855 1855 1949 1889 1942 1844 1881 1937 1892 1779 1841 1893 1902 1814 1791 1858 1870 1874 1856 1814 1744 1799 1831 1839 1717 1878 1815 1846 1864 1832 1927 1808 1859 1818 1848 1828 1803 1842 0 0\n0 0 1871 1884 1842 1834 1873 1884 1950 1911 1992 1847 1847 1834 1849 1809 1822 1927 1925 1835 1857 1891 1848 1833 1843 1939 1858 1871 1975 1816 1874 1915 1835 1918 1906 1902 1849 1863 1909 1798 1842 1910 1791 1843 1781 1832 1898 1889 1884 1853 1883 1855 1975 1767 1826 1761 1879 1814 1738 0 0\n0 0 1886 1909 1873 1850 1908 1894 1907 1872 1837 1773 1847 1926 1884 1882 1831 1832 1942 1897 1844 1950 1886 1978 1947 1815 1843 1785 1886 1914 1911 1883 1824 1873 1934 1943 1831 1906 1813 1820 1831 1870 1824 1875 1866 1913 1800 1818 1930 1860 1808 1884 1834 1921 1717 1812 1816 1947 1829 0 0\n0 0 1860 1893 1883 1843 1923 1853 1834 1858 1922 1944 1942 1839 1813 1852 1889 1945 1902 1977 1929 1881 1850 1967 1844 1877 1970 1850 1941 1897 1814 1894 1841 1837 1821 1866 1777 1805 1851 1889 1838 1843 1853 1776 1907 1909 1846 1781 1775 1876 1941 1851 1849 1854 1813 1885 1912 1887 1776 0 0\n0 0 1819 1896 1911 1936 1887 1847 1874 1894 1855 1869 1843 1864 1921 1883 1875 1926 1866 1923 1886 1889 1844 1896 2002 1944 1909 1858 1927 1870 1882 1886 1899 1894 1809 1904 1786 1920 1908 1888 1901 1859 1857 1793 1880 1828 1809 1839 1905 1893 1849 1920 1837 1868 1910 1850 1873 1900 1721 0 0\n0 0 1861 1895 1819 1865 1741 1797 1832 1849 1901 1869 1870 1811 1786 1910 1936 1961 1907 1899 1949 1863 1845 1885 1881 1831 1884 1937 1860 1906 1873 1838 1859 1898 1924 1863 1902 1881 1851 1880 1945 1851 1929 1846 1843 1879 1774 1826 1788 1871 1918 1780 1825 1853 1782 1852 1861 1867 1844 0 0\n0 0 1822 1867 1806 1745 1942 1836 1841 1861 1787 1867 1947 1906 1826 1822 1935 1787 1879 1920 1830 1928 1879 1837 1921 1923 1855 1932 1844 1841 1917 1928 1865 1915 1873 1839 1846 1910 1896 1903 1911 1838 1857 1905 1870 1811 1899 1874 1860 1822 1935 1757 1862 1807 1856 1868 1786 1919 1887 0 0\n0 0 1850 1926 1855 1766 1858 1815 1894 1861 1911 1910 1846 1861 1857 1800 1837 1784 1912 1937 1916 1942 1929 1866 1905 1916 1923 1922 1899 1838 1910 1872 1778 1849 1863 1868 1870 1828 1880 1793 1889 1937 1857 1888 1882 1946 1841 1838 1800 1819 1874 1918 1879 1895 1874 1884 1861 1761 1800 0 0\n0 0 0 1782 0 0 0 0 1879 0 0 0 0 1884 0 0 0 0 0 0 0 1893 0 1932 1909 1938 0 0 0 0 0 1928 0 0 1816 0 0 1921 1887 0 0 0 0 1876 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 1907 0 0 0 0 1944 0 0 0 0 1954 0 0 0 0 0 0 0 1930 0 1875 1882 1912 0 0 0 0 0 1890 0 0 1875 0 0 1873 1872 0 0 0 0 1897 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n np_input = np.load('array.npy')\n\n# Remove all zeros from column\nnp_input = np_input[:, (np_input != 0).any(axis=0)]\n\n# Remove all zeros from row\nnp_input = np_input[(np_input != 0).any(axis=1)]\n\n# converting to list of lists\nnp_input = np_input.tolist()\n\n# Remove sub list that contains a zero\nnp_input = [x for x in np_input if 0 not in x]\n\n# Convert pixles_input to numpy array\nfinal_np = np.array(np_input)\n\nprint(final_np)\n np_input = np.load('array.npy')\nfinal_np = np.array([x for x in np_input[:, (np_input != 0).any(axis=0)][(np_input != 0).any(axis=1)].tolist() if 0 not in x])\nprint(final_np)\n [[1872 1803 1731 ... 1709 1774 1765]\n [1937 1746 1790 ... 1685 1814 1756]\n [1754 1895 1806 ... 1817 1885 1792]\n ...\n [1861 1895 1819 ... 1861 1867 1844]\n [1822 1867 1806 ... 1786 1919 1887]\n [1850 1926 1855 ... 1861 1761 1800]]\n 1872 1803 1731 1766 1816 1843 1706 1768 1815 1741 1846 1857 1731 1745 1842 1720 1769 1853 1764 1776 1816 1773 1793 1767 1830 1791 1835 1823 1762 1832 1763 1762 1779 1901 1872 1819 1862 1802 1726 1788 1847 1785 1796 1773 1800 1742 1873 1830 1869 1832 1809 1861 1702 1808 1709 1774 1765\n1937 1746 1790 1750 1862 1898 1770 1727 1868 1895 1761 1800 1814 1826 1836 1774 1847 1868 1837 1746 1809 1869 1818 1760 1940 1844 1845 1833 1815 1872 1773 1816 1769 1860 1841 1856 1857 1779 1779 1822 1781 1778 1858 1727 1816 1835 1835 1864 1793 1781 1908 1820 1803 1838 1685 1814 1756\n1754 1895 1806 1818 1829 1733 1865 1903 1764 1850 1847 1913 1856 1757 1782 1826 1818 1875 1843 1777 1716 1825 1761 1842 1843 1925 1791 1879 1887 1873 1789 1769 1805 1915 1825 1829 1817 1840 1882 1762 1840 1878 1830 1862 1789 1884 1798 1802 1847 1875 1825 1773 1803 1850 1817 1885 1792\n1773 1830 1797 1878 1758 1897 1813 1836 1835 1960 1841 1807 1788 1799 1839 1834 1792 1855 1785 1912 1824 1845 1831 1902 1879 1869 1793 1901 1801 1881 1871 1786 1851 1879 1822 1829 1951 1873 1778 1769 1941 1805 1826 1892 1869 1783 1895 1799 1800 1973 1829 1869 1903 1858 1806 1837 1817\n1828 1858 1793 1833 1894 1832 1763 1892 1786 1893 1883 1846 1828 1821 1875 1864 1778 1863 1832 1801 1798 1871 1753 1899 1892 1901 1907 1877 1756 1865 1899 1874 1841 1775 1838 1817 1864 1798 1843 1803 1853 1878 1831 1855 1803 1816 1885 1818 1882 1859 1790 1892 1826 1906 1842 1831 1754\n1811 1831 1837 1828 1792 1768 1818 1797 1766 1924 1849 1921 1881 1795 1883 1954 1811 1804 2006 1849 1841 1808 1867 1918 1755 1765 1881 1852 1930 1848 1807 1876 1776 1790 1849 1855 1942 1871 1908 1822 1810 1794 1889 1780 1857 1879 1845 1858 1901 1839 1744 1743 1811 1853 1841 1854 1864\n1880 1888 1874 1878 1888 1868 1852 1887 1875 1874 1892 1828 1842 1822 1789 1870 1829 1841 1864 1859 1846 1776 1799 1875 1875 1811 1873 1837 1921 1917 1777 1840 1872 1816 1878 1890 1821 1925 1810 1945 1884 1845 1859 1843 1806 1894 1886 1886 1885 1931 1761 1819 1889 1765 1891 1896 1824\n1856 1827 1826 1882 1786 1852 1820 1880 1912 1795 1854 1868 1899 1855 1886 1894 1891 1907 1907 1713 1800 1922 1831 1814 1894 1851 1927 1879 1881 1884 1932 1904 1807 1839 1851 1885 1889 1913 1878 1754 1930 1905 1915 1825 1901 1870 1839 1867 1897 1862 1843 1836 1774 1764 1838 1829 1876\n1858 1840 1897 1884 1861 1910 1860 1879 1882 1860 1831 1828 1846 1820 1889 1830 1852 1880 1842 1917 1872 1839 1820 1888 1871 1838 1817 1939 1905 1890 1832 1925 1780 1862 1793 1887 1836 1846 1852 1939 1922 1874 1865 1890 1864 1863 1918 1819 1861 1851 1854 1886 1898 1888 1796 1917 1754\n1891 1852 1926 1803 1863 1814 1849 1857 1870 1882 1979 1786 1880 1820 1812 1863 1922 1916 1851 1879 1827 1859 1913 1843 1852 1823 1812 1891 1932 1887 1883 1975 1769 1831 1859 1954 1780 1829 1853 1754 1832 1733 1886 1800 1808 1879 1821 1934 1897 1822 1941 1863 1818 1826 1883 1894 1928\n1829 1820 1899 1869 1864 1863 1895 1923 1839 1804 1884 1835 1859 1872 1825 1841 1817 1817 1832 1882 1878 1854 1867 1917 1843 1928 1949 1859 1929 1938 1826 1808 1823 1872 1865 1811 1908 1848 1861 1926 1799 1825 1799 1859 1957 1848 1863 1846 1806 1934 1845 1899 1827 1881 1836 1806 1798\n1794 1914 1880 1892 1849 1862 1819 1927 1873 1886 1857 1907 1840 1897 1857 1867 1925 1972 1871 1975 1854 1843 1856 1872 1875 1927 1819 1905 1948 1881 1904 1832 1863 1854 1811 1869 1797 1946 1805 1779 1824 1919 1886 1817 1845 1844 1909 1885 1900 1826 1867 1817 1833 1870 1888 1879 1875\n1930 1857 1851 1862 1907 1924 1838 1833 1858 1847 1892 1788 1902 1786 1880 1818 1896 1938 1953 1952 1903 1723 1867 1955 1859 1869 1890 1830 1864 1837 1806 1827 1872 1868 1907 1977 1878 1895 1786 1892 1897 1872 1927 1807 1854 1865 1911 1957 1816 1833 1904 1897 1764 1895 1854 1800 1825\n1889 1837 1887 1885 1865 1863 1779 1883 1815 1807 1856 1788 1857 1842 1812 1838 1949 1887 1909 1843 1848 1901 1812 1890 1882 1873 1835 1870 1855 1846 1811 1899 1855 1826 1916 1781 1887 1882 1887 1826 1848 1855 1804 1859 1827 1802 1884 1920 1920 1876 1839 1835 1822 1868 1844 1796 1813\n1845 1883 1857 1790 1738 1915 1963 1899 1878 1890 1813 1779 1836 1832 1895 1863 1874 1899 1946 1851 1967 1816 1860 1860 1793 1852 1917 1904 1879 1911 1747 1939 1938 1849 1917 1894 1845 1895 1877 1903 1870 1868 1878 1857 1921 1858 1843 1800 1930 1820 1752 1827 1885 1927 1902 1842 1857\n1916 1898 1929 1884 1981 1866 1940 1978 1848 1903 1935 1843 1817 1944 1871 1862 1917 1876 1920 1921 1789 1881 1938 1793 1906 1912 1854 1904 1855 1901 1877 1814 1894 1907 1894 1828 1839 1980 1805 1878 1861 1808 1885 1854 1958 1863 1756 1922 1898 1808 1822 1864 1916 1855 1919 1896 1857\n1961 1800 1897 1857 1791 1823 1925 1827 1894 1911 1836 1826 1888 1854 1753 1841 1900 1859 1807 1910 1902 1908 1902 1920 1901 1951 1944 1920 1897 1889 1880 1873 1836 1886 1930 1856 1984 1935 1834 1926 1868 1932 1876 1891 1796 1814 1807 1824 1852 1888 1870 1911 1834 1845 1854 1863 1818\n1885 1947 1836 1886 1803 1982 1901 1939 1930 1876 1832 1888 1886 1855 1845 1910 1877 1836 1910 1888 1904 1905 1859 1899 1834 1879 1893 1861 1896 1931 1855 1890 1964 1939 1798 1894 1844 1913 1906 1920 1873 1807 1875 1837 1900 1904 1919 1845 1895 1844 1793 1855 1926 1786 1917 1834 1898\n1863 1856 1776 1925 1943 1875 1903 1858 1878 1865 1877 1821 1892 1914 1907 1863 1779 1879 1939 1893 1867 1846 1940 1910 1927 1920 1920 1934 1788 1851 1937 1943 1906 1853 1954 1910 1892 1857 1878 1853 1887 1876 1915 1819 1820 1933 1813 1848 1867 1866 1949 1905 1832 1876 1786 1918 1822\n1897 1880 1904 1942 1886 1894 1887 1946 1881 1855 1924 1866 1905 1846 1960 1854 1878 1979 1908 1933 1868 1920 1938 1805 1882 1879 1850 1862 1889 1872 1900 1903 1856 1862 1862 1959 1886 1856 1910 1912 1847 1939 1884 1885 1798 1885 1825 1903 1837 1900 1825 1837 1845 1807 1890 1843 1834\n1879 1896 1898 1980 1844 1889 2013 1938 1950 1877 1849 1916 1879 1871 1946 1916 1890 1945 1942 1934 1914 1821 1902 1938 1878 1906 1823 1927 1912 1948 1932 1927 1859 1819 1933 1927 1915 1789 1970 1930 1931 1831 1856 1890 1831 1852 1863 1884 1821 1842 1861 1843 1751 1872 1790 1852 1819\n1884 1974 1825 1888 1932 1843 1911 1899 1905 1845 1847 1920 1883 1934 1879 1869 1792 2024 1882 1944 1850 1913 1899 1799 1899 1927 1849 1935 1880 1874 1888 1881 1870 1829 1908 1841 1957 1892 2001 1999 1941 1959 1917 1913 1893 1849 1908 1853 1928 1868 1784 1881 1871 1844 1754 1849 1907\n1890 1898 1845 1922 1950 1938 1868 1915 1907 1858 1825 1867 1933 1921 1933 1820 1865 1851 1947 1903 1869 1871 1837 1941 1892 1833 1817 1856 1863 1884 1909 1875 1904 1943 1916 2001 1887 1858 1837 1875 1846 1824 1913 1831 1891 1901 1818 1908 1921 1864 1898 1869 1829 1733 1815 1824 1861\n1902 1934 1894 1839 1894 1869 1962 1809 1891 1865 1957 1950 1926 1861 1954 1876 1782 1883 1959 1852 1849 1891 1887 1756 1861 1905 1894 1913 1831 1828 1906 1875 1981 1887 1990 1922 1825 1995 1831 1852 1864 1922 1878 1895 1897 1819 1851 1873 1799 1901 1810 1880 1922 1875 1858 1841 1881\n1852 1867 1940 1858 1867 1888 1863 1839 1851 1885 1875 1928 1903 1913 1858 1838 1819 1818 1744 1850 1856 1884 1861 1846 1896 1891 1894 1946 1911 1888 1865 1849 1777 1893 2010 1931 1832 1901 1817 1900 1869 1863 1825 1848 1885 1893 1875 1843 1884 1819 1950 1899 1926 1837 1819 1876 1873\n1872 1871 1884 1844 1847 1935 1859 1858 1894 1866 1930 1741 1919 1854 1855 1866 1833 1860 1875 1852 1976 1835 1811 1994 1897 1833 1891 1904 1938 1906 1802 1875 1861 1835 1939 1870 1877 1972 1949 1880 1881 1795 1792 1764 1945 1978 1875 1887 1861 1890 1832 1794 1873 1919 1797 1876 1842\n1897 1884 1845 1842 1878 1918 1835 1866 1868 1858 1908 1900 1868 1756 1841 1746 1842 1891 1852 1889 1869 1886 1802 1902 1859 1935 1978 1880 1918 1865 1779 1889 1824 1781 1902 1890 1836 1833 1908 1865 1916 1916 1902 1796 1878 1858 1825 1914 1921 1829 1848 1862 1863 1847 1847 1831 1888\n1856 1933 1882 1948 1882 2003 1938 1901 1856 1755 1834 1868 1861 1768 1863 1841 1814 1896 1859 1871 1860 1908 1912 1893 1896 1968 1863 1938 1920 1828 1952 1854 1867 1913 1764 1893 1876 1892 1901 1813 1890 1916 1915 1887 1836 1812 1798 1846 1867 1846 1866 1787 1915 1898 1911 1717 1873\n1877 1885 1868 1858 1932 1949 1835 1849 1898 1867 1911 1902 1926 1859 1818 1941 1836 1816 1940 1908 1886 1818 1899 1948 1870 1845 1887 1925 1891 1823 1885 1844 1795 1886 1879 1865 1841 1830 1902 1946 1803 1889 1893 1856 1816 1853 1813 1851 1897 1852 1827 1918 1834 1859 1738 1808 1796\n1838 1839 1997 1844 1855 1867 1953 1898 1876 1865 1882 1808 1857 1856 1850 1832 1892 1802 1858 1882 1896 1925 1840 1905 1895 1838 1865 1922 1904 1843 1958 1890 1907 1796 1858 1871 1906 1815 1888 1870 1902 1717 1868 1823 1888 1905 1821 1812 1928 1867 1787 1826 1821 1905 1839 1747 1755\n1870 1868 1899 1915 1873 1841 1938 1918 1897 1902 1846 1887 1750 1868 1841 1828 1928 1852 1876 1905 1859 1838 1931 1871 1920 1779 1836 1897 1863 1937 1895 1934 1940 1872 1890 1893 1852 1874 1860 1857 1874 1903 1826 1873 1877 1833 1922 1847 1832 1874 1914 1829 1846 1863 1829 1913 1816\n1887 1888 1924 1880 1818 1878 1842 1908 1947 1914 1848 1867 1868 1891 1874 1872 1900 1828 1905 1865 1925 1965 1868 1893 1864 1869 1868 1867 1863 1946 1822 1883 1863 1817 1948 1846 1843 1826 1832 1793 1825 1802 2014 1967 1832 1895 1848 1833 1914 1817 1898 1798 1910 1865 1862 1856 1855\n1914 1862 1828 1924 1897 1984 1931 1925 1896 1895 1908 1933 1889 1813 1836 1921 1855 1841 1935 1917 1897 1890 1880 1904 1851 1937 1936 1920 1856 1798 1810 1819 1871 1855 1905 1832 1941 1844 1827 1855 1901 1846 1826 1762 1870 1899 1873 1853 1902 1839 1884 1841 1838 1816 1846 1860 1787\n1869 1874 1867 1894 1865 1951 1865 1887 1857 1900 1839 1874 1877 1876 1845 1897 1881 1952 1832 1855 1855 1949 1889 1942 1844 1881 1937 1892 1779 1841 1893 1902 1814 1791 1858 1870 1874 1856 1814 1744 1799 1831 1839 1717 1878 1815 1846 1864 1832 1927 1808 1859 1818 1848 1828 1803 1842\n1871 1884 1842 1834 1873 1884 1950 1911 1992 1847 1847 1834 1849 1809 1822 1927 1925 1835 1857 1891 1848 1833 1843 1939 1858 1871 1975 1816 1874 1915 1835 1918 1906 1902 1849 1863 1909 1798 1842 1910 1791 1843 1781 1832 1898 1889 1884 1853 1883 1855 1975 1767 1826 1761 1879 1814 1738\n1886 1909 1873 1850 1908 1894 1907 1872 1837 1773 1847 1926 1884 1882 1831 1832 1942 1897 1844 1950 1886 1978 1947 1815 1843 1785 1886 1914 1911 1883 1824 1873 1934 1943 1831 1906 1813 1820 1831 1870 1824 1875 1866 1913 1800 1818 1930 1860 1808 1884 1834 1921 1717 1812 1816 1947 1829\n1860 1893 1883 1843 1923 1853 1834 1858 1922 1944 1942 1839 1813 1852 1889 1945 1902 1977 1929 1881 1850 1967 1844 1877 1970 1850 1941 1897 1814 1894 1841 1837 1821 1866 1777 1805 1851 1889 1838 1843 1853 1776 1907 1909 1846 1781 1775 1876 1941 1851 1849 1854 1813 1885 1912 1887 1776\n1819 1896 1911 1936 1887 1847 1874 1894 1855 1869 1843 1864 1921 1883 1875 1926 1866 1923 1886 1889 1844 1896 2002 1944 1909 1858 1927 1870 1882 1886 1899 1894 1809 1904 1786 1920 1908 1888 1901 1859 1857 1793 1880 1828 1809 1839 1905 1893 1849 1920 1837 1868 1910 1850 1873 1900 1721\n1861 1895 1819 1865 1741 1797 1832 1849 1901 1869 1870 1811 1786 1910 1936 1961 1907 1899 1949 1863 1845 1885 1881 1831 1884 1937 1860 1906 1873 1838 1859 1898 1924 1863 1902 1881 1851 1880 1945 1851 1929 1846 1843 1879 1774 1826 1788 1871 1918 1780 1825 1853 1782 1852 1861 1867 1844\n1822 1867 1806 1745 1942 1836 1841 1861 1787 1867 1947 1906 1826 1822 1935 1787 1879 1920 1830 1928 1879 1837 1921 1923 1855 1932 1844 1841 1917 1928 1865 1915 1873 1839 1846 1910 1896 1903 1911 1838 1857 1905 1870 1811 1899 1874 1860 1822 1935 1757 1862 1807 1856 1868 1786 1919 1887\n1850 1926 1855 1766 1858 1815 1894 1861 1911 1910 1846 1861 1857 1800 1837 1784 1912 1937 1916 1942 1929 1866 1905 1916 1923 1922 1899 1838 1910 1872 1778 1849 1863 1868 1870 1828 1880 1793 1889 1937 1857 1888 1882 1946 1841 1838 1800 1819 1874 1918 1879 1895 1874 1884 1861 1761 1800\n"
},
{
"answer_id": 74660120,
"author": "Pranav Hosangadi",
"author_id": 843953,
"author_profile": "https://Stackoverflow.com/users/843953",
"pm_score": -1,
"selected": false,
"text": "any(axis=1) axis=0 all data = np.array([[0, 0, 0, 0, 0, 0, 0],\n [0, 1, 3, 4, 6, 1, 0],\n [0, 2, 3, 5, 2, 1, 0],\n [0, 1, 0, 0, 1, 0, 0],\n [0, 0, 0, 0, 0, 0, 0]])\n delete_rows = (data == 0).all(axis=1)\ndelete_cols = (data == 0).all(axis=0)\n -999 data == 0 data[delete_rows, :] = -999\ndata[:, delete_cols] = -999\n delete_rows zero_rows = (data == 0).any(axis=1)\n\nd_r = np.zeros(zero_rows.shape, dtype=bool)\nd_r[1:] = d_r[1:] | delete_rows[:-1]\nd_r[:-1] = d_r[:-1] | delete_rows[1:]\n\ndelete_rows = delete_rows | (zero_rows & d_r)\ndata[delete_rows, :] = -999\n delete_rows del_count = sum(delete_rows)\nprev_del_count = del_count + 1\n\nwhile del_count != prev_del_count:\n zero_rows = (data == 0).any(axis=1)\n\n d_r = np.zeros(zero_rows.shape, dtype=bool)\n d_r[1:] = d_r[1:] | delete_rows[:-1]\n d_r[:-1] = d_r[:-1] | delete_rows[1:]\n\n delete_rows = delete_rows | (zero_rows & d_r)\n prev_del_count, del_count = del_count, sum(delete_rows)\n data[delete_rows, :] = -999\n del_count = sum(delete_cols)\nprev_del_count = del_count + 1\n\nwhile del_count != prev_del_count:\n zero_cols = (data == 0).any(axis=0)\n\n d_c = np.zeros(zero_cols.shape, dtype=bool)\n d_c[1:] = d_c[1:] | delete_cols[:-1]\n d_c[:-1] = d_c[:-1] | delete_cols[1:]\n\n delete_cols = delete_cols | (zero_cols & d_c)\n prev_del_count, del_count = del_count, sum(delete_cols)\n data[:, delete_cols] = -999\n delete_rows = np.array([ True, False, False, True, True])\ndelete_cols = np.array([ True, False, False, False, False, False, True])\n filtered_data = data[~delete_rows, :][:, ~delete_cols]\n array([[1, 3, 4, 6, 1],\n [2, 3, 5, 2, 1]])\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655756",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2047830/"
] |
74,655,757
|
<p>I have a nested tabs navigator inside a stack navigator.</p>
<ul>
<li>When I navigate from Tab Screen A to Stack Screen B, B's useEffect is called, all good.</li>
<li>When I navigate from Stack Screen C to also Stack Screen B, B's useEffect is NOT called. I dont understand why.
-I am able to navigate to Screen B from both Screens, thats not the problem. I also am able to pass params. The only thing is just the useEffect is not called when coming from C, coming from A works fine.</li>
</ul>
<p>I use in both cases same:</p>
<pre><code> <Button title="goTo" onPress={() => props.navigation.navigate('SearchResults', {id: id})}/>
</code></pre>
<p>I also tried to use useIsFocused and useFocusEffect, but its also not called when I navigate from stack screen C. What am I doing wrong?</p>
<p>EDIT:
It seems that the problem is with navigating to Screen C (from which I try to navigate to Screen B (that doesnt mount) is that I defined it in the header of Tab Navigator. If I wouldnt, I could navigate to C and C would mount. But I dont understand why that is or what to do.
So In my code : When I navigate from NotificationsScreen to SearchResultsScreen, SearchScreen wont mount (as it seems its because I access NotificationsScreen from header of tabs navigator)</p>
<pre><code>const MyTabs = (props) => {
return (
<Tab.Navigator
screenOptions={{
headerRight: (props) => (
<TouchableOpacity onPress={() => navigation.navigate("Notifications")}>
<Icon name="notifications"/>
</TouchableOpacity>
)
}}
>
<Tab.Screen
name="Home"
component={HomeScreen}
/>
<Tab.Screen
// when I navigate from SearchScreen to SearchResultsScreen, SearchResultsScreen useEffect is called
name="Search"
component={SearchScreen}
/>
</Tab.Navigator>
);
}
</code></pre>
<pre><code>const MyStack = () => {
return (
<Stack.Navigator>
<Stack.Screen name="Tabs">
{(props) => <MyTabs {...props} />}
</Stack.Screen>
<Stack.Screen
name="SearchResults"
component={SearchResultsScreen}
/>
<Stack.Screen
name="Notifications"
component={NotificationsScreen}
// when I navigate from NotificationsScreen to SearchResultsScreen, SearchResultsScreen useEffect is NOT called
/>
</Stack.Navigator>
</code></pre>
|
[
{
"answer_id": 74655917,
"author": "JSONCMD",
"author_id": 20629269,
"author_profile": "https://Stackoverflow.com/users/20629269",
"pm_score": 1,
"selected": false,
"text": "navigation.replace(\"SearchResults\", null, null)\n"
},
{
"answer_id": 74656018,
"author": "NAZIR HUSSAIN",
"author_id": 20587701,
"author_profile": "https://Stackoverflow.com/users/20587701",
"pm_score": 0,
"selected": false,
"text": "useEffect(()=>{\n//useEffect stuff on mount\n\nreturn () => {\n // on component unmount.\n }\n},[]) \n"
},
{
"answer_id": 74656165,
"author": "Engr.Aftab Ufaq",
"author_id": 9570734,
"author_profile": "https://Stackoverflow.com/users/9570734",
"pm_score": 1,
"selected": false,
"text": "**useFocusEffect** import { useFocusEffect } from '@react-navigation/native';\n\nfunction Profile({ userId }) {\n const [user, setUser] = React.useState(null);\n\n useFocusEffect(\n React.useCallback(() => {\n const unsubscribe = API.subscribe(userId, user => setUser(user));\n\n return () => unsubscribe();\n }, [userId])\n );\n\n return <ProfileContent user={user} />;\n}\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655757",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6377312/"
] |
74,655,783
|
<p>I don't know how to select, in proc sql, the min for positive values of diff (to have the 25/11/2022) and the max for negatives diff (to have the 11/11/2022).</p>
<p><a href="https://i.stack.imgur.com/5kyF1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5kyF1.png" alt="enter image description here" /></a></p>
<p>Do I need to use the case statement or having ?</p>
<p>Thank you for your help !</p>
|
[
{
"answer_id": 74655917,
"author": "JSONCMD",
"author_id": 20629269,
"author_profile": "https://Stackoverflow.com/users/20629269",
"pm_score": 1,
"selected": false,
"text": "navigation.replace(\"SearchResults\", null, null)\n"
},
{
"answer_id": 74656018,
"author": "NAZIR HUSSAIN",
"author_id": 20587701,
"author_profile": "https://Stackoverflow.com/users/20587701",
"pm_score": 0,
"selected": false,
"text": "useEffect(()=>{\n//useEffect stuff on mount\n\nreturn () => {\n // on component unmount.\n }\n},[]) \n"
},
{
"answer_id": 74656165,
"author": "Engr.Aftab Ufaq",
"author_id": 9570734,
"author_profile": "https://Stackoverflow.com/users/9570734",
"pm_score": 1,
"selected": false,
"text": "**useFocusEffect** import { useFocusEffect } from '@react-navigation/native';\n\nfunction Profile({ userId }) {\n const [user, setUser] = React.useState(null);\n\n useFocusEffect(\n React.useCallback(() => {\n const unsubscribe = API.subscribe(userId, user => setUser(user));\n\n return () => unsubscribe();\n }, [userId])\n );\n\n return <ProfileContent user={user} />;\n}\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655783",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14002405/"
] |
74,655,786
|
<p>For my database I need to create a new column based on a condition.
In a seperate file I have add all the conditions like this:</p>
<pre><code>conditions = [{year: 2016, price: 30000, fuel: Petrol, result: 12},
{year: 2017, price: 45000, fuel: Elektricity, result: 18},
{year: 2018, price: None, fuel: Petrol, result: 14},
</code></pre>
<p>I am using the following code to add a new column</p>
<pre><code>df['new_column'] = np.where((df['year'] == dict[year]) & (df['price'] > dict[price]) & (df['fuel description'] == dict[fuel])), dict[result], df['new_column'
</code></pre>
<p>As you see in the conditions, it is possible that one of the values is none.
This means (in this case price: none) that the formula as follows:</p>
<pre><code>df['new_column'] = np.where((df['year'] == dict[year]) & (df['fuel description'] == dict[fuel])), dict[result], df['new_column'
</code></pre>
<p>It is possible that multiple conditions are none, I want to prevent working with to much if and else statements but I can't figure out a way to do something in the formula that when it is none it needs to remove the condition.</p>
<p>Is this possible or should I just work with:</p>
<pre><code>If dict[price] != None:
df['new_column'] = np.where((df['year'] == dict[year]) & (df['price'] > dict[price]) & (df['fuel description'] == dict[fuel])), dict[result], df['new_column'
else:
df['new_column'] = np.where((df['year'] == dict[year]) & (df['fuel description'] == dict[fuel])), dict[result], df['new_column'
</code></pre>
|
[
{
"answer_id": 74655917,
"author": "JSONCMD",
"author_id": 20629269,
"author_profile": "https://Stackoverflow.com/users/20629269",
"pm_score": 1,
"selected": false,
"text": "navigation.replace(\"SearchResults\", null, null)\n"
},
{
"answer_id": 74656018,
"author": "NAZIR HUSSAIN",
"author_id": 20587701,
"author_profile": "https://Stackoverflow.com/users/20587701",
"pm_score": 0,
"selected": false,
"text": "useEffect(()=>{\n//useEffect stuff on mount\n\nreturn () => {\n // on component unmount.\n }\n},[]) \n"
},
{
"answer_id": 74656165,
"author": "Engr.Aftab Ufaq",
"author_id": 9570734,
"author_profile": "https://Stackoverflow.com/users/9570734",
"pm_score": 1,
"selected": false,
"text": "**useFocusEffect** import { useFocusEffect } from '@react-navigation/native';\n\nfunction Profile({ userId }) {\n const [user, setUser] = React.useState(null);\n\n useFocusEffect(\n React.useCallback(() => {\n const unsubscribe = API.subscribe(userId, user => setUser(user));\n\n return () => unsubscribe();\n }, [userId])\n );\n\n return <ProfileContent user={user} />;\n}\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655786",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13680411/"
] |
74,655,798
|
<p>I'm using Firebase Realtime database to add chat features to my app. In the database I have the following data:</p>
<pre><code>{
events: {
"event-uuid1": {
"chat-uuid1": {
"message": "hey"
},
"chat-uuid2": {
"message": "hey again"
}
}
}
}
</code></pre>
<p>In my Flutter app, I have this StreamBuilder (I know this is lengthy, I'm not sure where the problem is so providing more rather than less):</p>
<pre><code>class _EventChatScreenState extends ConsumerState<EventChatScreen> {
FirebaseDatabase dbInstance = FirebaseDatabase.instance;
late TextEditingController _messageFieldController;
late DatabaseReference eventDbRef;
@override
void initState() {
super.initState();
_messageFieldController = TextEditingController();
eventDbRef = dbInstance.ref("none");
}
@override
void dispose() {
_messageFieldController.dispose();
super.dispose();
}
Map<String, ChatMessage> chatMessages = {};
@override
Widget build(BuildContext context) {
final user = ref.watch(userProvider);
final event = ModalRoute.of(context)!.settings.arguments as EventRepository;
if (eventDbRef.path == "none") {
print("IT IS NONE");
eventDbRef = dbInstance.ref("/events/${event.event.eventId}/");
print(eventDbRef.path); // Print's correct value
}
return StreamBuilder(
stream: eventDbRef.onChildAdded,
builder: (context, snapshot) {
if (chatMessages == {}) {
return const Text("Loading...");
}
DatabaseEvent data;
if (snapshot.hasData) {
data = snapshot.data as DatabaseEvent;
ChatMessage newChatMessage = ChatMessage(
chatMessageId: "",
userId: "",
displayname: "",
message: "",
datetime: "",
);
for (var child in data.snapshot.children) {
switch (child.key) {
case "chatMessageId":
newChatMessage.chatMessageId = child.value.toString();
break;
case "userId":
newChatMessage.userId = child.value.toString();
break;
case "displayName":
newChatMessage.displayname = child.value.toString();
break;
case "message":
newChatMessage.message = child.value.toString();
break;
case "datetime":
final datetime = DateTime.parse(child.value.toString());
final DateFormat formatter = DateFormat('h:mm aa');
final String formatted = formatter.format(datetime);
newChatMessage.datetime = formatted;
break;
default:
}
}
if (chatMessages[data.snapshot.key] == null) {
chatMessages[data.snapshot.key!] = newChatMessage;
}
}
return ListView.builder(
itemCount: chatMessages.length,
itemBuilder: (context, index) {
String key = chatMessages.keys.elementAt(index);
if (chatMessages[key]!.userId == user.user.userId) {
return UnconstrainedBox(
alignment: Alignment.centerRight,
child: Container(
margin: const EdgeInsets.symmetric(vertical: 5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.only(left: 10),
child: Text(chatMessages[key]!.displayname),
),
Container(
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 15),
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(
Radius.circular(20),
),
color: Theme.of(context).colorScheme.primary,
),
child: Text(chatMessages[key]!.message,
style: TextStyle(
color: Theme.of(context).colorScheme.onPrimary,
),
),
),
Container(
padding: const EdgeInsets.only(left: 10),
child: Text(chatMessages[key]!.datetime),
),
],
),
),
);
}
},
);
},
),
</code></pre>
<p>The problem is that when the user goes to the chat screen <strong>one</strong> of the messages will already be present in the chat. I would expect there to be nothing since I am not setting any initial data anywhere, not using Realtime Database's persistence, and not using my own local database yet.</p>
<p>My understanding of StreamBuilders is that they only get new data as it comes in, not data that may already exist and is thus not sent through it (Ie. when a new chat message is sent the stream should receive it, which works, but it should not receive chat message messages already in the database). If that understanding is wrong then why am I only getting one message despite there being 2, 3, 4, etc. in the database?</p>
<p>Perhaps I'm understanding/using StreamBuilders, Firebase Realtime Database, or both incorrectly?</p>
|
[
{
"answer_id": 74656020,
"author": "GrahamD",
"author_id": 10376604,
"author_profile": "https://Stackoverflow.com/users/10376604",
"pm_score": 1,
"selected": true,
"text": "eventDbRef.onChildAdded"
},
{
"answer_id": 74656081,
"author": "Delwinn",
"author_id": 16714498,
"author_profile": "https://Stackoverflow.com/users/16714498",
"pm_score": 1,
"selected": false,
"text": "FutureBuilder StreamBuilder db database"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655798",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6327846/"
] |
74,655,807
|
<p>I need to sort array of objects by 2 conditions</p>
<ol>
<li>sort by value</li>
<li>if names are the same show them next to each other in value order</li>
</ol>
<p>Example example: <a href="https://codesandbox.io/s/relaxed-dhawan-sfryng?file=/src/index.js" rel="nofollow noreferrer">https://codesandbox.io/s/relaxed-dhawan-sfryng?file=/src/index.js</a></p>
|
[
{
"answer_id": 74655851,
"author": "AschenAI",
"author_id": 20665111,
"author_profile": "https://Stackoverflow.com/users/20665111",
"pm_score": 1,
"selected": false,
"text": "Array.prototype.sort() function sortByValueAndName(a, b) {\n // If the values are different, sort by value\n if (a.value !== b.value) {\n return a.value - b.value;\n }\n\n // If the values are the same, sort by name\n if (a.name !== b.name) {\n return a.name < b.name ? -1 : 1;\n }\n\n // If both the values and the names are the same, the objects are equal\n return 0;\n}\n\n// Example array of objects\nconst objects = [\n { name: \"John\", value: 10 },\n { name: \"Jane\", value: 10 },\n { name: \"Alice\", value: 5 },\n];\n\n// Sort the array using the custom sorting function\nobjects.sort(sortByValueAndName);\n\n// The sorted array will be:\n// [\n// { name: \"Alice\", value: 5 },\n// { name: \"John\", value: 10 },\n// { name: \"Jane\", value: 10 },\n// ]\n"
},
{
"answer_id": 74656409,
"author": "flyingfox",
"author_id": 3176419,
"author_profile": "https://Stackoverflow.com/users/3176419",
"pm_score": 0,
"selected": false,
"text": "const array = [\n {\n name: \"John\",\n value: 5\n },\n {\n name: \"David\",\n value: 6\n },\n {\n name: \"John\",\n value: 2\n },\n {\n name: \"Michael\",\n value: 4\n }\n];\n\nconst customSort = (data) => {\n \n // create a new array to make elements have same name together\n let newArray = data.reduce((a,v) => {\n let obj = a.find(e => e.name === v.name)\n if(obj){\n obj.datas.push(v) \n }else{\n a.push({'name':v.name,'datas':[v]})\n }\n return a\n },[])\n \n // sort data in the new array by value\n newArray.forEach(e => {\n e.datas.sort((a,b) => a.value - b.value) \n })\n\n // create a value object with boolean value to avoid add duplicate element\n let values = data.reduce((a,v) => {\n a[v.value] = false\n return a\n },{})\n let keys = Object.keys(values)\n\n let result = []\n for(k of keys){\n \n // if the value has iterated,then skip it\n if(values[k]){\n continue\n }\n // find data by value\n let arr = newArray.filter(e1 => e1.datas.some(e2 => e2.value == k)).flatMap(e => e.datas)\n result.push(...arr)\n \n // mark the value already added\n arr.forEach(e => {\n values[e.value] = true \n })\n }\n return result\n}\n\n\nconsole.log(customSort(array))"
},
{
"answer_id": 74657241,
"author": "Amirhossein",
"author_id": 11342834,
"author_profile": "https://Stackoverflow.com/users/11342834",
"pm_score": 0,
"selected": false,
"text": "const arr = [\n {\n name: \"John\",\n value: 5\n },\n {\n name: \"David\",\n value: 6\n },\n {\n name: \"John\",\n value: 2\n },\n {\n name: \"Michael\",\n value: 4\n }\n];\n\nconst groupByItems = [];\n\n// Get index of the item based on name in groupByItems array\nconst getIndex = (name) => {\n let index = -1;\n groupByItems.forEach((groupByItem, _index) => {\n if(groupByItem.name === name) {\n index = _index;\n }\n });\n return index;\n}\n\n// Group items by their name\nconst groupByName = () => {\n arr.forEach((item) => {\n const name = item.name;\n const value = item.value;\n let index = getIndex(name);\n //Means that the [name] has not added before, so we should add it\n if(index === -1) {\n groupByItems.push({\n name: name,\n // Hold all values of the [name]\n values: [],\n // Hold minValue to sort groupByItems by that\n minValue: Infinity\n });\n index = groupByItems.length - 1;\n }\n // Add current value to the list of values\n groupByItems[index].values.push(value);\n // Update minValue\n if(groupByItems[index].minValue > value) {\n groupByItems[index].minValue = value;\n }\n });\n}\n\ngroupByName();\n\n//Sort by minValue and then return final objects\nconst result = groupByItems.sort((a, b) => a.minValue - b.minValue).flatMap((item) => (\n item.values.sort((firstValue, secondValue) => firstValue - secondValue).map((value) => {\n return {\n name: item.name,\n value: value\n }\n })\n));\n\nconsole.log(result);"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655807",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17126247/"
] |
74,655,823
|
<p>I have an application written in the electron module. When I add a script from a JS file to an html file or enter a script between <script> tags and define a new module, I get an error: <strong>ReferenceError: require is not defined</strong></p>
<p>This is my HTML script:
<code><script src="../scripts/computer.js"></script></code></p>
<p>This is the javascript file:
<code>const os = require("os")</code></p>
<p>I wanted to fetch information from my computer and then display it in my application using the "os" module but it doesn't work</p>
|
[
{
"answer_id": 74655851,
"author": "AschenAI",
"author_id": 20665111,
"author_profile": "https://Stackoverflow.com/users/20665111",
"pm_score": 1,
"selected": false,
"text": "Array.prototype.sort() function sortByValueAndName(a, b) {\n // If the values are different, sort by value\n if (a.value !== b.value) {\n return a.value - b.value;\n }\n\n // If the values are the same, sort by name\n if (a.name !== b.name) {\n return a.name < b.name ? -1 : 1;\n }\n\n // If both the values and the names are the same, the objects are equal\n return 0;\n}\n\n// Example array of objects\nconst objects = [\n { name: \"John\", value: 10 },\n { name: \"Jane\", value: 10 },\n { name: \"Alice\", value: 5 },\n];\n\n// Sort the array using the custom sorting function\nobjects.sort(sortByValueAndName);\n\n// The sorted array will be:\n// [\n// { name: \"Alice\", value: 5 },\n// { name: \"John\", value: 10 },\n// { name: \"Jane\", value: 10 },\n// ]\n"
},
{
"answer_id": 74656409,
"author": "flyingfox",
"author_id": 3176419,
"author_profile": "https://Stackoverflow.com/users/3176419",
"pm_score": 0,
"selected": false,
"text": "const array = [\n {\n name: \"John\",\n value: 5\n },\n {\n name: \"David\",\n value: 6\n },\n {\n name: \"John\",\n value: 2\n },\n {\n name: \"Michael\",\n value: 4\n }\n];\n\nconst customSort = (data) => {\n \n // create a new array to make elements have same name together\n let newArray = data.reduce((a,v) => {\n let obj = a.find(e => e.name === v.name)\n if(obj){\n obj.datas.push(v) \n }else{\n a.push({'name':v.name,'datas':[v]})\n }\n return a\n },[])\n \n // sort data in the new array by value\n newArray.forEach(e => {\n e.datas.sort((a,b) => a.value - b.value) \n })\n\n // create a value object with boolean value to avoid add duplicate element\n let values = data.reduce((a,v) => {\n a[v.value] = false\n return a\n },{})\n let keys = Object.keys(values)\n\n let result = []\n for(k of keys){\n \n // if the value has iterated,then skip it\n if(values[k]){\n continue\n }\n // find data by value\n let arr = newArray.filter(e1 => e1.datas.some(e2 => e2.value == k)).flatMap(e => e.datas)\n result.push(...arr)\n \n // mark the value already added\n arr.forEach(e => {\n values[e.value] = true \n })\n }\n return result\n}\n\n\nconsole.log(customSort(array))"
},
{
"answer_id": 74657241,
"author": "Amirhossein",
"author_id": 11342834,
"author_profile": "https://Stackoverflow.com/users/11342834",
"pm_score": 0,
"selected": false,
"text": "const arr = [\n {\n name: \"John\",\n value: 5\n },\n {\n name: \"David\",\n value: 6\n },\n {\n name: \"John\",\n value: 2\n },\n {\n name: \"Michael\",\n value: 4\n }\n];\n\nconst groupByItems = [];\n\n// Get index of the item based on name in groupByItems array\nconst getIndex = (name) => {\n let index = -1;\n groupByItems.forEach((groupByItem, _index) => {\n if(groupByItem.name === name) {\n index = _index;\n }\n });\n return index;\n}\n\n// Group items by their name\nconst groupByName = () => {\n arr.forEach((item) => {\n const name = item.name;\n const value = item.value;\n let index = getIndex(name);\n //Means that the [name] has not added before, so we should add it\n if(index === -1) {\n groupByItems.push({\n name: name,\n // Hold all values of the [name]\n values: [],\n // Hold minValue to sort groupByItems by that\n minValue: Infinity\n });\n index = groupByItems.length - 1;\n }\n // Add current value to the list of values\n groupByItems[index].values.push(value);\n // Update minValue\n if(groupByItems[index].minValue > value) {\n groupByItems[index].minValue = value;\n }\n });\n}\n\ngroupByName();\n\n//Sort by minValue and then return final objects\nconst result = groupByItems.sort((a, b) => a.minValue - b.minValue).flatMap((item) => (\n item.values.sort((firstValue, secondValue) => firstValue - secondValue).map((value) => {\n return {\n name: item.name,\n value: value\n }\n })\n));\n\nconsole.log(result);"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655823",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20557852/"
] |
74,655,835
|
<p>I implemented a progress bar but I'm having problems.</p>
<p>The progress bar to complete should take 5 seconds. My problem is that the value is updated from second to second and I would like it to be continuous, without any kind of stops.</p>
<p><a href="https://stackblitz.com/edit/angular-devextreme-sandbox-t66yne?file=src%2Fapp%2Fapp.component.css,src%2Fapp%2Fapp.component.html,src%2Fapp%2Fapp.component.ts,src%2Findex.html" rel="nofollow noreferrer"><strong>DEMO</strong></a></p>
<p><strong>HTML</strong></p>
<pre><code><dx-progress-bar
#progressBar
[showStatus]="false"
id="progress-bar-status"
[rtlEnabled]="true"
[class.complete]="progressBar.value == maxValue"
[min]="0"
[max]="maxValue"
[value]="maxValue - seconds"
>
</dx-progress-bar>
</code></pre>
<p><strong>.Ts</strong></p>
<pre><code> seconds = 5;
maxValue = 5;
intervalId: number;
onButtonClick() {
this.seconds = 5;
this.intervalId = window.setInterval(() => this.timer(), 1000);
}
timer() {
this.seconds--;
if (this.seconds == 0) {
clearInterval(this.intervalId);
}
}
</code></pre>
<p><strong>intended result</strong></p>
<p><a href="https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_progressbar_3" rel="nofollow noreferrer">Example</a></p>
|
[
{
"answer_id": 74655851,
"author": "AschenAI",
"author_id": 20665111,
"author_profile": "https://Stackoverflow.com/users/20665111",
"pm_score": 1,
"selected": false,
"text": "Array.prototype.sort() function sortByValueAndName(a, b) {\n // If the values are different, sort by value\n if (a.value !== b.value) {\n return a.value - b.value;\n }\n\n // If the values are the same, sort by name\n if (a.name !== b.name) {\n return a.name < b.name ? -1 : 1;\n }\n\n // If both the values and the names are the same, the objects are equal\n return 0;\n}\n\n// Example array of objects\nconst objects = [\n { name: \"John\", value: 10 },\n { name: \"Jane\", value: 10 },\n { name: \"Alice\", value: 5 },\n];\n\n// Sort the array using the custom sorting function\nobjects.sort(sortByValueAndName);\n\n// The sorted array will be:\n// [\n// { name: \"Alice\", value: 5 },\n// { name: \"John\", value: 10 },\n// { name: \"Jane\", value: 10 },\n// ]\n"
},
{
"answer_id": 74656409,
"author": "flyingfox",
"author_id": 3176419,
"author_profile": "https://Stackoverflow.com/users/3176419",
"pm_score": 0,
"selected": false,
"text": "const array = [\n {\n name: \"John\",\n value: 5\n },\n {\n name: \"David\",\n value: 6\n },\n {\n name: \"John\",\n value: 2\n },\n {\n name: \"Michael\",\n value: 4\n }\n];\n\nconst customSort = (data) => {\n \n // create a new array to make elements have same name together\n let newArray = data.reduce((a,v) => {\n let obj = a.find(e => e.name === v.name)\n if(obj){\n obj.datas.push(v) \n }else{\n a.push({'name':v.name,'datas':[v]})\n }\n return a\n },[])\n \n // sort data in the new array by value\n newArray.forEach(e => {\n e.datas.sort((a,b) => a.value - b.value) \n })\n\n // create a value object with boolean value to avoid add duplicate element\n let values = data.reduce((a,v) => {\n a[v.value] = false\n return a\n },{})\n let keys = Object.keys(values)\n\n let result = []\n for(k of keys){\n \n // if the value has iterated,then skip it\n if(values[k]){\n continue\n }\n // find data by value\n let arr = newArray.filter(e1 => e1.datas.some(e2 => e2.value == k)).flatMap(e => e.datas)\n result.push(...arr)\n \n // mark the value already added\n arr.forEach(e => {\n values[e.value] = true \n })\n }\n return result\n}\n\n\nconsole.log(customSort(array))"
},
{
"answer_id": 74657241,
"author": "Amirhossein",
"author_id": 11342834,
"author_profile": "https://Stackoverflow.com/users/11342834",
"pm_score": 0,
"selected": false,
"text": "const arr = [\n {\n name: \"John\",\n value: 5\n },\n {\n name: \"David\",\n value: 6\n },\n {\n name: \"John\",\n value: 2\n },\n {\n name: \"Michael\",\n value: 4\n }\n];\n\nconst groupByItems = [];\n\n// Get index of the item based on name in groupByItems array\nconst getIndex = (name) => {\n let index = -1;\n groupByItems.forEach((groupByItem, _index) => {\n if(groupByItem.name === name) {\n index = _index;\n }\n });\n return index;\n}\n\n// Group items by their name\nconst groupByName = () => {\n arr.forEach((item) => {\n const name = item.name;\n const value = item.value;\n let index = getIndex(name);\n //Means that the [name] has not added before, so we should add it\n if(index === -1) {\n groupByItems.push({\n name: name,\n // Hold all values of the [name]\n values: [],\n // Hold minValue to sort groupByItems by that\n minValue: Infinity\n });\n index = groupByItems.length - 1;\n }\n // Add current value to the list of values\n groupByItems[index].values.push(value);\n // Update minValue\n if(groupByItems[index].minValue > value) {\n groupByItems[index].minValue = value;\n }\n });\n}\n\ngroupByName();\n\n//Sort by minValue and then return final objects\nconst result = groupByItems.sort((a, b) => a.minValue - b.minValue).flatMap((item) => (\n item.values.sort((firstValue, secondValue) => firstValue - secondValue).map((value) => {\n return {\n name: item.name,\n value: value\n }\n })\n));\n\nconsole.log(result);"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655835",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12460041/"
] |
74,655,844
|
<p>I have the following problem: I've have created a repository and made changes to it, and commited them in git. Now, I've realized that the name of the repository is wrong, and I have created another with the right name, and I wonder if there is a way to import all the code (together with the changes I've made) in the first repository into the second repository using git and not copy pasting it manually. In the first repository there is a branch with all of my changes.</p>
<p>Mind that I cannot directly change the name of the first repository, as it doesn't belong to me and I am unable to do so.</p>
<p>Any ideas?</p>
<p>My original idea is to copy-paste all of the classes and code, manually, from one repository to the other, but that is absolutely time-consuming as the first repository has to many classes and a lot of code, and some copy-pasting errors might take place. I just want a safe and fast way to do this.</p>
|
[
{
"answer_id": 74655851,
"author": "AschenAI",
"author_id": 20665111,
"author_profile": "https://Stackoverflow.com/users/20665111",
"pm_score": 1,
"selected": false,
"text": "Array.prototype.sort() function sortByValueAndName(a, b) {\n // If the values are different, sort by value\n if (a.value !== b.value) {\n return a.value - b.value;\n }\n\n // If the values are the same, sort by name\n if (a.name !== b.name) {\n return a.name < b.name ? -1 : 1;\n }\n\n // If both the values and the names are the same, the objects are equal\n return 0;\n}\n\n// Example array of objects\nconst objects = [\n { name: \"John\", value: 10 },\n { name: \"Jane\", value: 10 },\n { name: \"Alice\", value: 5 },\n];\n\n// Sort the array using the custom sorting function\nobjects.sort(sortByValueAndName);\n\n// The sorted array will be:\n// [\n// { name: \"Alice\", value: 5 },\n// { name: \"John\", value: 10 },\n// { name: \"Jane\", value: 10 },\n// ]\n"
},
{
"answer_id": 74656409,
"author": "flyingfox",
"author_id": 3176419,
"author_profile": "https://Stackoverflow.com/users/3176419",
"pm_score": 0,
"selected": false,
"text": "const array = [\n {\n name: \"John\",\n value: 5\n },\n {\n name: \"David\",\n value: 6\n },\n {\n name: \"John\",\n value: 2\n },\n {\n name: \"Michael\",\n value: 4\n }\n];\n\nconst customSort = (data) => {\n \n // create a new array to make elements have same name together\n let newArray = data.reduce((a,v) => {\n let obj = a.find(e => e.name === v.name)\n if(obj){\n obj.datas.push(v) \n }else{\n a.push({'name':v.name,'datas':[v]})\n }\n return a\n },[])\n \n // sort data in the new array by value\n newArray.forEach(e => {\n e.datas.sort((a,b) => a.value - b.value) \n })\n\n // create a value object with boolean value to avoid add duplicate element\n let values = data.reduce((a,v) => {\n a[v.value] = false\n return a\n },{})\n let keys = Object.keys(values)\n\n let result = []\n for(k of keys){\n \n // if the value has iterated,then skip it\n if(values[k]){\n continue\n }\n // find data by value\n let arr = newArray.filter(e1 => e1.datas.some(e2 => e2.value == k)).flatMap(e => e.datas)\n result.push(...arr)\n \n // mark the value already added\n arr.forEach(e => {\n values[e.value] = true \n })\n }\n return result\n}\n\n\nconsole.log(customSort(array))"
},
{
"answer_id": 74657241,
"author": "Amirhossein",
"author_id": 11342834,
"author_profile": "https://Stackoverflow.com/users/11342834",
"pm_score": 0,
"selected": false,
"text": "const arr = [\n {\n name: \"John\",\n value: 5\n },\n {\n name: \"David\",\n value: 6\n },\n {\n name: \"John\",\n value: 2\n },\n {\n name: \"Michael\",\n value: 4\n }\n];\n\nconst groupByItems = [];\n\n// Get index of the item based on name in groupByItems array\nconst getIndex = (name) => {\n let index = -1;\n groupByItems.forEach((groupByItem, _index) => {\n if(groupByItem.name === name) {\n index = _index;\n }\n });\n return index;\n}\n\n// Group items by their name\nconst groupByName = () => {\n arr.forEach((item) => {\n const name = item.name;\n const value = item.value;\n let index = getIndex(name);\n //Means that the [name] has not added before, so we should add it\n if(index === -1) {\n groupByItems.push({\n name: name,\n // Hold all values of the [name]\n values: [],\n // Hold minValue to sort groupByItems by that\n minValue: Infinity\n });\n index = groupByItems.length - 1;\n }\n // Add current value to the list of values\n groupByItems[index].values.push(value);\n // Update minValue\n if(groupByItems[index].minValue > value) {\n groupByItems[index].minValue = value;\n }\n });\n}\n\ngroupByName();\n\n//Sort by minValue and then return final objects\nconst result = groupByItems.sort((a, b) => a.minValue - b.minValue).flatMap((item) => (\n item.values.sort((firstValue, secondValue) => firstValue - secondValue).map((value) => {\n return {\n name: item.name,\n value: value\n }\n })\n));\n\nconsole.log(result);"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655844",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20666361/"
] |
74,655,864
|
<p>I have the following pipeline and html template, but the app always displays <code>#noMatch</code> and doesn't logs <code>"in the pipe"</code> in the <code>reduce</code> function. I feel it's a matter of timing but I'm not able to fix it.</p>
<p><strong>ts</strong></p>
<pre><code>user$: Observable<User> = new Observable<User>();
matches$: Observable<User[]> = this.user$.pipe(
switchMap((user: User) => {
this.type= user.type;
return of([user, user, user]);
}),
distinctUntilChanged(),
);
filteredMatches$: Observable<{ type1: User[]; type2: User[] }>;
ngOnInit(): void {
this.user$ = this.authService.user$;
this.filteredMatches$ = this.matches$.pipe(
reduce((acc: any, curr: User[]) => {
if (!acc.type1) acc.type1= [];
if (!acc.type2) acc.type2= [];
console.log('in the pipe');
this.networkingService.decideType(this.type, curr.type)
? acc.type1.push(curr)
: acc.type2.push(curr);
return acc;
}),
);
}
</code></pre>
<p><strong>html</strong></p>
<pre><code><ng-template *ngIf="(filteredMatches$ | async) as matches; else noMatch">
<app-child *ngFor="let user of matches.type1" [user]="user">
<app-child *ngFor="let user of matches.type2" [user]="user">
</ng-template>
<ng-template #noMatch>
<app-no-match></app-no-match>
</ng-template>
</code></pre>
|
[
{
"answer_id": 74656129,
"author": "Salketer",
"author_id": 1620194,
"author_profile": "https://Stackoverflow.com/users/1620194",
"pm_score": 3,
"selected": true,
"text": "user$: Observable<User> = new Observable<User>();\nmatches$: Observable<User[]> = this.user$.pipe(\n switchMap((user: User) => {\n this.type= user.type;\n return of([user, user, user]);\n }),\n distinctUntilChanged(),\n);\n mathes$ user$ this.user$ = this.authService.user$;\n user$: Observable<User> = new Observable<User>();\n //by\n user$: Observable<User> = this.authService.user$;\n matches$: Observable<User[]> = this.authService.user$.pipe(\n switchMap((user: User) => {\n this.type= user.type;\n return of([user, user, user]);\n }),\n distinctUntilChanged(),\n);\nfilteredMatches$: Observable<{ type1: User[]; type2: User[] }> = this.matches$.pipe(\n reduce((acc: any, curr: User[]) => {\n if (!acc.type1) acc.type1= [];\n if (!acc.type2) acc.type2= [];\n console.log('in the pipe');\n\n this.networkingService.decideType(this.type, curr.type)\n ? acc.type1.push(curr)\n : acc.type2.push(curr);\n return acc;\n }),\n );\n"
},
{
"answer_id": 74656252,
"author": "mbojko",
"author_id": 7194268,
"author_profile": "https://Stackoverflow.com/users/7194268",
"pm_score": 2,
"selected": false,
"text": "user$: Observable<User> = new Subject<User>(); \nmatches$: Observable<User[]> // no changes here\n\nngOnInit(): void {\n this.authService.user$.subscribe(this.users$);\n Subject"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655864",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16807584/"
] |
74,655,872
|
<p>I am loading fonts from my local for website. @font-face doesnt work properly. Some font weights doesnt work. Only work bold ones. When I changed font weight for light,lighter,400-500 etc it doesnt work. I'm stuck completely. Anybody help?</p>
<p>My Network:
<a href="https://i.stack.imgur.com/wCM4Q.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wCM4Q.jpg" alt="network" /></a>
My Computed:
<a href="https://i.stack.imgur.com/jhPgs.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jhPgs.jpg" alt="computed" /></a>
My Files:
<a href="https://i.stack.imgur.com/ZR0Vj.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZR0Vj.jpg" alt="files" /></a></p>
<pre><code> @font-face {
font-family: "Gotham Narrow";
src: local("../font/gothamnarrow-thin-webfont.woff2") format("woff2");
font-weight: 100;
font-style: normal;
}
@font-face {
font-family: "Gotham Narrow";
src: local("../font/gothamnarrow-light-webfont.woff2") format("woff2");
font-weight: 300;
font-style: normal;
}
@font-face {
font-family: "Gotham Narrow";
src: local("../font/gothamnarrow-book-webfont.woff2") format("woff2");
font-weight: 400;
font-style: normal;
}
@font-face {
font-family: "Gotham Narrow";
src: local("../font/gothamnarrow-medium-webfont.woff2") format("woff2");
font-weight: 500;
font-style: normal;
}
@font-face {
font-family: "Gotham Narrow";
src: local("../font/gothamnarrow-bold-webfont.woff2") format("woff2");
font-weight: 700;
font-style: normal;
}
@font-face {
font-family: "Gotham Narrow";
src: local("../font/gothamnarrow-ultra-webfont.woff2") format("woff2");
font-weight: 800;
font-style: normal;
}
@font-face {
font-family: "Gotham Narrow";
src: local("../font/gothamnarrow-black-webfont.woff2") format("woff2");
font-weight: 900;
font-style: normal;
}
</code></pre>
|
[
{
"answer_id": 74657415,
"author": "pier farrugia",
"author_id": 19996700,
"author_profile": "https://Stackoverflow.com/users/19996700",
"pm_score": 0,
"selected": false,
"text": "@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"assets-new/font/GothamNarrow-Book.eot\") ;\n src: url(\"assets-new/font/GothamNarrow-Book.eot?#iefix\")\n format(\"embedded-opentype\"),\n url(\"assets-new/font/GothamNarrow-Book.woff2\") format(\"woff2\"),\n url(\"assets-new/font/GothamNarrow-Book.woff\") format(\"woff\"),\n url(\"assets-new/font/GothamNarrow-Book.ttf\") format(\"truetype\"),\n url(\"assets-new/font/GothamNarrow-Book.svg#GothamNarrow-Book\") format(\"svg\");\n\n font-style: 400;\n font-display: swap;\n}\n\n@font-face {\n font-family: \"Gotham Narrow Medium\";\n src: url(\"assets-new/font/GothamNarrow-Medium.eot\")\n ;\n src: url(\"assets-new/font/GothamNarrow-Medium.eot?#iefix\")\n format(\"embedded-opentype\"),\n url(\"assets-new/font/GothamNarrow-Medium.woff2\") format(\"woff2\"),\n url(\"assets-new/font/GothamNarrow-Medium.woff\") format(\"woff\"),\n url(\"assets-new/font/GothamNarrow-Medium.ttf\") format(\"truetype\"),\n url(\"assets-new/font/GothamNarrow-Medium.svg#GothamNarrow-Medium\")\n format(\"svg\");\n\n font-style: 500;\n font-display: swap;\n}\n\ndiv1 {\n font-family: \"Gotham Narrow\";\n}\ndiv2 {\n font-family: \"Gotham Narrow Medium\";\n}\n :root {\n --font-primary: \"Gotham Narrow\", sans-serif;\n --font-primary-medium: \"Gotham Narrow Medium\", sans-serif;\n\n}\ndiv1 {\n font-family: var(--font-primary);\n}\ndiv2 {\n font-family: var(--font-primary-medium);\n}\n"
},
{
"answer_id": 74668383,
"author": "herrstrietzel",
"author_id": 15015675,
"author_profile": "https://Stackoverflow.com/users/15015675",
"pm_score": 1,
"selected": false,
"text": "@font-face @font-face font-family: \"Gotham Narrow \"; /* trailing space - won'work */\n src @font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"https://fonts.gstatic.com/s/roboto/v30/KFOkCnqEu92Fr1MmgVxIIzI.woff2\") format(\"woff2\");\n font-style: normal;\n font-weight: 100;\n font-display: swap;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"https://fonts.gstatic.com/s/roboto/v30/KFOmCnqEu92Fr1Mu4mxK.woff2\") format(\"woff2\");\n font-style: normal;\n font-weight: 400;\n font-display: swap;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"https://fonts.gstatic.com/s/roboto/v30/KFOlCnqEu92Fr1MmWUlfBBc4.woff2\") format(\"woff2\");\n font-style: normal;\n font-weight: 700;\n font-display: swap;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"https://fonts.gstatic.com/s/roboto/v30/KFOlCnqEu92Fr1MmYUtfBBc4.woff2\") format(\"woff2\");\n font-style: normal;\n font-weight: 900;\n font-display: swap;\n}\n/** wrong url/path */\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"https://fonts.gstatic.com/s/roboto/v30/KFOmCnqEu92Fr1Mu4mxK-wrong.woff2\") format(\"woff2\");\n font-style: normal;\n font-weight: 1000;\n font-display: swap;\n}\n\n/* default for body */\nbody{\n font-family: \"Gotham Narrow\";\n font-weight: 400;\n font-size:2em;\n}\n\nh1{\n font-weight: 900\n}\nh1,h2{\n font-size:1.5em\n}\n\nh2,\nstrong{\n font-weight: 700\n}\n\n\n.light{\n font-weight: 100;\n}\n\n.regular{\n font-weight: 400;\n}\n\n.bold{\n font-weight: 900;\n}\n\n.heavy{\n font-weight: 900;\n}\n\n/** doesn't exist **/\n.ultra{\n font-weight: 1000;\n} <h1>Font weight 900</h1>\n<h2>Font weight 700</h2>\n<p>Font weight 400 <strong>Font weight 700</strong> <span class=\"light\">Font weight 100</span> <span class=\"ultra\">Font weight 1000 - doesn't exist</span></p> font-weight:400 <strong> font-weight:700 font-weight:900 body{\n font-family: \"Gotham Narrow\";\n font-weight: 400;\n}\n\nh2,\nstrong{\n font-weight: 700\n}\n"
},
{
"answer_id": 74672189,
"author": "usul93",
"author_id": 17768986,
"author_profile": "https://Stackoverflow.com/users/17768986",
"pm_score": 0,
"selected": false,
"text": "@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Thin.woff2\") format(\"woff2\");\n font-weight: 100;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Light.woff2\") format(\"woff2\");\n font-weight: 300;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Book.woff2\") format(\"woff2\");\n font-weight: 400;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Medium.woff2\") format(\"woff2\");\n font-weight: 500;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Bold.woff2\") format(\"woff2\");\n font-weight: 700;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Black.woff2\") format(\"woff2\");\n font-weight: 800;\n font-style: normal;\n}\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Ultra.woff2\") format(\"woff2\");\n font-weight: 900;\n font-style: normal;\n}\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655872",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17768986/"
] |
74,655,880
|
<p>I want to convert only numbers in this str</p>
<pre><code>"ABC234TSY65234525erQ"
</code></pre>
<p>I tried to change only areas with numbers to the * sign</p>
<p>This is what I wanted</p>
<pre><code>"ABC*TSY*erQ"
</code></pre>
<p>But when I actually did it, it came out like this</p>
<pre><code>"ABC***TSY********erQ"
</code></pre>
<p>How do I change it?</p>
<p>Thanks you!</p>
|
[
{
"answer_id": 74657415,
"author": "pier farrugia",
"author_id": 19996700,
"author_profile": "https://Stackoverflow.com/users/19996700",
"pm_score": 0,
"selected": false,
"text": "@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"assets-new/font/GothamNarrow-Book.eot\") ;\n src: url(\"assets-new/font/GothamNarrow-Book.eot?#iefix\")\n format(\"embedded-opentype\"),\n url(\"assets-new/font/GothamNarrow-Book.woff2\") format(\"woff2\"),\n url(\"assets-new/font/GothamNarrow-Book.woff\") format(\"woff\"),\n url(\"assets-new/font/GothamNarrow-Book.ttf\") format(\"truetype\"),\n url(\"assets-new/font/GothamNarrow-Book.svg#GothamNarrow-Book\") format(\"svg\");\n\n font-style: 400;\n font-display: swap;\n}\n\n@font-face {\n font-family: \"Gotham Narrow Medium\";\n src: url(\"assets-new/font/GothamNarrow-Medium.eot\")\n ;\n src: url(\"assets-new/font/GothamNarrow-Medium.eot?#iefix\")\n format(\"embedded-opentype\"),\n url(\"assets-new/font/GothamNarrow-Medium.woff2\") format(\"woff2\"),\n url(\"assets-new/font/GothamNarrow-Medium.woff\") format(\"woff\"),\n url(\"assets-new/font/GothamNarrow-Medium.ttf\") format(\"truetype\"),\n url(\"assets-new/font/GothamNarrow-Medium.svg#GothamNarrow-Medium\")\n format(\"svg\");\n\n font-style: 500;\n font-display: swap;\n}\n\ndiv1 {\n font-family: \"Gotham Narrow\";\n}\ndiv2 {\n font-family: \"Gotham Narrow Medium\";\n}\n :root {\n --font-primary: \"Gotham Narrow\", sans-serif;\n --font-primary-medium: \"Gotham Narrow Medium\", sans-serif;\n\n}\ndiv1 {\n font-family: var(--font-primary);\n}\ndiv2 {\n font-family: var(--font-primary-medium);\n}\n"
},
{
"answer_id": 74668383,
"author": "herrstrietzel",
"author_id": 15015675,
"author_profile": "https://Stackoverflow.com/users/15015675",
"pm_score": 1,
"selected": false,
"text": "@font-face @font-face font-family: \"Gotham Narrow \"; /* trailing space - won'work */\n src @font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"https://fonts.gstatic.com/s/roboto/v30/KFOkCnqEu92Fr1MmgVxIIzI.woff2\") format(\"woff2\");\n font-style: normal;\n font-weight: 100;\n font-display: swap;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"https://fonts.gstatic.com/s/roboto/v30/KFOmCnqEu92Fr1Mu4mxK.woff2\") format(\"woff2\");\n font-style: normal;\n font-weight: 400;\n font-display: swap;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"https://fonts.gstatic.com/s/roboto/v30/KFOlCnqEu92Fr1MmWUlfBBc4.woff2\") format(\"woff2\");\n font-style: normal;\n font-weight: 700;\n font-display: swap;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"https://fonts.gstatic.com/s/roboto/v30/KFOlCnqEu92Fr1MmYUtfBBc4.woff2\") format(\"woff2\");\n font-style: normal;\n font-weight: 900;\n font-display: swap;\n}\n/** wrong url/path */\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"https://fonts.gstatic.com/s/roboto/v30/KFOmCnqEu92Fr1Mu4mxK-wrong.woff2\") format(\"woff2\");\n font-style: normal;\n font-weight: 1000;\n font-display: swap;\n}\n\n/* default for body */\nbody{\n font-family: \"Gotham Narrow\";\n font-weight: 400;\n font-size:2em;\n}\n\nh1{\n font-weight: 900\n}\nh1,h2{\n font-size:1.5em\n}\n\nh2,\nstrong{\n font-weight: 700\n}\n\n\n.light{\n font-weight: 100;\n}\n\n.regular{\n font-weight: 400;\n}\n\n.bold{\n font-weight: 900;\n}\n\n.heavy{\n font-weight: 900;\n}\n\n/** doesn't exist **/\n.ultra{\n font-weight: 1000;\n} <h1>Font weight 900</h1>\n<h2>Font weight 700</h2>\n<p>Font weight 400 <strong>Font weight 700</strong> <span class=\"light\">Font weight 100</span> <span class=\"ultra\">Font weight 1000 - doesn't exist</span></p> font-weight:400 <strong> font-weight:700 font-weight:900 body{\n font-family: \"Gotham Narrow\";\n font-weight: 400;\n}\n\nh2,\nstrong{\n font-weight: 700\n}\n"
},
{
"answer_id": 74672189,
"author": "usul93",
"author_id": 17768986,
"author_profile": "https://Stackoverflow.com/users/17768986",
"pm_score": 0,
"selected": false,
"text": "@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Thin.woff2\") format(\"woff2\");\n font-weight: 100;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Light.woff2\") format(\"woff2\");\n font-weight: 300;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Book.woff2\") format(\"woff2\");\n font-weight: 400;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Medium.woff2\") format(\"woff2\");\n font-weight: 500;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Bold.woff2\") format(\"woff2\");\n font-weight: 700;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Black.woff2\") format(\"woff2\");\n font-weight: 800;\n font-style: normal;\n}\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Ultra.woff2\") format(\"woff2\");\n font-weight: 900;\n font-style: normal;\n}\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655880",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10304086/"
] |
74,655,906
|
<p>I have a Vue project and need to search an array with nested objects for a specific object and then return it. The user has a text input field for searching and the search should target "title".</p>
<p>The data looks like this:</p>
<pre><code>const data =
[{
"catId": "1",
"catTitle": "a",
"exampleArray": [{
"id": "111",
"title": "aaa"
}, {
"id": "222",
"title": "bbb"
}, {
"id": "333",
"title": "ccc"
}]
}, {
"catId": "2",
"catTitle": "b",
"exampleArray": [{
"id": "444",
"title": "ddd"
}, {
"id": "555",
"title": "eee"
}]
}, {
"catId": "3",
"catTitle": "c",
"exampleArray": []
}, {
"catId": "4",
"catTitle": "d",
"exampleArray": [{
"id": "555",
"title": "fff"
}]
}]
</code></pre>
<p>I have tried:</p>
<pre><code>
return data.filter(item => {
return item.catArray.filter(category=> {
return category.title.toLowerCase().includes(this.search.toLowerCase())
})
})
</code></pre>
<p>e.g. if user input is "aaa", should return:</p>
<pre><code>
[{
"catId": "1",
"catTitle": "a",
"exampleArray": [{
"id": "111",
"title": "aaa"
}]
}]
</code></pre>
<p>The search should also return all matching results.</p>
|
[
{
"answer_id": 74655945,
"author": "AschenAI",
"author_id": 20665111,
"author_profile": "https://Stackoverflow.com/users/20665111",
"pm_score": 0,
"selected": false,
"text": "Array.prototype.find() const data = [\n {\n catId: \"1\",\n catTitle: \"a\",\n exampleArray: [\n {\n id: \"111\",\n title: \"aaa\",\n },\n {\n id: \"222\",\n title: \"bbb\",\n },\n {\n id: \"333\",\n title: \"ccc\",\n },\n ],\n },\n // ...\n];\n\n// The search term that the user entered\nconst searchTerm = \"aaa\";\n\n// Use the find() method to search the data array for the object that has\n// a title property that includes the search term\nconst result = data.find((item) => {\n return item.exampleArray.some((item) => {\n return item.title.toLowerCase().includes(searchTerm.toLowerCase());\n });\n});\nconsole.log(result);\n// The result will be:\n// {\n// \"catId\": \"1\",\n// \"catTitle\": \"a\",\n// \"exampleArray\": [{\n// \"id\": \"111\",\n// \"title\": \"aaa\"\n// }]\n// }"
},
{
"answer_id": 74655951,
"author": "oliverbj",
"author_id": 989185,
"author_profile": "https://Stackoverflow.com/users/989185",
"pm_score": 0,
"selected": false,
"text": "return data.Filter(item => {\n // filter the `exampleArray` for each `item` by checking if the `title` property of each object in the array contains the search string\n const matchingItems = item.exampleArray.filter(example => example.title.toLowerCase().includes(this.search.toLowerCase()));\n // return `true` for the current `item` if there are any matching items in the `exampleArray`\n return matchingItems.length > 0;\n});\n exampleArray exampleArray [\n {\n \"catId\":\"1\",\n \"catTitle\":\"a\",\n \"exampleArray\":[\n {\n \"id\":\"111\",\n \"title\":\"aaa\"\n }\n ]\n }\n]\n"
},
{
"answer_id": 74655968,
"author": "Salketer",
"author_id": 1620194,
"author_profile": "https://Stackoverflow.com/users/1620194",
"pm_score": 1,
"selected": false,
"text": "const data = \n[{\n \"catId\": \"1\",\n \"catTitle\": \"a\",\n \"exampleArray\": [{\n \"id\": \"111\",\n \"title\": \"aaa\"\n }, {\n \"id\": \"222\",\n \"title\": \"bbb\"\n }, {\n \"id\": \"333\",\n \"title\": \"ccc\"\n }]\n}, {\n \"catId\": \"2\",\n \"catTitle\": \"b\",\n \"exampleArray\": [{\n \"id\": \"444\",\n \"title\": \"ddd\"\n }, {\n \"id\": \"555\",\n \"title\": \"eee\"\n }]\n}, {\n \"catId\": \"3\",\n \"catTitle\": \"c\",\n \"exampleArray\": []\n}, {\n \"catId\": \"4\",\n \"catTitle\": \"d\",\n \"exampleArray\": [{\n \"id\": \"555\",\n \"title\": \"fff\"\n }]\n}];\nconst search = \"fff\";\n\nconsole.log(data.filter(item => {\n return item.exampleArray.some(category=> {\n return category.title.toLowerCase().includes(search.toLowerCase())\n })\n })) some"
},
{
"answer_id": 74657584,
"author": "Rohìt Jíndal",
"author_id": 4116300,
"author_profile": "https://Stackoverflow.com/users/4116300",
"pm_score": 0,
"selected": false,
"text": "Array.filter() String.includes() const data = [{\n \"catId\": \"1\",\n \"catTitle\": \"a\",\n \"exampleArray\": [{\n \"id\": \"111\",\n \"title\": \"aaa\"\n }, {\n \"id\": \"222\",\n \"title\": \"bbb\"\n }, {\n \"id\": \"333\",\n \"title\": \"ccc\"\n }]\n}, {\n \"catId\": \"2\",\n \"catTitle\": \"b\",\n \"exampleArray\": [{\n \"id\": \"444\",\n \"title\": \"ddd\"\n }, {\n \"id\": \"555\",\n \"title\": \"eee\"\n }]\n}, {\n \"catId\": \"3\",\n \"catTitle\": \"c\",\n \"exampleArray\": []\n}, {\n \"catId\": \"4\",\n \"catTitle\": \"d\",\n \"exampleArray\": [{\n \"id\": \"555\",\n \"title\": \"fff\"\n }]\n}];\n\nconst searchWord = 'aaa';\n\nconst res = data.filter(obj => {\n obj.exampleArray = obj.exampleArray.filter(({ title }) => title.includes(searchWord))\n return obj.exampleArray.length;\n});\n\nconsole.log(res);"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655906",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20666131/"
] |
74,655,908
|
<p>I have a validated JSON file with all the languages of the world. I am trying to populate a list on a Vue 3 app but cannot seem to get it right. My lack of experience forces me to ask how do I access the inner parts of an object.</p>
<p>JSON file (shortened):</p>
<pre><code>[
{ "code": "ab", "name": "Abkhaz", "nativeName": "аҧсуа" },
{ "code": "aa", "name": "Afar", "nativeName": "Afaraf" },
{ "code": "af", "name": "Afrikaans", "nativeName": "Afrikaans" },
{ "code": "ak", "name": "Akan", "nativeName": "Akan" },
{ "code": "sq", "name": "Albanian", "nativeName": "Shqip" },
{ "code": "am", "name": "Amharic", "nativeName": "አማርኛ" },
{ "code": "ar", "name": "Arabic", "nativeName": "العربية" },
{ "code": "an", "name": "Aragonese", "nativeName": "Aragonés" }
]
</code></pre>
<p>Vue JS part that imports the JSON file and adds it to a list:</p>
<pre><code><script setup>
import { ref } from "vue";
import languages from '@/store/languages.json'
import axios from "axios";
const allLangauges = ref([languages])
</script>
</code></pre>
<p>Here is the part in the Vue app that is supposed to populate the div:</p>
<pre><code><div class="selectLanguageWrap relative" v-if="fields.searching">
<div class="selectLanguages absolute">
<div
v-for="name in allLangauges"
:key="name.id"
:value="name.id"
class="languageOption flex"
>
<input type="checkbox" name="" id="" value="" />
<h4>{{ name.name }}</h4>
</div>
</div>
</div>
</code></pre>
<p>If I console.log the response then I get the following:
<a href="https://i.stack.imgur.com/7CcUW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7CcUW.png" alt="enter image description here" /></a></p>
<p>How do I access the name property of the inner array? I am still learning so want to know how to access the inner parts. Do I have to do languages._rawValue.name? or ['name'] or how?</p>
<p>What am I doing wrong and why can I not see a complete list with all the languages in the div?</p>
|
[
{
"answer_id": 74655945,
"author": "AschenAI",
"author_id": 20665111,
"author_profile": "https://Stackoverflow.com/users/20665111",
"pm_score": 0,
"selected": false,
"text": "Array.prototype.find() const data = [\n {\n catId: \"1\",\n catTitle: \"a\",\n exampleArray: [\n {\n id: \"111\",\n title: \"aaa\",\n },\n {\n id: \"222\",\n title: \"bbb\",\n },\n {\n id: \"333\",\n title: \"ccc\",\n },\n ],\n },\n // ...\n];\n\n// The search term that the user entered\nconst searchTerm = \"aaa\";\n\n// Use the find() method to search the data array for the object that has\n// a title property that includes the search term\nconst result = data.find((item) => {\n return item.exampleArray.some((item) => {\n return item.title.toLowerCase().includes(searchTerm.toLowerCase());\n });\n});\nconsole.log(result);\n// The result will be:\n// {\n// \"catId\": \"1\",\n// \"catTitle\": \"a\",\n// \"exampleArray\": [{\n// \"id\": \"111\",\n// \"title\": \"aaa\"\n// }]\n// }"
},
{
"answer_id": 74655951,
"author": "oliverbj",
"author_id": 989185,
"author_profile": "https://Stackoverflow.com/users/989185",
"pm_score": 0,
"selected": false,
"text": "return data.Filter(item => {\n // filter the `exampleArray` for each `item` by checking if the `title` property of each object in the array contains the search string\n const matchingItems = item.exampleArray.filter(example => example.title.toLowerCase().includes(this.search.toLowerCase()));\n // return `true` for the current `item` if there are any matching items in the `exampleArray`\n return matchingItems.length > 0;\n});\n exampleArray exampleArray [\n {\n \"catId\":\"1\",\n \"catTitle\":\"a\",\n \"exampleArray\":[\n {\n \"id\":\"111\",\n \"title\":\"aaa\"\n }\n ]\n }\n]\n"
},
{
"answer_id": 74655968,
"author": "Salketer",
"author_id": 1620194,
"author_profile": "https://Stackoverflow.com/users/1620194",
"pm_score": 1,
"selected": false,
"text": "const data = \n[{\n \"catId\": \"1\",\n \"catTitle\": \"a\",\n \"exampleArray\": [{\n \"id\": \"111\",\n \"title\": \"aaa\"\n }, {\n \"id\": \"222\",\n \"title\": \"bbb\"\n }, {\n \"id\": \"333\",\n \"title\": \"ccc\"\n }]\n}, {\n \"catId\": \"2\",\n \"catTitle\": \"b\",\n \"exampleArray\": [{\n \"id\": \"444\",\n \"title\": \"ddd\"\n }, {\n \"id\": \"555\",\n \"title\": \"eee\"\n }]\n}, {\n \"catId\": \"3\",\n \"catTitle\": \"c\",\n \"exampleArray\": []\n}, {\n \"catId\": \"4\",\n \"catTitle\": \"d\",\n \"exampleArray\": [{\n \"id\": \"555\",\n \"title\": \"fff\"\n }]\n}];\nconst search = \"fff\";\n\nconsole.log(data.filter(item => {\n return item.exampleArray.some(category=> {\n return category.title.toLowerCase().includes(search.toLowerCase())\n })\n })) some"
},
{
"answer_id": 74657584,
"author": "Rohìt Jíndal",
"author_id": 4116300,
"author_profile": "https://Stackoverflow.com/users/4116300",
"pm_score": 0,
"selected": false,
"text": "Array.filter() String.includes() const data = [{\n \"catId\": \"1\",\n \"catTitle\": \"a\",\n \"exampleArray\": [{\n \"id\": \"111\",\n \"title\": \"aaa\"\n }, {\n \"id\": \"222\",\n \"title\": \"bbb\"\n }, {\n \"id\": \"333\",\n \"title\": \"ccc\"\n }]\n}, {\n \"catId\": \"2\",\n \"catTitle\": \"b\",\n \"exampleArray\": [{\n \"id\": \"444\",\n \"title\": \"ddd\"\n }, {\n \"id\": \"555\",\n \"title\": \"eee\"\n }]\n}, {\n \"catId\": \"3\",\n \"catTitle\": \"c\",\n \"exampleArray\": []\n}, {\n \"catId\": \"4\",\n \"catTitle\": \"d\",\n \"exampleArray\": [{\n \"id\": \"555\",\n \"title\": \"fff\"\n }]\n}];\n\nconst searchWord = 'aaa';\n\nconst res = data.filter(obj => {\n obj.exampleArray = obj.exampleArray.filter(({ title }) => title.includes(searchWord))\n return obj.exampleArray.length;\n});\n\nconsole.log(res);"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655908",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9361135/"
] |
74,655,911
|
<p>I'm trying to extract text from <BR> tag. But unfortunately nothing worked for me.</p>
<pre><code><div id="sign_in" class="sign_in">
<h4>usernames lists:</h4>
user_1
<br>
user_2
<br>
user_3
<br>
user_4
<br>
</div>
</code></pre>
<p>I'm trying to get it in the list and then extract text.</p>
<pre><code>List <WebElement> li = driver.findElements(By.xpath("//div[@class='sign_in']/br"));
for(int i=0;i<li.size();i++) {
System.out.println(li.get(i).getText());
}
</code></pre>
|
[
{
"answer_id": 74655945,
"author": "AschenAI",
"author_id": 20665111,
"author_profile": "https://Stackoverflow.com/users/20665111",
"pm_score": 0,
"selected": false,
"text": "Array.prototype.find() const data = [\n {\n catId: \"1\",\n catTitle: \"a\",\n exampleArray: [\n {\n id: \"111\",\n title: \"aaa\",\n },\n {\n id: \"222\",\n title: \"bbb\",\n },\n {\n id: \"333\",\n title: \"ccc\",\n },\n ],\n },\n // ...\n];\n\n// The search term that the user entered\nconst searchTerm = \"aaa\";\n\n// Use the find() method to search the data array for the object that has\n// a title property that includes the search term\nconst result = data.find((item) => {\n return item.exampleArray.some((item) => {\n return item.title.toLowerCase().includes(searchTerm.toLowerCase());\n });\n});\nconsole.log(result);\n// The result will be:\n// {\n// \"catId\": \"1\",\n// \"catTitle\": \"a\",\n// \"exampleArray\": [{\n// \"id\": \"111\",\n// \"title\": \"aaa\"\n// }]\n// }"
},
{
"answer_id": 74655951,
"author": "oliverbj",
"author_id": 989185,
"author_profile": "https://Stackoverflow.com/users/989185",
"pm_score": 0,
"selected": false,
"text": "return data.Filter(item => {\n // filter the `exampleArray` for each `item` by checking if the `title` property of each object in the array contains the search string\n const matchingItems = item.exampleArray.filter(example => example.title.toLowerCase().includes(this.search.toLowerCase()));\n // return `true` for the current `item` if there are any matching items in the `exampleArray`\n return matchingItems.length > 0;\n});\n exampleArray exampleArray [\n {\n \"catId\":\"1\",\n \"catTitle\":\"a\",\n \"exampleArray\":[\n {\n \"id\":\"111\",\n \"title\":\"aaa\"\n }\n ]\n }\n]\n"
},
{
"answer_id": 74655968,
"author": "Salketer",
"author_id": 1620194,
"author_profile": "https://Stackoverflow.com/users/1620194",
"pm_score": 1,
"selected": false,
"text": "const data = \n[{\n \"catId\": \"1\",\n \"catTitle\": \"a\",\n \"exampleArray\": [{\n \"id\": \"111\",\n \"title\": \"aaa\"\n }, {\n \"id\": \"222\",\n \"title\": \"bbb\"\n }, {\n \"id\": \"333\",\n \"title\": \"ccc\"\n }]\n}, {\n \"catId\": \"2\",\n \"catTitle\": \"b\",\n \"exampleArray\": [{\n \"id\": \"444\",\n \"title\": \"ddd\"\n }, {\n \"id\": \"555\",\n \"title\": \"eee\"\n }]\n}, {\n \"catId\": \"3\",\n \"catTitle\": \"c\",\n \"exampleArray\": []\n}, {\n \"catId\": \"4\",\n \"catTitle\": \"d\",\n \"exampleArray\": [{\n \"id\": \"555\",\n \"title\": \"fff\"\n }]\n}];\nconst search = \"fff\";\n\nconsole.log(data.filter(item => {\n return item.exampleArray.some(category=> {\n return category.title.toLowerCase().includes(search.toLowerCase())\n })\n })) some"
},
{
"answer_id": 74657584,
"author": "Rohìt Jíndal",
"author_id": 4116300,
"author_profile": "https://Stackoverflow.com/users/4116300",
"pm_score": 0,
"selected": false,
"text": "Array.filter() String.includes() const data = [{\n \"catId\": \"1\",\n \"catTitle\": \"a\",\n \"exampleArray\": [{\n \"id\": \"111\",\n \"title\": \"aaa\"\n }, {\n \"id\": \"222\",\n \"title\": \"bbb\"\n }, {\n \"id\": \"333\",\n \"title\": \"ccc\"\n }]\n}, {\n \"catId\": \"2\",\n \"catTitle\": \"b\",\n \"exampleArray\": [{\n \"id\": \"444\",\n \"title\": \"ddd\"\n }, {\n \"id\": \"555\",\n \"title\": \"eee\"\n }]\n}, {\n \"catId\": \"3\",\n \"catTitle\": \"c\",\n \"exampleArray\": []\n}, {\n \"catId\": \"4\",\n \"catTitle\": \"d\",\n \"exampleArray\": [{\n \"id\": \"555\",\n \"title\": \"fff\"\n }]\n}];\n\nconst searchWord = 'aaa';\n\nconst res = data.filter(obj => {\n obj.exampleArray = obj.exampleArray.filter(({ title }) => title.includes(searchWord))\n return obj.exampleArray.length;\n});\n\nconsole.log(res);"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655911",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20666408/"
] |
74,655,919
|
<p>I have the following code.</p>
<p>I want to go through the 'outlierdataframe' dataframe <strong>row by row</strong> and <strong>explode the values</strong> in the 'x' and 'y' columns.</p>
<p>For each exploded row, I then want to store this exploded row as its own <strong>dataframe</strong>, with <strong>columns 'newID', 'x' and 'y'</strong>.</p>
<p>However, the following code prints <strong>everything in one column</strong> rather than printing the <strong>exploded 'x' values in one column</strong>, the <strong>exploded 'y' values in another column</strong>?</p>
<p>I would be so grateful for a helping hand!</p>
<pre><code>individualframe = outlierdataframe.iloc[0]
individualoutliers = individualframe.explode(list('xy'))
newframe = pd.DataFrame(individualoutliers)
print(newframe)
</code></pre>
<p>outlier dataframe first line:</p>
<p><a href="https://i.stack.imgur.com/JvuCi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JvuCi.png" alt="enter image description here" /></a></p>
<p>indexing first line of outlier dataframe:</p>
<pre><code>outlierdataframe.iloc[0]
index 24
subID Prolific_610020
level 1
complete False
duration 20.015686
map_view 12.299759
distance 203.426697
x [55, 55, 55, 60, 60, 60, 65, 70, 70, 75, 80, 8...
y [60, 60, 60, 60, 65, 65, 70, 70, 75, 75, 80, 8...
r [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 1...
batch 1
newID 610020
Name: 24, dtype: object
</code></pre>
<pre><code>newframe = pd.DataFrame(individualoutliers)
print(newframe)
24
0 24
1 Prolific_610020
2 1
3 False
4 20.015686
.. ...
121 55
122 55
123 55
124 1
125 610020
</code></pre>
|
[
{
"answer_id": 74656105,
"author": "Caledonian26",
"author_id": 12985497,
"author_profile": "https://Stackoverflow.com/users/12985497",
"pm_score": 0,
"selected": false,
"text": "individualframe = outlierdataframe.iloc[0]\nindividualoutliers1 = individualframe[['x']].explode('x')\nindividualoutliers2 = individualframe[['y']].explode('y')\nnewIDs = individualframe[['newID']][0]\nindividualoutliers1 = pd.DataFrame(individualoutliers1)\nindividualoutliers2 = pd.DataFrame(individualoutliers2)\ndata = [individualoutliers1,individualoutliers2]\nnewframe = pd.concat(data,axis=1)\nnewframe = newframe.rename(columns={newframe.columns.values[0]:'x',newframe.columns.values[1]:'y'})\nnewframe['newID'] = newIDs \nprint(newframe)\n\n\nOutput exceeds the size limit. Open the full output data in a text editor\n y y newID\n0 55 60 610020\n1 55 60 610020\n2 55 60 610020\n3 60 60 610020\n4 60 65 610020\n5 60 65 610020\n6 65 70 610020\n"
},
{
"answer_id": 74656130,
"author": "abokey",
"author_id": 16120011,
"author_profile": "https://Stackoverflow.com/users/16120011",
"pm_score": 1,
"selected": false,
"text": "pandas.DataFrame.apply pandas.Series.explode list x y out = (\n df\n .loc[:, [\"newID\", \"x\", \"y\"]]\n .apply(lambda x: pd.Series(x).explode())\n )\n print(out)\n\n newID x y\n0 610020 100 60\n0 610020 55 60\n0 610020 55 60\n0 610020 60 60\n0 610020 60 65\n0 610020 60 65\n0 610020 65 70\n0 610020 70 70\n0 610020 70 75\n0 610020 75 75\n0 610020 80 80\n df_newID for k, g in out.groupby(\"newID\"):\n globals()['df_' + str(k)] = g\n \nprint(df_610020, type(df_610020))\n\n newID x y\n0 610020 100 60\n0 610020 55 60\n0 610020 55 60\n0 610020 60 60\n0 610020 60 65\n0 610020 60 65\n0 610020 65 70\n0 610020 70 70\n0 610020 70 75\n0 610020 75 75\n0 610020 80 80 <class 'pandas.core.frame.DataFrame'>\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655919",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12985497/"
] |
74,655,952
|
<p>I want to use Redis through docker for the cache but got this error.</p>
<pre class="lang-none prettyprint-override"><code>django.core.cache.backends.base.InvalidCacheBackendError: Could not find backend 'django.core.cache.backends.redis.RedisCache': No module named 'django.core.cache.backends.redis'
</code></pre>
<p>My cache settings are this.</p>
<pre class="lang-py prettyprint-override"><code>CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.redis.RedisCache',
'LOCATION': 'redis://127.0.0.1:6379',
}
}
</code></pre>
<p>I took them from Django documentation.</p>
<p>I used this command to start a Redis instance in docker.</p>
<pre><code>docker run --name some-redis -d redis
</code></pre>
|
[
{
"answer_id": 74656019,
"author": "lucutzu33",
"author_id": 8770336,
"author_profile": "https://Stackoverflow.com/users/8770336",
"pm_score": 0,
"selected": false,
"text": "django-redis"
},
{
"answer_id": 74656401,
"author": "scūriolus",
"author_id": 12236313,
"author_profile": "https://Stackoverflow.com/users/12236313",
"pm_score": 1,
"selected": false,
"text": "'LOCATION': 'redis://127.0.0.1:6379' redis docker run --name some-redis -d redis some-redis 'LOCATION': 'redis://127.0.0.1:6379' 'LOCATION': 'redis://some-redis:6379'"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655952",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20613517/"
] |
74,655,963
|
<p>In my project, I am working with the redux store and that data will store in local storage. On every new update, local storage will update and as per local storage, my component will render with forEach method.</p>
<p>With the below code, I am getting the data from local storage.</p>
<pre><code>const ShowMyFlashcard = () => {
let cardValueObj=[]
useEffect(() => {
let cardValue = localStorage.getItem("cardValue");
if (cardValue == null) {
cardValueObj= [];
} else {
cardValueObj= JSON.parse(cardValue);
}
});
return (
// {/* SECTION TO SHOW CREATED ALL CARDS*/}
<div className="mx-10 my-10 grid grid-cols-3 gap-4 place-content-around flex flex-wrap justify-items-center">
{cardValueObj.forEach((element) => {
<div className=" shadow-md bg-white p-5 h-64 w-64 m-4 mx-1.5 my-1.5">
<div>
<h1 className="text-center font-bold mx-1.5 my-1.5">
{element.createGroup}
</h1>
<div className="text-center bg-white mx-1.5 my-1.5 h-32 w-48">
<span>{element.groupDescription}</span>
</div>
<div className="flex justify-center">
<button className="rounded-md text-red-600 border-solid border-2 bg-white border-red-700 mx-2 my-2 h-8 w-40">
View Cards
</button>
</div>
</div>
</div>;
})}
</div>
);
};
</code></pre>
<p>export default ShowMyFlashcard;</p>
|
[
{
"answer_id": 74656019,
"author": "lucutzu33",
"author_id": 8770336,
"author_profile": "https://Stackoverflow.com/users/8770336",
"pm_score": 0,
"selected": false,
"text": "django-redis"
},
{
"answer_id": 74656401,
"author": "scūriolus",
"author_id": 12236313,
"author_profile": "https://Stackoverflow.com/users/12236313",
"pm_score": 1,
"selected": false,
"text": "'LOCATION': 'redis://127.0.0.1:6379' redis docker run --name some-redis -d redis some-redis 'LOCATION': 'redis://127.0.0.1:6379' 'LOCATION': 'redis://some-redis:6379'"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655963",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19317459/"
] |
74,655,983
|
<p>How would I align the <code><a></code> element, containing the Button with the string <code>Push Me</code> to the right side of the <code><div></code> (<code><Paper></code>)?</p>
<p><a href="https://codesandbox.io/s/eager-noyce-j356qe" rel="nofollow noreferrer">https://codesandbox.io/s/eager-noyce-j356qe</a></p>
<p>The application is in ´demo.tsx` file.</p>
<p>Note: I cannot set the position of the button to <code>absolute</code> and then position it <code>right: 0px</code> because I need to adjust the height of the <code><div></code> (<code><Paper></code>) according to its content, which includes the height of the <code><Button></code>.</p>
|
[
{
"answer_id": 74656019,
"author": "lucutzu33",
"author_id": 8770336,
"author_profile": "https://Stackoverflow.com/users/8770336",
"pm_score": 0,
"selected": false,
"text": "django-redis"
},
{
"answer_id": 74656401,
"author": "scūriolus",
"author_id": 12236313,
"author_profile": "https://Stackoverflow.com/users/12236313",
"pm_score": 1,
"selected": false,
"text": "'LOCATION': 'redis://127.0.0.1:6379' redis docker run --name some-redis -d redis some-redis 'LOCATION': 'redis://127.0.0.1:6379' 'LOCATION': 'redis://some-redis:6379'"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74655983",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3935035/"
] |
74,656,004
|
<p>I have several category dummies that are mutually exclusive</p>
<pre><code>id cat1 cat2 cat3
A 0 0 1
B 1 0 0
C 1 0 0
D 0 0 1
E 0 1 0
F 0 0 1
..
</code></pre>
<p>I want to create a new column that contains all categories</p>
<pre><code>id cat1 cat2 cat3 type
A 0 0 1 cat3
B 1 0 0 cat1
C 1 0 0 cat1
D 0 0 1 cat3
E 0 1 0 cat2
F 0 0 1 cat3
..
</code></pre>
|
[
{
"answer_id": 74656035,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 2,
"selected": true,
"text": "pandas.from_dummies filter df['type'] = pd.from_dummies(df.filter(like='cat'))\n id cat1 cat2 cat3 type\n0 A 0 0 1 cat3\n1 B 1 0 0 cat1\n2 C 1 0 0 cat1\n3 D 0 0 1 cat3\n4 E 0 1 0 cat2\n5 F 0 0 1 cat3\n"
},
{
"answer_id": 74656052,
"author": "jezrael",
"author_id": 2901002,
"author_profile": "https://Stackoverflow.com/users/2901002",
"pm_score": 0,
"selected": false,
"text": "DataFrame.dot DataFrame.filter cat 1 , m = df.filter(like='cat').eq(1)\n#all columns without first\n#m = df.iloc[:, 1:].eq(1)\ndf['type'] = m.dot(m.columns + ',').str[:-1]\nprint (df)\n id cat1 cat2 cat3 type\n0 A 0 0 1 cat3\n1 B 1 0 0 cat1\n2 C 1 0 0 cat1\n3 D 0 0 1 cat3\n4 E 0 1 0 cat2\n5 F 0 0 1 cat3\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656004",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14790056/"
] |
74,656,012
|
<pre><code>int a = 5;
int b = a; //error, a is not a constant expression
int main(void)
{
static int c = a; //error, a is not a constant expression
int d = a; //okay, a don't have to be a constant expression
return 0;
}
</code></pre>
<ol>
<li><p>I don't understand what happens when a C compiler handles those variable declarations.</p>
</li>
<li><p>Why was C designed to be unable to handle <code>int b = a</code>?</p>
</li>
</ol>
|
[
{
"answer_id": 74656125,
"author": "Eric Postpischil",
"author_id": 298225,
"author_profile": "https://Stackoverflow.com/users/298225",
"pm_score": 2,
"selected": false,
"text": "int a = 5; int b = a; a b a int b = a; b int b = a; main int b = a; main b main"
},
{
"answer_id": 74656149,
"author": "Lundin",
"author_id": 584518,
"author_profile": "https://Stackoverflow.com/users/584518",
"pm_score": 1,
"selected": false,
"text": "static static x = func(); func() x a b a b"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656012",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20142751/"
] |
74,656,116
|
<p>As you can see in my index.html page, I am adding two javascript file in a single page, one is for menu drop down and another is for readmore option.i'm new to javascript please help.when i add both last one file is work only first file cannot work .</p>
<pre><code>
"index.html"
<!DOCTYPE html>
<html>
<head>
<title>united</title>
<link rel="stylesheet" href="/static/css/dps.css"/>
</head>
<body>
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">MENU</button>
<div id="myDropdown" class="dropdown-content">
<a href='..'>Home</a>
<a href="aboutus">About</a>
<a href="#contact">Contact</a>
<a href="Question-bank">Question Bank</a>
<a href="updated-calender">calender</a>
<a href="calculator">calculator</a>
</div>
</div><br>
<script src="/static/js/menu.js"></script>
<script src="/static/js/readmore.js" ></script>
</Body>
</html>
</code></pre>
<p>"menu.js"</p>
<pre><code> /* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
// Close the dropdown if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
</code></pre>
<p>"readmore.js"</p>
<pre><code>
function myFunction() {
var dots = document.getElementById("dots");
var moreText = document.getElementById("more");
var btnText = document.getElementById("myBtn");
if (dots.style.display === "none") {
dots.style.display = "inline";
btnText.innerHTML = "Read more";
moreText.style.display = "none";
}
else {
dots.style.display = "none";
btnText.innerHTML = "Read less";
moreText.style.display = "inline";
}
}
</code></pre>
<p>please solve my problem why two js files cannot work in a single page.</p>
|
[
{
"answer_id": 74660423,
"author": "Tiddo",
"author_id": 532901,
"author_profile": "https://Stackoverflow.com/users/532901",
"pm_score": 1,
"selected": false,
"text": "myFunction myFunction"
},
{
"answer_id": 74660671,
"author": "Keke675",
"author_id": 18931610,
"author_profile": "https://Stackoverflow.com/users/18931610",
"pm_score": 0,
"selected": false,
"text": "const element = document.getElementById('dropbtnId');\nelement.addEventListener(\"click\", function() {\n myFunction();\n});\n const element = document.getElementById('dropbtnId');\nelement.addEventListener(\"click\", function() {\n alert(\"triggered\");\n}); <html>\n <head>\n <title>united</title>\n \n <link rel=\"stylesheet\" href=\"/static/css/dps.css\"/>\n </head>\n <body>\n \n \n <div class=\"dropdown\">\n <button id=\"dropbtnId\" class=\"dropbtn\">MENU</button>\n <div id=\"myDropdown\" class=\"dropdown-content\">\n <a href='..'>Home</a>\n <a href=\"aboutus\">About</a>\n <a href=\"#contact\">Contact</a>\n <a href=\"Question-bank\">Question Bank</a>\n <a href=\"updated-calender\">calender</a>\n <a href=\"calculator\">calculator</a>\n </div>\n </div><br>"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656116",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20519479/"
] |
74,656,132
|
<p>Is it possible to get data of sub-documents by reading only the main document in Firestore? Basically, the Firebase <code>listCollections()</code> method gives the id of subcollections, but how can we get their data?</p>
<p>I have tried for <code>listCollections()</code> to get the id of sub-collections, but have not found a way to get data sub-collections data.</p>
|
[
{
"answer_id": 74657117,
"author": "renaud H",
"author_id": 7032224,
"author_profile": "https://Stackoverflow.com/users/7032224",
"pm_score": 0,
"selected": false,
"text": "snapshot.forEach(doc =>{\nconsole.log(doc.id)\nconsole.log(doc.data())\n})\n\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656132",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18890260/"
] |
74,656,137
|
<p>I'm trying to estimate the gradient of my graph.</p>
<pre><code>#define the function
def gradient(y1,y2,x1,x2):
gradient = ((y1 - y2)/(x2 - x1))
y1 = 1.07
y2 = 1.39
x1 = 283
x2 = 373
print('The gradient of this graph is', gradient)
</code></pre>
<p>All it prints is</p>
<pre><code>The gradient of this graph is <function gradient at 0x7fb95096bd30>
</code></pre>
|
[
{
"answer_id": 74657117,
"author": "renaud H",
"author_id": 7032224,
"author_profile": "https://Stackoverflow.com/users/7032224",
"pm_score": 0,
"selected": false,
"text": "snapshot.forEach(doc =>{\nconsole.log(doc.id)\nconsole.log(doc.data())\n})\n\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656137",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20618730/"
] |
74,656,148
|
<p>I have an out from a tool, which is almost json.</p>
<pre class="lang-json prettyprint-override"><code> {"acquired": None,
"avail": True,
"cls": "NetworkService",
"params": {"address": "192.168.7.193", "password": "root", "username": "root"}}
</code></pre>
<p>The problem is <code>None</code> and <code>True</code>, is there a possible way to tell jq to threat these as strings?</p>
<p>I could preprocess with <code>sed</code>, but it would break if suddenly a third value appeared.</p>
|
[
{
"answer_id": 74656324,
"author": "jpseng",
"author_id": 16332641,
"author_profile": "https://Stackoverflow.com/users/16332641",
"pm_score": 3,
"selected": true,
"text": "yq --input-format yaml --output-format json file.json\n {\n \"acquired\": \"None\",\n \"avail\": true,\n \"cls\": \"NetworkService\",\n \"params\": {\n \"address\": \"192.168.7.193\",\n \"password\": \"root\",\n \"username\": \"root\"\n }\n}\n"
},
{
"answer_id": 74656711,
"author": "pmf",
"author_id": 2158479,
"author_profile": "https://Stackoverflow.com/users/2158479",
"pm_score": 1,
"selected": false,
"text": "jq yq . file.json\n {\n \"acquired\": \"None\",\n \"avail\": true,\n \"cls\": \"NetworkService\",\n \"params\": {\n \"address\": \"192.168.7.193\",\n \"password\": \"root\",\n \"username\": \"root\"\n }\n}\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656148",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1809810/"
] |
74,656,156
|
<p>I'm trying to use the below command. Whenever I use this, memory usage is extremely high. Is there a way to lower memory usage while completing the same task?</p>
<pre><code>Get-ChildItem -Path "C:\" -Recurse |
sort -descending -property length |
select -first 20 fullname, @{Name="Gigabytes";Expression={[Math]::round($_.length / 1GB, 2)}}
</code></pre>
|
[
{
"answer_id": 74657999,
"author": "Santiago Squarzon",
"author_id": 15339544,
"author_profile": "https://Stackoverflow.com/users/15339544",
"pm_score": 2,
"selected": false,
"text": "SortedSet<T> IComparable IEquatable<T> $sorted.Count -lt 20 class SimpleFile : System.IComparable, System.IEquatable[object] {\n [string] $FullName\n [Int64] $Length\n [double] $Gigabytes\n\n SimpleFile([IO.FileInfo] $File) {\n $this.FullName = $File.FullName\n $this.Length = $File.Length\n $this.Gigabytes = [Math]::Round($File.Length / 1Gb, 2)\n }\n\n [int] GetHashCode() {\n return $this.FullName.GetHashCode()\n }\n\n [int] CompareTo([object] $That) {\n if($diff = $this.Length.CompareTo($That.Length)) {\n return $diff\n }\n return 0\n }\n\n [bool] Equals([object] $That) {\n return $this.FullName -eq $That.FullName\n }\n}\n\n$result = Get-ChildItem C:\\ -Recurse -File -EA 0 | & {\n begin {\n $sorted = [System.Collections.Generic.SortedSet[SimpleFile]]::new()\n }\n process {\n if($sorted.Count -lt 20) {\n $null = $sorted.Add($_)\n return\n }\n if($sorted.Min.Length -lt $_.Length) {\n $null = $sorted.Remove($sorted.Min)\n $null = $sorted.Add($_)\n }\n }\n end {\n $sorted.Reverse()\n }\n}\n"
},
{
"answer_id": 74659124,
"author": "js2010",
"author_id": 6654942,
"author_profile": "https://Stackoverflow.com/users/6654942",
"pm_score": 0,
"selected": false,
"text": "cmd /c 'dir /s c:\\ | findstr /v \"Directory of\" | findstr /v \"<DIR>\" | findstr /v \"<JUNCTION>\" | findstr /v \"Total Files Listed:\" | sort.exe /+20' | select -last 20\n\n\n09/13/2018 04:45 PM 362,337,255 78ec5a6bf483ef155dc2a311e526f8a5.cab\n09/23/2022 02:24 PM 379,584,512 clonezilla-live-3.0.1-8-amd64.iso\n09/13/2018 04:45 PM 445,038,363 8bb1cf01f3ce1952f356d0aff91dbb2f.cab\n09/13/2018 04:45 PM 445,038,363 8bb1cf01f3ce1952f356d0aff91dbb2f.cab\n04/13/2012 03:02 PM 481,143,404 Data1.cab\n02/23/2022 12:10 PM 540,587,242 Miller_MUS171_Lecture02_v2.mp4\n05/17/2017 06:27 PM 551,624,704 maple.help\n09/13/2018 04:44 PM 600,753,345 a32918368eba6a062aaaaf73e3618131.cab\n09/13/2018 04:44 PM 600,753,345 a32918368eba6a062aaaaf73e3618131.cab\n11/10/2022 03:12 AM 641,728,512 BaseLayer.vhdx\n11/10/2022 03:12 AM 641,728,512 BaseLayer.vhdx\n11/09/2022 09:17 AM 687,780,220 Windows10.0-KB5019959-x64.cab\n12/12/2017 01:45 PM 740,060,956 2ddf168b.msi\n09/13/2018 04:45 PM 760,142,380 9722214af0ab8aa9dffb6cfdafd937b7.cab\n09/13/2018 04:45 PM 760,142,380 9722214af0ab8aa9dffb6cfdafd937b7.cab\n06/02/2016 03:19 PM 894,730,632 392b35b.msi\n04/18/2021 03:03 PM 905,672,704 37b241d4.msi\n06/13/2022 12:52 PM 905,672,704 37b241d7.msi\n04/18/2021 03:03 PM 905,672,704 Stata17.msi\n01/12/2018 03:06 PM 1,075,667,093 windows10.0-kb4056891-x64.msu\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656156",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10778022/"
] |
74,656,186
|
<p>I have 2 directories, A and B. In A, I have subdirectories 1, 2, 3, 4 while in B I have 1 and 3. How can I highlight 2 and 4 easily?
The contents of the subdirectories are the same, respectively, so I just want to compare the names.</p>
<p>Mark -> Compare Directories only compare files, but not directories.</p>
|
[
{
"answer_id": 74660479,
"author": "albina",
"author_id": 20666497,
"author_profile": "https://Stackoverflow.com/users/20666497",
"pm_score": 1,
"selected": false,
"text": " $ diff A/ B/\n Common subdirectories: A/1 and B/1\n Only in A/: 2\n Common subdirectories: A/3 and B/3\n Only in A/: 4\n $ diff -rq A B\nOnly in A/: 2\nOnly in A/: 4\n\n-r recursively compares any subdirectories\n-q shows only differences without any details\n comp fc diff"
},
{
"answer_id": 74660530,
"author": "Begging",
"author_id": 16606223,
"author_profile": "https://Stackoverflow.com/users/16606223",
"pm_score": 0,
"selected": false,
"text": "diff -rq A B\n diff <(find A -type d) <(find B -type d)\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656186",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2354702/"
] |
74,656,214
|
<pre><code>#include <stdio.h>
struct dog
{
int name[10];
char breed[10];
int age;
char color[10];
};
int main()
{
struct dog frodo;
struct dog **ptr=&frodo.name;
for(int i=0;i<10;i++)
frodo.name[i]=i;
for(int i=0;i<10;i++)
printf(" frodo.name[%d]%d\n",i,frodo.name[i]);
for(int i=0;i<10;i++)
printf(" ptr =%d\n",ptr[i]);
}
</code></pre>
<p>I tried using double pointer but the index is not matching when value is being printed.</p>
<p>O/P:
frodo.name[0]0
frodo.name[1]1</p>
<p>ptr =0
ptr =2</p>
|
[
{
"answer_id": 74656255,
"author": "tstanisl",
"author_id": 4989451,
"author_profile": "https://Stackoverflow.com/users/4989451",
"pm_score": 1,
"selected": false,
"text": "ptr frodo.name int ptr int* int *ptr=&frodo.name[0];\n"
},
{
"answer_id": 74657521,
"author": "Tim-Schaeffer_Crown",
"author_id": 20660203,
"author_profile": "https://Stackoverflow.com/users/20660203",
"pm_score": 1,
"selected": true,
"text": "int name[10];\n name struct dog int int int int * pint = name; name int &name int int #include <stdio.h>\n\nstruct dog\n{\n int name[10];\n char breed[10];\n int age;\n char color[10];\n};\n struct dog name int breed char age int color char int main()\n{\nstruct dog frodo;\n frodo struct dog main struct dog **ptr=&frodo.name;\n ptr_to_dog struct dog * ptr_to_dog struct dog struct dog frodo frodo ptr_to_dog = &frodo; &frodo frodo struct dog ptr_to_dog struct dog **ptr ptr struct dog ptr_to_dog struct dog ptr ptr = &ptr_to_dog &frodo.name . & &(frodo.name) frodo.name name foo struct dog &frodo.name name frodo name int &frodo.name int int name struct dog foo ptr int &frodo.name frodo ptr struct dog * ptr_to_dog = &frodo frodo struct dog ptr_to_dog struct dog struct dog struct dog ptr_to_dog[3] struct dog struct dog ptr_to_dog ptr_to_dog struct dog for(int i=0;i<10;i++)\nfrodo.name[i]=i;\n\nfor(int i=0;i<10;i++)\nprintf(\" frodo.name[%d]%d\\n\",i,frodo.name[i]);\n\nfor(int i=0;i<10;i++)\nprintf(\" ptr =%d\\n\",ptr[i]);\n}\n ptr struct dog ptr struct dog int name struct dog frodo ptr name struct dog ptr int name struct dog frodo int * ptr = frodo.name;\n name int frodo.name int name struct dog frodo int name int ptr ptr char frodo.name int char &frodo.name[0] int int frodo.name int frodo.name int int frodo.name &frodo.name frodo.name int #include <stdio.h>\n\nstruct dog\n{\n int name[10];\n char breed[10];\n int age;\n char color[10];\n};\n\nint main()\n{\nstruct dog frodo;\nint *ptr= frodo.name;\n\nfor(int i=0;i<10;i++)\nfrodo.name[i]=i;\n\nfor(int i=0;i<10;i++)\nprintf(\" frodo.name[%d]%d\\n\",i,frodo.name[i]);\n\nfor(int i=0;i<10;i++)\nprintf(\" ptr =%d\\n\",ptr[i]);\n}\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656214",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20666363/"
] |
74,656,225
|
<p>I have a use case in which i use linkedserver in my database sql server but i would like to handle this in wso2 instead of using linkedserver is it possible ? my use case that i have inner join between two table in different database server.</p>
<p>My actual LinkedServer Query</p>
<pre><code>SELECT local.name AS LocalLogins, linked.name AS LinkedLogins
FROM master.sys.server_principals AS local
LEFT JOIN [SRVR002\ACCTG].master.sys.server_principals AS linked
ON local.name = linked.name;
GO
</code></pre>
|
[
{
"answer_id": 74656255,
"author": "tstanisl",
"author_id": 4989451,
"author_profile": "https://Stackoverflow.com/users/4989451",
"pm_score": 1,
"selected": false,
"text": "ptr frodo.name int ptr int* int *ptr=&frodo.name[0];\n"
},
{
"answer_id": 74657521,
"author": "Tim-Schaeffer_Crown",
"author_id": 20660203,
"author_profile": "https://Stackoverflow.com/users/20660203",
"pm_score": 1,
"selected": true,
"text": "int name[10];\n name struct dog int int int int * pint = name; name int &name int int #include <stdio.h>\n\nstruct dog\n{\n int name[10];\n char breed[10];\n int age;\n char color[10];\n};\n struct dog name int breed char age int color char int main()\n{\nstruct dog frodo;\n frodo struct dog main struct dog **ptr=&frodo.name;\n ptr_to_dog struct dog * ptr_to_dog struct dog struct dog frodo frodo ptr_to_dog = &frodo; &frodo frodo struct dog ptr_to_dog struct dog **ptr ptr struct dog ptr_to_dog struct dog ptr ptr = &ptr_to_dog &frodo.name . & &(frodo.name) frodo.name name foo struct dog &frodo.name name frodo name int &frodo.name int int name struct dog foo ptr int &frodo.name frodo ptr struct dog * ptr_to_dog = &frodo frodo struct dog ptr_to_dog struct dog struct dog struct dog ptr_to_dog[3] struct dog struct dog ptr_to_dog ptr_to_dog struct dog for(int i=0;i<10;i++)\nfrodo.name[i]=i;\n\nfor(int i=0;i<10;i++)\nprintf(\" frodo.name[%d]%d\\n\",i,frodo.name[i]);\n\nfor(int i=0;i<10;i++)\nprintf(\" ptr =%d\\n\",ptr[i]);\n}\n ptr struct dog ptr struct dog int name struct dog frodo ptr name struct dog ptr int name struct dog frodo int * ptr = frodo.name;\n name int frodo.name int name struct dog frodo int name int ptr ptr char frodo.name int char &frodo.name[0] int int frodo.name int frodo.name int int frodo.name &frodo.name frodo.name int #include <stdio.h>\n\nstruct dog\n{\n int name[10];\n char breed[10];\n int age;\n char color[10];\n};\n\nint main()\n{\nstruct dog frodo;\nint *ptr= frodo.name;\n\nfor(int i=0;i<10;i++)\nfrodo.name[i]=i;\n\nfor(int i=0;i<10;i++)\nprintf(\" frodo.name[%d]%d\\n\",i,frodo.name[i]);\n\nfor(int i=0;i<10;i++)\nprintf(\" ptr =%d\\n\",ptr[i]);\n}\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656225",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17243183/"
] |
74,656,240
|
<p>I have created a service to which i am subscribed to in my component, however, the div is not rendering at all when i use ngFor.</p>
<p>Component.TS file</p>
<pre><code> import { Component, OnInit } from '@angular/core';
import {FormBuilder, Validators} from '@angular/forms';
import { PlansService } from 'src/app/services/plans.service';
interface JobType {
value: string;
viewValue: string;
}
interface WorkEnv {
value: string;
viewValue: string;
}
@Component({
selector: 'app-post-job',
templateUrl: './post-job.component.html',
styleUrls: ['./post-job.component.css']
})
export class PostJobComponent implements OnInit {
jobTypes: JobType[] = [
{value: 'type-0', viewValue: 'Full-Time'},
{value: 'type-1', viewValue: 'Part-Time'},
{value: 'type-2', viewValue: 'Freelance'},
];
workEnvs: WorkEnv[] = [
{value: 'type-0', viewValue: 'Remote'},
{value: 'type-1', viewValue: 'Hybrid'},
{value: 'type-2', viewValue: 'On-site'},
];
jobForm = this.fb.group({
jobTitle: this.fb.group({
title: ['', [Validators.required, Validators.minLength(2), Validators.pattern('^[_A-z0-9]*((-|\s)*[_A-z0-9])*$')]],
jobType: ['', [Validators.required]]
}),
})
plans: any;
constructor(private fb: FormBuilder, private service:PlansService) {
}
ngOnInit(): void {
this.service.getPlans()
.subscribe(response => {
this.plans = response;
console.log(response);
});
}
// Getter method to access formcontrols
get myForm() {
return this.jobForm.controls;
}
// Submit Registration Form
// onSubmit() {
// this.submitted = true;
// if(!this.jobForm.valid) {
// alert('Please fill all the required fields to create a super hero!')
// } else {
// console.log(this.jobForm.value)
// }
// }
}
</code></pre>
<p>Component.html file</p>
<pre><code><div class="subscription-container" >
<div class="card" *ngFor="let plan of plans " >
<h1>{{plan.title}}</h1>
</div>
</div>
</code></pre>
<p>the data is showing in my console.log but it is not rendering on the card at all. Please help, thank you in advance!</p>
<p>I tried to add a dummy array in the ts file and i printed that to the console log but still did not render in the div</p>
|
[
{
"answer_id": 74656255,
"author": "tstanisl",
"author_id": 4989451,
"author_profile": "https://Stackoverflow.com/users/4989451",
"pm_score": 1,
"selected": false,
"text": "ptr frodo.name int ptr int* int *ptr=&frodo.name[0];\n"
},
{
"answer_id": 74657521,
"author": "Tim-Schaeffer_Crown",
"author_id": 20660203,
"author_profile": "https://Stackoverflow.com/users/20660203",
"pm_score": 1,
"selected": true,
"text": "int name[10];\n name struct dog int int int int * pint = name; name int &name int int #include <stdio.h>\n\nstruct dog\n{\n int name[10];\n char breed[10];\n int age;\n char color[10];\n};\n struct dog name int breed char age int color char int main()\n{\nstruct dog frodo;\n frodo struct dog main struct dog **ptr=&frodo.name;\n ptr_to_dog struct dog * ptr_to_dog struct dog struct dog frodo frodo ptr_to_dog = &frodo; &frodo frodo struct dog ptr_to_dog struct dog **ptr ptr struct dog ptr_to_dog struct dog ptr ptr = &ptr_to_dog &frodo.name . & &(frodo.name) frodo.name name foo struct dog &frodo.name name frodo name int &frodo.name int int name struct dog foo ptr int &frodo.name frodo ptr struct dog * ptr_to_dog = &frodo frodo struct dog ptr_to_dog struct dog struct dog struct dog ptr_to_dog[3] struct dog struct dog ptr_to_dog ptr_to_dog struct dog for(int i=0;i<10;i++)\nfrodo.name[i]=i;\n\nfor(int i=0;i<10;i++)\nprintf(\" frodo.name[%d]%d\\n\",i,frodo.name[i]);\n\nfor(int i=0;i<10;i++)\nprintf(\" ptr =%d\\n\",ptr[i]);\n}\n ptr struct dog ptr struct dog int name struct dog frodo ptr name struct dog ptr int name struct dog frodo int * ptr = frodo.name;\n name int frodo.name int name struct dog frodo int name int ptr ptr char frodo.name int char &frodo.name[0] int int frodo.name int frodo.name int int frodo.name &frodo.name frodo.name int #include <stdio.h>\n\nstruct dog\n{\n int name[10];\n char breed[10];\n int age;\n char color[10];\n};\n\nint main()\n{\nstruct dog frodo;\nint *ptr= frodo.name;\n\nfor(int i=0;i<10;i++)\nfrodo.name[i]=i;\n\nfor(int i=0;i<10;i++)\nprintf(\" frodo.name[%d]%d\\n\",i,frodo.name[i]);\n\nfor(int i=0;i<10;i++)\nprintf(\" ptr =%d\\n\",ptr[i]);\n}\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656240",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20231075/"
] |
74,656,258
|
<p>ɵrenderComponent not found in в @angular/core v 15
How can I use this method in @angular/core v 15 ?</p>
<pre><code>import { ɵrenderComponent, ɵdetectChanges, ɵLifecycleHooksFeature } from "@angular/core";
import { CompileComponent } from "./compile-component.decorator";
import "./style.css";
@CompileComponent({
selector: `ivy`,
template: `
<h1>
Hey! {{ name }} here.
</h1>
<button (click)="changeName()">Change Name</button>
<hr />
<button (click)="loadDynamicComponent()">Load Dynamic Component</button>
<br />
`
})
export class IvyComponent {
name = `Sidd `;
changeName() {
this.name = `Ivy `;
ɵdetectChanges(this);
}
loadDynamicComponent() {
import('./dynamic.component').then(({DynamicComponent}) => {
ɵrenderComponent(DynamicComponent, {
host: "dynamic",
hostFeatures: [ ɵLifecycleHooksFeature ]
});
});
}
}
ɵrenderComponent(IvyComponent, { host: "ivy" });
</code></pre>
<p><a href="https://stackblitz.com/edit/dynamically-load-angular-component-lazily-in-ivy-9zmhrx?file=package.json,index.ts" rel="nofollow noreferrer">https://stackblitz.com/edit/dynamically-load-angular-component-lazily-in-ivy-9zmhrx?file=package.json,index.ts</a></p>
|
[
{
"answer_id": 74656255,
"author": "tstanisl",
"author_id": 4989451,
"author_profile": "https://Stackoverflow.com/users/4989451",
"pm_score": 1,
"selected": false,
"text": "ptr frodo.name int ptr int* int *ptr=&frodo.name[0];\n"
},
{
"answer_id": 74657521,
"author": "Tim-Schaeffer_Crown",
"author_id": 20660203,
"author_profile": "https://Stackoverflow.com/users/20660203",
"pm_score": 1,
"selected": true,
"text": "int name[10];\n name struct dog int int int int * pint = name; name int &name int int #include <stdio.h>\n\nstruct dog\n{\n int name[10];\n char breed[10];\n int age;\n char color[10];\n};\n struct dog name int breed char age int color char int main()\n{\nstruct dog frodo;\n frodo struct dog main struct dog **ptr=&frodo.name;\n ptr_to_dog struct dog * ptr_to_dog struct dog struct dog frodo frodo ptr_to_dog = &frodo; &frodo frodo struct dog ptr_to_dog struct dog **ptr ptr struct dog ptr_to_dog struct dog ptr ptr = &ptr_to_dog &frodo.name . & &(frodo.name) frodo.name name foo struct dog &frodo.name name frodo name int &frodo.name int int name struct dog foo ptr int &frodo.name frodo ptr struct dog * ptr_to_dog = &frodo frodo struct dog ptr_to_dog struct dog struct dog struct dog ptr_to_dog[3] struct dog struct dog ptr_to_dog ptr_to_dog struct dog for(int i=0;i<10;i++)\nfrodo.name[i]=i;\n\nfor(int i=0;i<10;i++)\nprintf(\" frodo.name[%d]%d\\n\",i,frodo.name[i]);\n\nfor(int i=0;i<10;i++)\nprintf(\" ptr =%d\\n\",ptr[i]);\n}\n ptr struct dog ptr struct dog int name struct dog frodo ptr name struct dog ptr int name struct dog frodo int * ptr = frodo.name;\n name int frodo.name int name struct dog frodo int name int ptr ptr char frodo.name int char &frodo.name[0] int int frodo.name int frodo.name int int frodo.name &frodo.name frodo.name int #include <stdio.h>\n\nstruct dog\n{\n int name[10];\n char breed[10];\n int age;\n char color[10];\n};\n\nint main()\n{\nstruct dog frodo;\nint *ptr= frodo.name;\n\nfor(int i=0;i<10;i++)\nfrodo.name[i]=i;\n\nfor(int i=0;i<10;i++)\nprintf(\" frodo.name[%d]%d\\n\",i,frodo.name[i]);\n\nfor(int i=0;i<10;i++)\nprintf(\" ptr =%d\\n\",ptr[i]);\n}\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656258",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14606358/"
] |
74,656,291
|
<p>I have this data frame where I sliced columns from the original data frame:</p>
<pre><code>Type 1 Attack
Grass 62
Grass 82
Dragon 100
Fire 52
Rock 100
</code></pre>
<p>I want to create each Pokemon’s adjusted attack attribute against grass Pokemon based on ‘Type 1’ where;</p>
<ul>
<li>the attack attribute is doubled if grass Pokemon are bad against that type</li>
<li>halved if they are good against that type</li>
<li>else remains the same.</li>
</ul>
<p>I have looping through the data:</p>
<pre><code>grass_attack = []
for value in df_["Type 1"]:
if value ==["Type 1 == Fire"] or value==["Type 1 == Flying"] or value==["Type 1 == Poison"] or value==["Type 1 == Bug"] or value==["Type1== Steel"] or value ==["Type 1 == Grass"] or value ==["Type 1 == Dragon"]:
result.append(df_["Attack"]/2)
elif value==["Type 1==Ground"] or value==["Type1== Ground"] or value==["Type 1 == Water"]:
grass_attack.append(df_["Attack"]*2)
else:
grass_attack.append(df_["Attack"])
df_["grass_attack"] = grass_attack
print(df_)
</code></pre>
<p>but I got some crazy results after this. How can I efficiently loop through a data frame's column in order to adjust another column?</p>
<p>or is there another way to do this?</p>
|
[
{
"answer_id": 74656255,
"author": "tstanisl",
"author_id": 4989451,
"author_profile": "https://Stackoverflow.com/users/4989451",
"pm_score": 1,
"selected": false,
"text": "ptr frodo.name int ptr int* int *ptr=&frodo.name[0];\n"
},
{
"answer_id": 74657521,
"author": "Tim-Schaeffer_Crown",
"author_id": 20660203,
"author_profile": "https://Stackoverflow.com/users/20660203",
"pm_score": 1,
"selected": true,
"text": "int name[10];\n name struct dog int int int int * pint = name; name int &name int int #include <stdio.h>\n\nstruct dog\n{\n int name[10];\n char breed[10];\n int age;\n char color[10];\n};\n struct dog name int breed char age int color char int main()\n{\nstruct dog frodo;\n frodo struct dog main struct dog **ptr=&frodo.name;\n ptr_to_dog struct dog * ptr_to_dog struct dog struct dog frodo frodo ptr_to_dog = &frodo; &frodo frodo struct dog ptr_to_dog struct dog **ptr ptr struct dog ptr_to_dog struct dog ptr ptr = &ptr_to_dog &frodo.name . & &(frodo.name) frodo.name name foo struct dog &frodo.name name frodo name int &frodo.name int int name struct dog foo ptr int &frodo.name frodo ptr struct dog * ptr_to_dog = &frodo frodo struct dog ptr_to_dog struct dog struct dog struct dog ptr_to_dog[3] struct dog struct dog ptr_to_dog ptr_to_dog struct dog for(int i=0;i<10;i++)\nfrodo.name[i]=i;\n\nfor(int i=0;i<10;i++)\nprintf(\" frodo.name[%d]%d\\n\",i,frodo.name[i]);\n\nfor(int i=0;i<10;i++)\nprintf(\" ptr =%d\\n\",ptr[i]);\n}\n ptr struct dog ptr struct dog int name struct dog frodo ptr name struct dog ptr int name struct dog frodo int * ptr = frodo.name;\n name int frodo.name int name struct dog frodo int name int ptr ptr char frodo.name int char &frodo.name[0] int int frodo.name int frodo.name int int frodo.name &frodo.name frodo.name int #include <stdio.h>\n\nstruct dog\n{\n int name[10];\n char breed[10];\n int age;\n char color[10];\n};\n\nint main()\n{\nstruct dog frodo;\nint *ptr= frodo.name;\n\nfor(int i=0;i<10;i++)\nfrodo.name[i]=i;\n\nfor(int i=0;i<10;i++)\nprintf(\" frodo.name[%d]%d\\n\",i,frodo.name[i]);\n\nfor(int i=0;i<10;i++)\nprintf(\" ptr =%d\\n\",ptr[i]);\n}\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656291",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20585881/"
] |
74,656,297
|
<p>I am very new to SQL. I have three tables, transactions, products, and customers. I want to know how many products have been sold with profit.</p>
<pre><code>SELECT t.product_id, p.id, sum(t.total_price / t.quantity) - p.price As profit
From transactions as t , products As p
INNER JOIN transactions
on t.product_id = p.id
GROUP by t.product_id
</code></pre>
<p>I have only a total price column in my transactions table. Should I divide total_price to quantity or * ? How about my all query?</p>
|
[
{
"answer_id": 74656632,
"author": "Javohir Xoldorov",
"author_id": 16870814,
"author_profile": "https://Stackoverflow.com/users/16870814",
"pm_score": 0,
"selected": false,
"text": "SELECT t.product_id,sum(t.total_price / t.quantity - p.price) as profit\n FROM transactions as t\n INNER JOIN product as p on t.id = p.id\n GROUP by t.product_id\n order by t.product_id\n"
},
{
"answer_id": 74656717,
"author": "Javohir Xoldorov",
"author_id": 16870814,
"author_profile": "https://Stackoverflow.com/users/16870814",
"pm_score": -1,
"selected": false,
"text": "SELECT t.product_id,sum(t.total_price / t.quantity - p.price) as profit, \n count(t.quantity) as sold_count\n FROM transactions as t\n INNER JOIN product as p on t.id = p.id\n GROUP by t.product_id\n order by t.product_id \n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656297",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19198536/"
] |
74,656,303
|
<p>Despite the number of similar questions on Stackoverflow, I can't come up with a solution for the following Producer-Consumer problem:</p>
<p>My program has three threads:</p>
<ul>
<li><p><em>One writer thread</em> that reads from a file, saves data into a <code>sensor_data_t</code> struct, and <strong>writes it into a dynamic pointer-based buffer using</strong> <code>sbuffer_insert(buffer, &sensor_data)</code>. Once this thread finishes reading it sends an end-of-stream data struct represented by <code>data->id == 0</code>.</p>
</li>
<li><p><em>Two reader threads</em> that remove data from the buffer head (FIFO-style), and store it into a temporary data struct using <code>sbuffer_remove(buffer, &data)</code> and then print it to the cmd line for testing purposes.</p>
</li>
</ul>
<p>I think I have to avoid at the least:</p>
<ol>
<li>My reader threads to try to consume/remove from the buffer while it is empty.</li>
<li>My reader threads to consume/remove from the buffer at the same time.</li>
</ol>
<p>On the other hand, I don't think my writer thread in <code>sbuffer_insert()</code> needs to worry if the readers are changing the <code>head</code> because it only appends to the <code>tail</code>. <strong>Is this reasoning correct or am I missing something?</strong></p>
<p>Here's what I've done so far:</p>
<p>My main function:</p>
<pre><code>sbuffer_t *buffer;
void *writer(void *fp);
void *reader(void *fp);
int main()
{
// Initialize the buffer
sbuffer_init(&buffer);
// Open sensor_data file
FILE *sensor_data_fp;
sensor_data_fp = fopen("sensor_data", "rb");
// Start thread for reading sensor_data file adding elements to the sbuffer
pthread_t writer_thread;
pthread_create(&writer_thread, NULL, &writer, sensor_data_fp);
// Open sensor_data_out file
FILE *sensor_data_out_fp;
sensor_data_out_fp = fopen("sensor_data_out", "w");
// Start thread 1 and 2 for writing sensor_data_out file
pthread_t reader_thread1;
pthread_t reader_thread2;
pthread_create(&reader_thread1, NULL, &reader, sensor_data_out_fp);
pthread_create(&reader_thread2, NULL, &reader, sensor_data_out_fp);
// Wait for threads to finish and join them
pthread_join(reader_thread1, NULL);
pthread_join(reader_thread2, NULL);
pthread_join(writer_thread, NULL);
// Close sensor_data file
fclose(sensor_data_fp);
// Close sensor_data_out file
fclose(sensor_data_out_fp);
// free buffer
sbuffer_free(&buffer);
return 0;
}
</code></pre>
<p>My reader and writer threads:</p>
<pre><code>typedef uint16_t sensor_id_t;
typedef double sensor_value_t;
typedef time_t sensor_ts_t; // UTC timestamp as returned by time() - notice that the size of time_t is different on 32/64 bit machine
typedef struct {
sensor_id_t id;
sensor_value_t value;
sensor_ts_t ts;
} sensor_data_t;
void *writer(void *fp)
{
// cast fp to FILE
FILE *sensor_data_fp = (FILE *)fp;
// make char buffers of size sensor_id_t, sensor_value_t and sensor_ts_t
char sensor_id_buffer[sizeof(sensor_id_t)];
char sensor_value_buffer[sizeof(sensor_value_t)];
char sensor_ts_buffer[sizeof(sensor_ts_t)];
// parse sensor_data file into sensor_id_buffer, sensor_value_buffer and sensor_ts_buffer
while(fread(sensor_id_buffer, sizeof(sensor_id_t), 1, sensor_data_fp) == 1 &&
fread(sensor_value_buffer, sizeof(sensor_value_t), 1, sensor_data_fp) == 1 &&
fread(sensor_ts_buffer, sizeof(sensor_ts_t), 1, sensor_data_fp)) {
// create sensor_data_t
sensor_data_t sensor_data;
// copy sensor_id_buffer to sensor_data.id
memcpy(&sensor_data.id, sensor_id_buffer, sizeof(sensor_id_t));
// copy sensor_value_buffer to sensor_data.value
memcpy(&sensor_data.value, sensor_value_buffer, sizeof(sensor_value_t));
// copy sensor_ts_buffer to sensor_data.ts
memcpy(&sensor_data.ts, sensor_ts_buffer, sizeof(sensor_ts_t));
// print sensor_data for testing
// printf("sensor_data.id: %d, sensor_data.value: %f, sensor_data.ts: %ld\n", sensor_data.id, sensor_data.value, sensor_data.ts);
// insert sensor_data into buffer
sbuffer_insert(buffer, &sensor_data);
}
// Add dummy data to buffer to signal end of file
sensor_data_t sensor_data;
sensor_data.id = 0;
sensor_data.value = 0;
sensor_data.ts = 0;
sbuffer_insert(buffer, &sensor_data);
return NULL;
}
void *reader(void *fp)
{
// cast fp to FILE
//FILE *sensor_data_out_fp = (FILE *)fp;
// Init data as sensor_data_t
sensor_data_t data;
do{
// read data from buffer
if (sbuffer_remove(buffer, &data) == 0) { // SBUFFER_SUCCESS 0
// write data to sensor_data_out file
// fwrite(&data, sizeof(sensor_data_t), 1, sensor_data_out_fp);
// print data for testing
printf("data.id: %d, data.value: %f, data.ts: %ld \n", data.id, data.value, data.ts);
}
}
while(data.id != 0);
// free allocated memory
// free(fp);
return NULL;
}
</code></pre>
<p>Global variables and buffer initialization:</p>
<pre><code>typedef struct sbuffer_node {
struct sbuffer_node *next;
sensor_data_t data;
} sbuffer_node_t;
struct sbuffer {
sbuffer_node_t *head;
sbuffer_node_t *tail;
};
pthread_mutex_t mutex;
pthread_cond_t empty, removing;
int count = 0; // reader count
int sbuffer_init(sbuffer_t **buffer) {
*buffer = malloc(sizeof(sbuffer_t));
if (*buffer == NULL) return SBUFFER_FAILURE;
(*buffer)->head = NULL;
(*buffer)->tail = NULL;
// Initialize mutex and condition variables
pthread_mutex_init(&mutex, NULL);
pthread_cond_init(&empty, NULL);
pthread_cond_init(&removing, NULL);
return SBUFFER_SUCCESS;
}
</code></pre>
<p><code>sbuffer_remove</code> (Consumer)</p>
<pre><code>int sbuffer_remove(sbuffer_t *buffer, sensor_data_t *data) {
sbuffer_node_t *dummy;
if (buffer == NULL) return SBUFFER_FAILURE;
// while the count is 0, wait
pthread_mutex_lock(&mutex);
while (count > 0) {
pthread_cond_wait(&removing, &mutex);
}
pthread_mutex_unlock(&mutex);
pthread_mutex_lock(&mutex);
while (buffer->head == NULL){
pthread_cond_wait(&empty, &mutex); // Wait until buffer is not empty
if (data->id == 0){ // end-of-stream
pthread_mutex_unlock(&mutex);
return SBUFFER_NO_DATA;
}
}
count++;
*data = buffer->head->data;
dummy = buffer->head;
if (buffer->head == buffer->tail) // buffer has only one node
{
buffer->head = buffer->tail = NULL;
} else // buffer has many nodes empty
{
buffer->head = buffer->head->next;
}
free(dummy);
count--;
pthread_cond_signal(&removing); // Signal that data is removed
pthread_mutex_unlock(&mutex);
return SBUFFER_SUCCESS;
}
</code></pre>
<p><code>sbuffer_insert</code> (Producer)</p>
<pre><code>int sbuffer_insert(sbuffer_t *buffer, sensor_data_t *data) {
sbuffer_node_t *dummy;
if (buffer == NULL) return SBUFFER_FAILURE;
dummy = malloc(sizeof(sbuffer_node_t));
if (dummy == NULL) return SBUFFER_FAILURE;
dummy->data = *data;
dummy->next = NULL;
if (buffer->tail == NULL) // buffer empty (buffer->head should also be NULL
{
pthread_mutex_lock(&mutex);
buffer->head = buffer->tail = dummy;
pthread_cond_signal(&empty); // Signal that buffer is not empty
pthread_mutex_unlock(&mutex);
} else // buffer not empty
{
buffer->tail->next = dummy;
buffer->tail = buffer->tail->next;
}
return SBUFFER_SUCCESS;
}
</code></pre>
<p>Currently, the code has very unstable behavior. Sometimes it runs and prints everything, sometimes it doesn't print anything and gets stuck in a loop, sometimes it prints everything but the last value comes after the end-of-stream code and it doesn't terminate.</p>
<p>I would really appreciate a solution that explains what I'm doing wrong or a comment that redirects me to a duplicate of my question.</p>
|
[
{
"answer_id": 74656632,
"author": "Javohir Xoldorov",
"author_id": 16870814,
"author_profile": "https://Stackoverflow.com/users/16870814",
"pm_score": 0,
"selected": false,
"text": "SELECT t.product_id,sum(t.total_price / t.quantity - p.price) as profit\n FROM transactions as t\n INNER JOIN product as p on t.id = p.id\n GROUP by t.product_id\n order by t.product_id\n"
},
{
"answer_id": 74656717,
"author": "Javohir Xoldorov",
"author_id": 16870814,
"author_profile": "https://Stackoverflow.com/users/16870814",
"pm_score": -1,
"selected": false,
"text": "SELECT t.product_id,sum(t.total_price / t.quantity - p.price) as profit, \n count(t.quantity) as sold_count\n FROM transactions as t\n INNER JOIN product as p on t.id = p.id\n GROUP by t.product_id\n order by t.product_id \n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656303",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11206079/"
] |
74,656,346
|
<p>For readability purposes, I want to extract the NavigationBar composable in another function. Same with PreviousButton. Therefore I want to pass the mutableState of index to a these functions. But passing index as a parameter does not work, because I cannot update the state. What can I do?</p>
<pre><code>@Composable
fun MyChickensScreen(){
val art: List<Art> = Datasource().loadArt()
var index: Int by remember { mutableStateOf(0) }
// IDE suggests making index a val,
// but I want to update the state in another composable.
//...
NavigationBar(index = index)
}
}
//NavigationBar passes index to the PreviousButton Composable
@Composable
private fun PreviousButton(index: Int) {
Button(
onClick = { index = handlePrevClick(index) }, //Error: Val cannot be reassigned for index
) {
//...
}
}
</code></pre>
|
[
{
"answer_id": 74656632,
"author": "Javohir Xoldorov",
"author_id": 16870814,
"author_profile": "https://Stackoverflow.com/users/16870814",
"pm_score": 0,
"selected": false,
"text": "SELECT t.product_id,sum(t.total_price / t.quantity - p.price) as profit\n FROM transactions as t\n INNER JOIN product as p on t.id = p.id\n GROUP by t.product_id\n order by t.product_id\n"
},
{
"answer_id": 74656717,
"author": "Javohir Xoldorov",
"author_id": 16870814,
"author_profile": "https://Stackoverflow.com/users/16870814",
"pm_score": -1,
"selected": false,
"text": "SELECT t.product_id,sum(t.total_price / t.quantity - p.price) as profit, \n count(t.quantity) as sold_count\n FROM transactions as t\n INNER JOIN product as p on t.id = p.id\n GROUP by t.product_id\n order by t.product_id \n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656346",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11120671/"
] |
74,656,353
|
<p>I am struggling with window functions in SQL Server. I have a table that is tracking how many records were transferred. I wrote a query to sum how many rows are transferred for each parameter. However, at some point records had to be resend (they were dropped from the final location and resend). So, if I continue with my old query, I get duplicated values.</p>
<p>This is an example table:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: left;">parameter</th>
<th style="text-align: left;">rows</th>
<th style="text-align: left;">min_id</th>
<th style="text-align: left;">max_id</th>
<th style="text-align: left;">create_date</th>
<th style="text-align: left;">status</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">A1</td>
<td style="text-align: left;">48</td>
<td style="text-align: left;">350</td>
<td style="text-align: left;">521</td>
<td style="text-align: left;">06.11.2022</td>
<td style="text-align: left;">sent</td>
</tr>
<tr>
<td style="text-align: left;">A1</td>
<td style="text-align: left;">48</td>
<td style="text-align: left;">350</td>
<td style="text-align: left;">521</td>
<td style="text-align: left;">06.11.2022</td>
<td style="text-align: left;">error</td>
</tr>
<tr>
<td style="text-align: left;">A1</td>
<td style="text-align: left;">78</td>
<td style="text-align: left;">1</td>
<td style="text-align: left;">350</td>
<td style="text-align: left;">05.11.2022</td>
<td style="text-align: left;">sent</td>
</tr>
<tr>
<td style="text-align: left;">A1</td>
<td style="text-align: left;">13</td>
<td style="text-align: left;">299</td>
<td style="text-align: left;">350</td>
<td style="text-align: left;">04.11.2022</td>
<td style="text-align: left;">sent</td>
</tr>
<tr>
<td style="text-align: left;">A1</td>
<td style="text-align: left;">50</td>
<td style="text-align: left;">100</td>
<td style="text-align: left;">299</td>
<td style="text-align: left;">03.11.2022</td>
<td style="text-align: left;">sent</td>
</tr>
<tr>
<td style="text-align: left;">A1</td>
<td style="text-align: left;">15</td>
<td style="text-align: left;">1</td>
<td style="text-align: left;">100</td>
<td style="text-align: left;">01.11.2022</td>
<td style="text-align: left;">sent</td>
</tr>
<tr>
<td style="text-align: left;">B2</td>
<td style="text-align: left;">87</td>
<td style="text-align: left;">800</td>
<td style="text-align: left;">1202</td>
<td style="text-align: left;">07.11.2022</td>
<td style="text-align: left;">sent</td>
</tr>
<tr>
<td style="text-align: left;">B2</td>
<td style="text-align: left;">187</td>
<td style="text-align: left;">1</td>
<td style="text-align: left;">800</td>
<td style="text-align: left;">06.11.2022</td>
<td style="text-align: left;">sent</td>
</tr>
<tr>
<td style="text-align: left;">B2</td>
<td style="text-align: left;">12</td>
<td style="text-align: left;">570</td>
<td style="text-align: left;">800</td>
<td style="text-align: left;">04.11.2022</td>
<td style="text-align: left;">sent</td>
</tr>
<tr>
<td style="text-align: left;">B2</td>
<td style="text-align: left;">120</td>
<td style="text-align: left;">320</td>
<td style="text-align: left;">570</td>
<td style="text-align: left;">03.11.2022</td>
<td style="text-align: left;">sent</td>
</tr>
<tr>
<td style="text-align: left;">B2</td>
<td style="text-align: left;">55</td>
<td style="text-align: left;">1</td>
<td style="text-align: left;">320</td>
<td style="text-align: left;">01.11.2022</td>
<td style="text-align: left;">sent</td>
</tr>
</tbody>
</table>
</div>
<p>You can understand when the table was resend when min_id is 1 again.</p>
<p>The result I want to achieve is:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: left;">parameter</th>
<th style="text-align: left;">sum</th>
<th style="text-align: left;">min_id</th>
<th style="text-align: left;">max_id</th>
<th style="text-align: left;">max_date</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">A1</td>
<td style="text-align: left;">126</td>
<td style="text-align: left;">1</td>
<td style="text-align: left;">521</td>
<td style="text-align: left;">06.11.2022</td>
</tr>
<tr>
<td style="text-align: left;">B2</td>
<td style="text-align: left;">274</td>
<td style="text-align: left;">1</td>
<td style="text-align: left;">1202</td>
<td style="text-align: left;">07.11.2022</td>
</tr>
</tbody>
</table>
</div>
<p>What I was able to do so far (but is causing duplicate results):</p>
<pre><code>SELECT * FROM
(SELECT
parameter
, sum(rows) over (partition by parameter) as sum
, min_id
, max_id
, MAX(create_date) over (partition by parameter) as max_date
FROM my_table) as s
WHERE create_date = max_date and status = 'sent'
</code></pre>
<p>I think that maybe one more window function (nested window function?) needs to be added that will make a certain range of partitions starting with min_id=1 having the latest create_date. However, I failed to do so. Could anyone advise on how to approach this?</p>
|
[
{
"answer_id": 74656601,
"author": "Giridhar R",
"author_id": 20666700,
"author_profile": "https://Stackoverflow.com/users/20666700",
"pm_score": 0,
"selected": false,
"text": "SELECT\n parameter, \n SUM(rows) AS rows, \n MIN(min_id) AS min_id,\n MAX(max_id) AS max_id,\n MAX(create_date) AS max_date \nFROM my_table\nWHERE status = 'sent'\nGROUP BY parameter\n"
},
{
"answer_id": 74662811,
"author": "JJ32",
"author_id": 5592955,
"author_profile": "https://Stackoverflow.com/users/5592955",
"pm_score": 2,
"selected": true,
"text": "SELECT parameter, sum(rows) as sum, min(min_id) as min_id, max(max_id) as max_id,\n max(create_date) as max_date\nFROM\n (SELECT \n parameter\n , rows\n , min_id\n , max_id\n , create_date\n , status\n , MAX(case when min_id = 1 then create_date end) over (partition by parameter) as sent_start\n FROM my_table) as s\nWHERE create_date >= sent_start and status = 'sent'\nGROUP BY parameter\n ;WITH SentRows as\n(\nSELECT *\nFROM my_table\nWHERE status='sent'\n)\n\nSELECT parameter, sum(rows) as sum, min(min_id) as min_id, max(max_id) as max_id,\n max(create_date) as max_date \nFROM SentRows as s\nWHERE NOT EXISTS\n (SELECT 1 FROM SentRows t WHERE t.parameter = s.parameter AND t.create_date > s.create_date \n AND t.min_id <= s.min_id AND t.max_id >= s.max_id)\nGROUP BY parameter\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656353",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17159874/"
] |
74,656,377
|
<p>I have code in postgresql transform to sql server
In postgresql while inserting in table with data type timestamp with time zone in UTC format, it inserted with time zone</p>
<pre><code>create table public.testt123 (tz timestamp with time zone)
insert into public.testt123
select now() at time zone 'utc'
select * from public.testt123
</code></pre>
<p><a href="https://i.stack.imgur.com/AyAQc.png" rel="nofollow noreferrer">enter image description here</a></p>
<p>I have tried same with Sql server, below query</p>
<pre><code>create table Test1(tz [datetimeoffset](7))
insert into Test1
select GETUTCDATE() AT TIME ZONE 'UTC'
</code></pre>
<p><a href="https://i.stack.imgur.com/JRRBM.png" rel="nofollow noreferrer">enter image description here</a></p>
<p>It inserted without time zone, I have check using SYSDATETIMEOFFSET() but it gives time zone with current datetime not UTC</p>
<p>I have tried by left function, but it is correct way?</p>
<pre><code>Select cast(left(SYSDATETIMEOFFSET() AT TIME ZONE 'UTC',28) + DATENAME(TZOFFSET, SYSDATETIMEOFFSET()) as [datetimeoffset](7))
</code></pre>
<p><a href="https://i.stack.imgur.com/Jj2VZ.png" rel="nofollow noreferrer">enter image description here</a></p>
|
[
{
"answer_id": 74656466,
"author": "Dan Guzman",
"author_id": 3711162,
"author_profile": "https://Stackoverflow.com/users/3711162",
"pm_score": 0,
"selected": false,
"text": "SYSDATETIMEOFFSET() datetimeoffset AT TIME ZONE 'UTC' datetimeoffset SYSDATETIMEOFFSET() AT TIME ZONE 'UTC'\n"
},
{
"answer_id": 74656596,
"author": "Larnu",
"author_id": 2029983,
"author_profile": "https://Stackoverflow.com/users/2029983",
"pm_score": 1,
"selected": false,
"text": "SELECT SYSUTCDATETIME() AT TIME ZONE 'UTC' AT TIME ZONE 'India Standard Time';\n SELECT SYSDATETIMEOFFSET() AT TIME ZONE 'India Standard Time';\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656377",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20666592/"
] |
74,656,407
|
<p>Is it possible to make a conditional that does not check part of the string when is not needed?</p>
<p>For example:</p>
<p>Regex:
<code>^[a-zA-Z]+.*#[0-9]+$</code></p>
<p>Example text:
<code>feature: My name is Oliver #9123</code></p>
<p>I would like to when the text being:</p>
<p><code>release: My name is oliver</code></p>
<p>The same Regex matches both cases not requiring the #9123 for the release prefix, is that possible?</p>
<p>I have tried to use some regex conditionals that I found on google, but didn't have success.</p>
|
[
{
"answer_id": 74656476,
"author": "Carsten Massmann",
"author_id": 2610061,
"author_profile": "https://Stackoverflow.com/users/2610061",
"pm_score": 1,
"selected": true,
"text": "| const tests=[\"My name is Oliver #9123\",\n \"release: My name is oliver\",\n \"this should fail\",\n \"#12345 another fail\"];\n\ntests.forEach(str=>\n console.log(str+\" - \"+(str.match(/^release|[a-zA-Z]+.*#[0-9]+/)?\"pass\":\"fail\"))\n)"
},
{
"answer_id": 74656537,
"author": "igobr",
"author_id": 20085654,
"author_profile": "https://Stackoverflow.com/users/20085654",
"pm_score": 1,
"selected": false,
"text": "^[a-zA-Z\\s]+(#[0-9]+)?$\n \"My name is Oliver #9123\"\n\"My name is Oliver\"\n \"This is not valid #xxx\"\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656407",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18484082/"
] |
74,656,455
|
<p>I want to concatenate all 2 dimensional values in a dictionary.</p>
<p>The number of rows of these values is always the same.</p>
<pre class="lang-py prettyprint-override"><code>D = {'a': [[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]],
'b': [[1, 1],
[1, 1],
[1, 1]],
'c': [[2, 2, 2, 2],
[2, 2, 2, 2],
[2, 2, 2, 2]]
}
</code></pre>
<p>And the output must be form of a torch tensor.</p>
<pre class="lang-py prettyprint-override"><code>tensor([[0, 0, 0, 0, 0, 1, 1, 2, 2, 2, 2],
[0, 0, 0, 0, 0, 1, 1, 2, 2, 2, 2],
[0, 0, 0, 0, 0, 1, 1, 2, 2, 2, 2]])
</code></pre>
<p>Any help would be appreciated!!</p>
|
[
{
"answer_id": 74656609,
"author": "Will",
"author_id": 12829151,
"author_profile": "https://Stackoverflow.com/users/12829151",
"pm_score": 0,
"selected": false,
"text": "from itertools import chain \nl = []\nfor i in range(len(D)):\n t = [ D[k][i] for k in D ] \n l.append( list(chain.from_iterable(t)) )\n [[0, 0, 0, 0, 0, 1, 1, 2, 2, 2, 2],\n [0, 0, 0, 0, 0, 1, 1, 2, 2, 2, 2],\n [0, 0, 0, 0, 0, 1, 1, 2, 2, 2, 2]]\n"
},
{
"answer_id": 74657698,
"author": "core_not_dumped",
"author_id": 19106705,
"author_profile": "https://Stackoverflow.com/users/19106705",
"pm_score": 1,
"selected": false,
"text": "import torch\nprint(torch.cat(tuple([torch.tensor(D[name]) for name in D.keys()]), dim=1))\n tensor([[0, 0, 0, 0, 0, 1, 1, 2, 2, 2, 2],\n [0, 0, 0, 0, 0, 1, 1, 2, 2, 2, 2],\n [0, 0, 0, 0, 0, 1, 1, 2, 2, 2, 2]])\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656455",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19106705/"
] |
74,656,498
|
<p>I have input like this. I tried some solutions. But it doesn't work. I need to merge same <code>invoice_nr</code> objects to one array. Also I need other objects another array. All arrays must be another array.</p>
<pre><code>const result = [
{
invoice_nr: 16,
order_id: 5577,
color: 'red'
},
{
invoice_nr: 16,
order_id: 5577,
color: 'yellow'
},
{
invoice_nr: 17,
order_id: 5574,
color: 'green'
},
{
invoice_nr: 18,
order_id: 5578,
color: 'yellow'
},
{
invoice_nr: 18,
order_id: 5578,
color: 'blue'
}
];
</code></pre>
<p>But, I need output like this. How can I achieve that in javascript?
Array must be like this.</p>
<pre><code>const result = [
[
{
invoice_nr: 16,
order_id: 5577,
color: 'red'
},
{
invoice_nr: 16,
order_id: 5577,
color: 'yellow'
}
],
[
{
invoice_nr: 17,
order_id: 5574,
color: 'green'
}
],
[
{
invoice_nr: 18,
order_id: 5578,
color: 'yellow'
},
{
invoice_nr: 18,
order_id: 5578,
color: 'blue'
}
]
];
</code></pre>
|
[
{
"answer_id": 74656585,
"author": "Asraf",
"author_id": 20361860,
"author_profile": "https://Stackoverflow.com/users/20361860",
"pm_score": 2,
"selected": false,
"text": ".reduce() invoice_nr const result = [ { invoice_nr: 16, order_id: 5577, color: 'red' }, { invoice_nr: 16, order_id: 5577, color: 'yellow' }, { invoice_nr: 17, order_id: 5574, color: 'green' }, { invoice_nr: 18, order_id: 5578, color: 'yellow' }, { invoice_nr: 18, order_id: 5578, color: 'blue' } ];\n\nconst res = result.reduce((a,b) => ((a[b.invoice_nr] ??= []).push(b),a),{});\nconsole.log(Object.values(res)); .as-console-wrapper { max-height: 100% !important }"
},
{
"answer_id": 74656701,
"author": "gureenkov56",
"author_id": 18470572,
"author_profile": "https://Stackoverflow.com/users/18470572",
"pm_score": 0,
"selected": false,
"text": "const result = [\n {\n invoice_nr: 16,\n order_id: 5577,\n color: 'red'\n },\n {\n invoice_nr: 16,\n order_id: 5577,\n color: 'yellow'\n },\n {\n invoice_nr: 17,\n order_id: 5574,\n color: 'green'\n },\n {\n invoice_nr: 18,\n order_id: 5578,\n color: 'yellow'\n },\n {\n invoice_nr: 18,\n order_id: 5578,\n color: 'blue'\n }\n];\n\nlet uniq = [];\nlet res = [];\n// get unique ID\nresult.forEach(i => !uniq.includes(i.invoice_nr) ? uniq.push(i.invoice_nr) : '' );\n// filter by ID\nuniq.forEach(id => {\n res.push(result.filter(o => o.invoice_nr === id))\n})\n// that you need in res\nconsole.log(res);"
},
{
"answer_id": 74657083,
"author": "Trevor Dixon",
"author_id": 711902,
"author_profile": "https://Stackoverflow.com/users/711902",
"pm_score": 0,
"selected": false,
"text": "result.reduce((arr, item) => {\n const group = arr.at(-1), prevItem = group?.at(-1);\n if (prevItem?.invoice_nr === item.invoice_nr) {\n group.push(item);\n } else {\n arr.push([item]);\n }\n return arr;\n}, []);\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656498",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15863302/"
] |
74,656,532
|
<p>I want to add a newline to the last element of an array
I have tried this:</p>
<pre><code>$array[-1] .= "\n";
</code></pre>
<p>but I get the following error message:</p>
<pre><code>Modification of non-creatable array value attempted, subscript -1
</code></pre>
<p>I have tried a few other methods as well (without <code>.=</code>), without success.
Should I try <code>splice</code>?</p>
<p>example of what i want :</p>
<pre><code>@array = (
"one",
"two",
"n",
"last\n", # i want the newline to be added here
);
</code></pre>
|
[
{
"answer_id": 74656585,
"author": "Asraf",
"author_id": 20361860,
"author_profile": "https://Stackoverflow.com/users/20361860",
"pm_score": 2,
"selected": false,
"text": ".reduce() invoice_nr const result = [ { invoice_nr: 16, order_id: 5577, color: 'red' }, { invoice_nr: 16, order_id: 5577, color: 'yellow' }, { invoice_nr: 17, order_id: 5574, color: 'green' }, { invoice_nr: 18, order_id: 5578, color: 'yellow' }, { invoice_nr: 18, order_id: 5578, color: 'blue' } ];\n\nconst res = result.reduce((a,b) => ((a[b.invoice_nr] ??= []).push(b),a),{});\nconsole.log(Object.values(res)); .as-console-wrapper { max-height: 100% !important }"
},
{
"answer_id": 74656701,
"author": "gureenkov56",
"author_id": 18470572,
"author_profile": "https://Stackoverflow.com/users/18470572",
"pm_score": 0,
"selected": false,
"text": "const result = [\n {\n invoice_nr: 16,\n order_id: 5577,\n color: 'red'\n },\n {\n invoice_nr: 16,\n order_id: 5577,\n color: 'yellow'\n },\n {\n invoice_nr: 17,\n order_id: 5574,\n color: 'green'\n },\n {\n invoice_nr: 18,\n order_id: 5578,\n color: 'yellow'\n },\n {\n invoice_nr: 18,\n order_id: 5578,\n color: 'blue'\n }\n];\n\nlet uniq = [];\nlet res = [];\n// get unique ID\nresult.forEach(i => !uniq.includes(i.invoice_nr) ? uniq.push(i.invoice_nr) : '' );\n// filter by ID\nuniq.forEach(id => {\n res.push(result.filter(o => o.invoice_nr === id))\n})\n// that you need in res\nconsole.log(res);"
},
{
"answer_id": 74657083,
"author": "Trevor Dixon",
"author_id": 711902,
"author_profile": "https://Stackoverflow.com/users/711902",
"pm_score": 0,
"selected": false,
"text": "result.reduce((arr, item) => {\n const group = arr.at(-1), prevItem = group?.at(-1);\n if (prevItem?.invoice_nr === item.invoice_nr) {\n group.push(item);\n } else {\n arr.push([item]);\n }\n return arr;\n}, []);\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656532",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4279387/"
] |
74,656,689
|
<p>Hello so I've been trying to solve this problem but cant find anything I tried dictionaries and exec. How can I use string value as a variable name? I have a problem when I define a variable name in a string and try to make a button with the image it shows error - _tkinter.TclError: image "score6" doesn't exist, but if I manually type in the image variable name the error doesn't show.</p>
<pre><code> img = 'score' + str(correct) #here I make the variable name #the scores can be from 0-9
self.rez = Button(window, relief="sunken", image=img, bd=0, bg='#cecece',activebackground='#cecece')
self.rez.place(x=520, y=330)
</code></pre>
<p>#this is where images are defined(this is outside the class)</p>
<pre><code>score0 = ImageTk.PhotoImage(Image.open("scores/09.png"))
score1 = ImageTk.PhotoImage(Image.open("scores/19.png"))
score2 = ImageTk.PhotoImage(Image.open("scores/29.png"))
score3 = ImageTk.PhotoImage(Image.open("scores/39.png"))
score4 = ImageTk.PhotoImage(Image.open("scores/49.png"))
score5 = ImageTk.PhotoImage(Image.open("scores/59.png"))
</code></pre>
<p><code>so how can I use string value as a variable name?</code></p>
|
[
{
"answer_id": 74656585,
"author": "Asraf",
"author_id": 20361860,
"author_profile": "https://Stackoverflow.com/users/20361860",
"pm_score": 2,
"selected": false,
"text": ".reduce() invoice_nr const result = [ { invoice_nr: 16, order_id: 5577, color: 'red' }, { invoice_nr: 16, order_id: 5577, color: 'yellow' }, { invoice_nr: 17, order_id: 5574, color: 'green' }, { invoice_nr: 18, order_id: 5578, color: 'yellow' }, { invoice_nr: 18, order_id: 5578, color: 'blue' } ];\n\nconst res = result.reduce((a,b) => ((a[b.invoice_nr] ??= []).push(b),a),{});\nconsole.log(Object.values(res)); .as-console-wrapper { max-height: 100% !important }"
},
{
"answer_id": 74656701,
"author": "gureenkov56",
"author_id": 18470572,
"author_profile": "https://Stackoverflow.com/users/18470572",
"pm_score": 0,
"selected": false,
"text": "const result = [\n {\n invoice_nr: 16,\n order_id: 5577,\n color: 'red'\n },\n {\n invoice_nr: 16,\n order_id: 5577,\n color: 'yellow'\n },\n {\n invoice_nr: 17,\n order_id: 5574,\n color: 'green'\n },\n {\n invoice_nr: 18,\n order_id: 5578,\n color: 'yellow'\n },\n {\n invoice_nr: 18,\n order_id: 5578,\n color: 'blue'\n }\n];\n\nlet uniq = [];\nlet res = [];\n// get unique ID\nresult.forEach(i => !uniq.includes(i.invoice_nr) ? uniq.push(i.invoice_nr) : '' );\n// filter by ID\nuniq.forEach(id => {\n res.push(result.filter(o => o.invoice_nr === id))\n})\n// that you need in res\nconsole.log(res);"
},
{
"answer_id": 74657083,
"author": "Trevor Dixon",
"author_id": 711902,
"author_profile": "https://Stackoverflow.com/users/711902",
"pm_score": 0,
"selected": false,
"text": "result.reduce((arr, item) => {\n const group = arr.at(-1), prevItem = group?.at(-1);\n if (prevItem?.invoice_nr === item.invoice_nr) {\n group.push(item);\n } else {\n arr.push([item]);\n }\n return arr;\n}, []);\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656689",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19164904/"
] |
74,656,745
|
<p>I am solving a pattern problem in python, i need to print a pattern in such a way it consists of <code>X</code> and the numbers are filled first in increasing order and then after reaching mid number, they go to decreasing order,</p>
<p>basically i did what, i find out the area where the <code>X</code> will display.,and fill the remaining matrix with blank spaces..,</p>
<p>but it is not according to my pattern..</p>
<p><a href="https://i.stack.imgur.com/9RDIV.png" rel="nofollow noreferrer">Output Pattern image</a></p>
<p>here is my approach:</p>
<pre><code>n=int(input("Enter total rows"))
#n=5
for rows in range(n):
for cols in range(n):
if((rows == cols) or (rows+cols)==n-1 ):
print(rows,end="")
else:
print(" ",end="")
print()
</code></pre>
<p>what i am trying to do is:
<code>left diagonal and Right diagonal numbers</code> :<code>0 1 2 1 0</code>
but what i am getting is:
<code>left diagonal and Right diagonal numbers</code> :<code>0 1 2 3 4</code></p>
|
[
{
"answer_id": 74656585,
"author": "Asraf",
"author_id": 20361860,
"author_profile": "https://Stackoverflow.com/users/20361860",
"pm_score": 2,
"selected": false,
"text": ".reduce() invoice_nr const result = [ { invoice_nr: 16, order_id: 5577, color: 'red' }, { invoice_nr: 16, order_id: 5577, color: 'yellow' }, { invoice_nr: 17, order_id: 5574, color: 'green' }, { invoice_nr: 18, order_id: 5578, color: 'yellow' }, { invoice_nr: 18, order_id: 5578, color: 'blue' } ];\n\nconst res = result.reduce((a,b) => ((a[b.invoice_nr] ??= []).push(b),a),{});\nconsole.log(Object.values(res)); .as-console-wrapper { max-height: 100% !important }"
},
{
"answer_id": 74656701,
"author": "gureenkov56",
"author_id": 18470572,
"author_profile": "https://Stackoverflow.com/users/18470572",
"pm_score": 0,
"selected": false,
"text": "const result = [\n {\n invoice_nr: 16,\n order_id: 5577,\n color: 'red'\n },\n {\n invoice_nr: 16,\n order_id: 5577,\n color: 'yellow'\n },\n {\n invoice_nr: 17,\n order_id: 5574,\n color: 'green'\n },\n {\n invoice_nr: 18,\n order_id: 5578,\n color: 'yellow'\n },\n {\n invoice_nr: 18,\n order_id: 5578,\n color: 'blue'\n }\n];\n\nlet uniq = [];\nlet res = [];\n// get unique ID\nresult.forEach(i => !uniq.includes(i.invoice_nr) ? uniq.push(i.invoice_nr) : '' );\n// filter by ID\nuniq.forEach(id => {\n res.push(result.filter(o => o.invoice_nr === id))\n})\n// that you need in res\nconsole.log(res);"
},
{
"answer_id": 74657083,
"author": "Trevor Dixon",
"author_id": 711902,
"author_profile": "https://Stackoverflow.com/users/711902",
"pm_score": 0,
"selected": false,
"text": "result.reduce((arr, item) => {\n const group = arr.at(-1), prevItem = group?.at(-1);\n if (prevItem?.invoice_nr === item.invoice_nr) {\n group.push(item);\n } else {\n arr.push([item]);\n }\n return arr;\n}, []);\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656745",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20666897/"
] |
74,656,777
|
<p>I'm trying to remove outliers from a dataset, where an outlier is if the difference between one item and the next one is larger than 3 * the uncertainty on the item</p>
<pre><code>def remove_outliers(data):
for i in data:
x = np.where(abs(i[1] - (i+1)[1]) > 3( * data[:,2]))
data_outliers_removed = np.delete(data, x, axis =1)
return data_outliers_removed
</code></pre>
<p>is the function which I tried to use, however it either deletes no values or all values when I've played around with it.</p>
|
[
{
"answer_id": 74656585,
"author": "Asraf",
"author_id": 20361860,
"author_profile": "https://Stackoverflow.com/users/20361860",
"pm_score": 2,
"selected": false,
"text": ".reduce() invoice_nr const result = [ { invoice_nr: 16, order_id: 5577, color: 'red' }, { invoice_nr: 16, order_id: 5577, color: 'yellow' }, { invoice_nr: 17, order_id: 5574, color: 'green' }, { invoice_nr: 18, order_id: 5578, color: 'yellow' }, { invoice_nr: 18, order_id: 5578, color: 'blue' } ];\n\nconst res = result.reduce((a,b) => ((a[b.invoice_nr] ??= []).push(b),a),{});\nconsole.log(Object.values(res)); .as-console-wrapper { max-height: 100% !important }"
},
{
"answer_id": 74656701,
"author": "gureenkov56",
"author_id": 18470572,
"author_profile": "https://Stackoverflow.com/users/18470572",
"pm_score": 0,
"selected": false,
"text": "const result = [\n {\n invoice_nr: 16,\n order_id: 5577,\n color: 'red'\n },\n {\n invoice_nr: 16,\n order_id: 5577,\n color: 'yellow'\n },\n {\n invoice_nr: 17,\n order_id: 5574,\n color: 'green'\n },\n {\n invoice_nr: 18,\n order_id: 5578,\n color: 'yellow'\n },\n {\n invoice_nr: 18,\n order_id: 5578,\n color: 'blue'\n }\n];\n\nlet uniq = [];\nlet res = [];\n// get unique ID\nresult.forEach(i => !uniq.includes(i.invoice_nr) ? uniq.push(i.invoice_nr) : '' );\n// filter by ID\nuniq.forEach(id => {\n res.push(result.filter(o => o.invoice_nr === id))\n})\n// that you need in res\nconsole.log(res);"
},
{
"answer_id": 74657083,
"author": "Trevor Dixon",
"author_id": 711902,
"author_profile": "https://Stackoverflow.com/users/711902",
"pm_score": 0,
"selected": false,
"text": "result.reduce((arr, item) => {\n const group = arr.at(-1), prevItem = group?.at(-1);\n if (prevItem?.invoice_nr === item.invoice_nr) {\n group.push(item);\n } else {\n arr.push([item]);\n }\n return arr;\n}, []);\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656777",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20667026/"
] |
74,656,782
|
<p>I have a dataframe like this:</p>
<pre><code>df <- data.frame(ID = c(1,2,3,4,5),
Total = c(1,1,2,1,2),
Ma = c(1,2,1,2,1),
Mb = c(1,2,1,2,2),
Md = c(1,2,1,2,1),
Me = c(1,1,1,2,2))
</code></pre>
<p>I'd like to add a column to indicate the maximum of repetition rate, from <code>Total</code> through <code>Me</code> column for each row. It should be something like:</p>
<pre><code>rep.rate = c(1,0.6,0.8,0.8,0.6)
</code></pre>
<p>These values indicate the rate of repetition for the most common value across the five columns in each row.</p>
|
[
{
"answer_id": 74656816,
"author": "Sotos",
"author_id": 5635580,
"author_profile": "https://Stackoverflow.com/users/5635580",
"pm_score": 2,
"selected": false,
"text": "apply(df[-1], 1, function(i)max(prop.table(table(i))))\n#[1] 1.0 0.6 0.8 0.8 0.6\n"
},
{
"answer_id": 74656825,
"author": "Vinícius Félix",
"author_id": 9696037,
"author_profile": "https://Stackoverflow.com/users/9696037",
"pm_score": 0,
"selected": false,
"text": "library(dplyr)\n\ndf <- data.frame(ID = c(1,2,3,4,5), Total = c(1,1,2,1,2), Ma = c(1,2,1,2,1), Mb = c(1,2,1,2,2), Md = c(1,2,1,2,1), Me = c(1,1,1,2,2))\n\ncat_mode <-\n function(x){\n \n cat_levels <- unique(x)\n \n out <- cat_levels[which.max(tabulate(match(x, cat_levels)))]\n \n return(out)\n \n }\n\ndf %>% \n rowwise() %>% \n mutate(rep.rate = sum(c_across(Total:Me) == cat_mode(c_across(Total:Me)),na.rm =TRUE)/5 )\n\n# A tibble: 5 x 7\n# Rowwise: \n ID Total Ma Mb Md Me rep.rate\n <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>\n1 1 1 1 1 1 1 1 \n2 2 1 2 2 2 1 0.6\n3 3 2 1 1 1 1 0.8\n4 4 1 2 2 2 2 0.8\n5 5 2 1 2 1 2 0.6\n"
},
{
"answer_id": 74656921,
"author": "Captain Hat",
"author_id": 4676560,
"author_profile": "https://Stackoverflow.com/users/4676560",
"pm_score": 0,
"selected": false,
"text": "df <- data.frame(ID = c(1,2,3,4,5), Total = c(1,1,2,1,2), Ma = c(1,2,1,2,1), Mb = c(1,2,1,2,2), Md = c(1,2,1,2,1), Me = c(1,1,1,2,2))\n\nlibrary(dplyr, warn.conflicts = FALSE)\n\nget_repeat_rate <- function(x){\n table <- table(x)\n props <- table/sum(table\n max_prop <- max(props)\n return(max_prop)\n}\n\ndf |> \n rowwise() |> \n mutate(repeat_rate = get_repeat_rate(c_across(-ID)))\n\n#> # A tibble: 5 × 7\n#> # Rowwise: \n#> ID Total Ma Mb Md Me repeat_rate\n#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>\n#> 1 1 1 1 1 1 1 1 \n#> 2 2 1 2 2 2 1 0.6\n#> 3 3 2 1 1 1 1 0.8\n#> 4 4 1 2 2 2 2 0.8\n#> 5 5 2 1 2 1 2 0.6\n"
},
{
"answer_id": 74657801,
"author": "M--",
"author_id": 6461462,
"author_profile": "https://Stackoverflow.com/users/6461462",
"pm_score": 1,
"selected": false,
"text": "dplyr library(dplyr)\n\ndf %>% \n rowwise %>% \n mutate(rep.rate = max(table(c_across(-ID)))/(ncol(.)-1)) %>% \n ungroup\n # # A tibble: 5 x 7\n# ID Total Ma Mb Md Me rep.rate\n# <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>\n# 1 1 1 1 1 1 1 1 \n# 2 2 1 2 2 2 1 0.6\n# 3 3 2 1 1 1 1 0.8\n# 4 4 1 2 2 2 2 0.8\n# 5 5 2 1 2 1 2 0.6\n"
},
{
"answer_id": 74658388,
"author": "GitZine",
"author_id": 8758029,
"author_profile": "https://Stackoverflow.com/users/8758029",
"pm_score": 0,
"selected": false,
"text": "df%>%\nrowwise()%>%\nmutate(rep.rate=sum(across(Total:Me)== max(Total:Me))/5)\n rowwise() max(Total:Me) sum(across(Total:Me)== max)"
},
{
"answer_id": 74658923,
"author": "jblood94",
"author_id": 9463489,
"author_profile": "https://Stackoverflow.com/users/9463489",
"pm_score": 0,
"selected": false,
"text": "0.5 + abs(rowMeans(df[,-1] == df[1, 2]) - 0.5)\n#> [1] 1.0 0.6 0.8 0.8 0.6\n matrixStats::rowTabulates library(matrixStats)\n\nrowMaxs(\n rowTabulates(\n matrix(\n match(\n unlist(df[,-1]),\n unique(unlist(df[,-1]))\n ), nrow(df)\n )\n )\n)/(ncol(df) - 1)\n#> [1] 1.0 0.6 0.8 0.8 0.6\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656782",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16331793/"
] |
74,656,885
|
<p>I'm coding project with codewars and have a trouble. This function has to check if parentheses in string are valid. My problem is when i assign i = 0 in function valid pair it's doesnt work . I tried assign it below if statement and then my loop is infinite. My idea is valid pairs and then start over and over while parens.lenght will be <= 2 then i know that there left a pair and i can nothing to do with it. Could you help me?</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>// "()" => true
// ")(()))" => false
// "(" => false
// "(())((()())())" => true
const validPair = (parens) => {
console.log(parens);
for (let i = 0; i < parens.length; i++) {
if (parens[i] == '(' && parens[i + 1] == ')') {
parens.splice(i, 2);
i = 0;
console.log(parens.length);
}
if (parens.length <= 2) {
console.log(parens);
}
}
console.log(parens);
};
function validParentheses(parens) {
let validLength = 0;
parens = parens.split('');
parens.forEach((el) => {
if (el == '(') {
validLength++;
} else {
validLength--;
}
});
if (validLength != 0) {
return false;
} else {
validPair(parens);
}
}
console.log(validParentheses('(()))(()'));</code></pre>
</div>
</div>
</p>
<p>I will be updating this code but i stuck in this moment and dont know what to do.</p>
|
[
{
"answer_id": 74656816,
"author": "Sotos",
"author_id": 5635580,
"author_profile": "https://Stackoverflow.com/users/5635580",
"pm_score": 2,
"selected": false,
"text": "apply(df[-1], 1, function(i)max(prop.table(table(i))))\n#[1] 1.0 0.6 0.8 0.8 0.6\n"
},
{
"answer_id": 74656825,
"author": "Vinícius Félix",
"author_id": 9696037,
"author_profile": "https://Stackoverflow.com/users/9696037",
"pm_score": 0,
"selected": false,
"text": "library(dplyr)\n\ndf <- data.frame(ID = c(1,2,3,4,5), Total = c(1,1,2,1,2), Ma = c(1,2,1,2,1), Mb = c(1,2,1,2,2), Md = c(1,2,1,2,1), Me = c(1,1,1,2,2))\n\ncat_mode <-\n function(x){\n \n cat_levels <- unique(x)\n \n out <- cat_levels[which.max(tabulate(match(x, cat_levels)))]\n \n return(out)\n \n }\n\ndf %>% \n rowwise() %>% \n mutate(rep.rate = sum(c_across(Total:Me) == cat_mode(c_across(Total:Me)),na.rm =TRUE)/5 )\n\n# A tibble: 5 x 7\n# Rowwise: \n ID Total Ma Mb Md Me rep.rate\n <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>\n1 1 1 1 1 1 1 1 \n2 2 1 2 2 2 1 0.6\n3 3 2 1 1 1 1 0.8\n4 4 1 2 2 2 2 0.8\n5 5 2 1 2 1 2 0.6\n"
},
{
"answer_id": 74656921,
"author": "Captain Hat",
"author_id": 4676560,
"author_profile": "https://Stackoverflow.com/users/4676560",
"pm_score": 0,
"selected": false,
"text": "df <- data.frame(ID = c(1,2,3,4,5), Total = c(1,1,2,1,2), Ma = c(1,2,1,2,1), Mb = c(1,2,1,2,2), Md = c(1,2,1,2,1), Me = c(1,1,1,2,2))\n\nlibrary(dplyr, warn.conflicts = FALSE)\n\nget_repeat_rate <- function(x){\n table <- table(x)\n props <- table/sum(table\n max_prop <- max(props)\n return(max_prop)\n}\n\ndf |> \n rowwise() |> \n mutate(repeat_rate = get_repeat_rate(c_across(-ID)))\n\n#> # A tibble: 5 × 7\n#> # Rowwise: \n#> ID Total Ma Mb Md Me repeat_rate\n#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>\n#> 1 1 1 1 1 1 1 1 \n#> 2 2 1 2 2 2 1 0.6\n#> 3 3 2 1 1 1 1 0.8\n#> 4 4 1 2 2 2 2 0.8\n#> 5 5 2 1 2 1 2 0.6\n"
},
{
"answer_id": 74657801,
"author": "M--",
"author_id": 6461462,
"author_profile": "https://Stackoverflow.com/users/6461462",
"pm_score": 1,
"selected": false,
"text": "dplyr library(dplyr)\n\ndf %>% \n rowwise %>% \n mutate(rep.rate = max(table(c_across(-ID)))/(ncol(.)-1)) %>% \n ungroup\n # # A tibble: 5 x 7\n# ID Total Ma Mb Md Me rep.rate\n# <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>\n# 1 1 1 1 1 1 1 1 \n# 2 2 1 2 2 2 1 0.6\n# 3 3 2 1 1 1 1 0.8\n# 4 4 1 2 2 2 2 0.8\n# 5 5 2 1 2 1 2 0.6\n"
},
{
"answer_id": 74658388,
"author": "GitZine",
"author_id": 8758029,
"author_profile": "https://Stackoverflow.com/users/8758029",
"pm_score": 0,
"selected": false,
"text": "df%>%\nrowwise()%>%\nmutate(rep.rate=sum(across(Total:Me)== max(Total:Me))/5)\n rowwise() max(Total:Me) sum(across(Total:Me)== max)"
},
{
"answer_id": 74658923,
"author": "jblood94",
"author_id": 9463489,
"author_profile": "https://Stackoverflow.com/users/9463489",
"pm_score": 0,
"selected": false,
"text": "0.5 + abs(rowMeans(df[,-1] == df[1, 2]) - 0.5)\n#> [1] 1.0 0.6 0.8 0.8 0.6\n matrixStats::rowTabulates library(matrixStats)\n\nrowMaxs(\n rowTabulates(\n matrix(\n match(\n unlist(df[,-1]),\n unique(unlist(df[,-1]))\n ), nrow(df)\n )\n )\n)/(ncol(df) - 1)\n#> [1] 1.0 0.6 0.8 0.8 0.6\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656885",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16881950/"
] |
74,656,897
|
<p>if any of the webpage elements has <strong>is-open</strong> class, add <strong>open</strong> class to another div. doesn't work</p>
<p><strong>is-open</strong> is added to div's each time a modal or tab is opened on the page.</p>
<pre><code><script>
if($(".is-open").length){
$(".blur-screen").addClass("open");
} else {
$(".blur-screen").removeClass("open");
}
</script>
</code></pre>
|
[
{
"answer_id": 74656816,
"author": "Sotos",
"author_id": 5635580,
"author_profile": "https://Stackoverflow.com/users/5635580",
"pm_score": 2,
"selected": false,
"text": "apply(df[-1], 1, function(i)max(prop.table(table(i))))\n#[1] 1.0 0.6 0.8 0.8 0.6\n"
},
{
"answer_id": 74656825,
"author": "Vinícius Félix",
"author_id": 9696037,
"author_profile": "https://Stackoverflow.com/users/9696037",
"pm_score": 0,
"selected": false,
"text": "library(dplyr)\n\ndf <- data.frame(ID = c(1,2,3,4,5), Total = c(1,1,2,1,2), Ma = c(1,2,1,2,1), Mb = c(1,2,1,2,2), Md = c(1,2,1,2,1), Me = c(1,1,1,2,2))\n\ncat_mode <-\n function(x){\n \n cat_levels <- unique(x)\n \n out <- cat_levels[which.max(tabulate(match(x, cat_levels)))]\n \n return(out)\n \n }\n\ndf %>% \n rowwise() %>% \n mutate(rep.rate = sum(c_across(Total:Me) == cat_mode(c_across(Total:Me)),na.rm =TRUE)/5 )\n\n# A tibble: 5 x 7\n# Rowwise: \n ID Total Ma Mb Md Me rep.rate\n <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>\n1 1 1 1 1 1 1 1 \n2 2 1 2 2 2 1 0.6\n3 3 2 1 1 1 1 0.8\n4 4 1 2 2 2 2 0.8\n5 5 2 1 2 1 2 0.6\n"
},
{
"answer_id": 74656921,
"author": "Captain Hat",
"author_id": 4676560,
"author_profile": "https://Stackoverflow.com/users/4676560",
"pm_score": 0,
"selected": false,
"text": "df <- data.frame(ID = c(1,2,3,4,5), Total = c(1,1,2,1,2), Ma = c(1,2,1,2,1), Mb = c(1,2,1,2,2), Md = c(1,2,1,2,1), Me = c(1,1,1,2,2))\n\nlibrary(dplyr, warn.conflicts = FALSE)\n\nget_repeat_rate <- function(x){\n table <- table(x)\n props <- table/sum(table\n max_prop <- max(props)\n return(max_prop)\n}\n\ndf |> \n rowwise() |> \n mutate(repeat_rate = get_repeat_rate(c_across(-ID)))\n\n#> # A tibble: 5 × 7\n#> # Rowwise: \n#> ID Total Ma Mb Md Me repeat_rate\n#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>\n#> 1 1 1 1 1 1 1 1 \n#> 2 2 1 2 2 2 1 0.6\n#> 3 3 2 1 1 1 1 0.8\n#> 4 4 1 2 2 2 2 0.8\n#> 5 5 2 1 2 1 2 0.6\n"
},
{
"answer_id": 74657801,
"author": "M--",
"author_id": 6461462,
"author_profile": "https://Stackoverflow.com/users/6461462",
"pm_score": 1,
"selected": false,
"text": "dplyr library(dplyr)\n\ndf %>% \n rowwise %>% \n mutate(rep.rate = max(table(c_across(-ID)))/(ncol(.)-1)) %>% \n ungroup\n # # A tibble: 5 x 7\n# ID Total Ma Mb Md Me rep.rate\n# <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>\n# 1 1 1 1 1 1 1 1 \n# 2 2 1 2 2 2 1 0.6\n# 3 3 2 1 1 1 1 0.8\n# 4 4 1 2 2 2 2 0.8\n# 5 5 2 1 2 1 2 0.6\n"
},
{
"answer_id": 74658388,
"author": "GitZine",
"author_id": 8758029,
"author_profile": "https://Stackoverflow.com/users/8758029",
"pm_score": 0,
"selected": false,
"text": "df%>%\nrowwise()%>%\nmutate(rep.rate=sum(across(Total:Me)== max(Total:Me))/5)\n rowwise() max(Total:Me) sum(across(Total:Me)== max)"
},
{
"answer_id": 74658923,
"author": "jblood94",
"author_id": 9463489,
"author_profile": "https://Stackoverflow.com/users/9463489",
"pm_score": 0,
"selected": false,
"text": "0.5 + abs(rowMeans(df[,-1] == df[1, 2]) - 0.5)\n#> [1] 1.0 0.6 0.8 0.8 0.6\n matrixStats::rowTabulates library(matrixStats)\n\nrowMaxs(\n rowTabulates(\n matrix(\n match(\n unlist(df[,-1]),\n unique(unlist(df[,-1]))\n ), nrow(df)\n )\n )\n)/(ncol(df) - 1)\n#> [1] 1.0 0.6 0.8 0.8 0.6\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656897",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9062202/"
] |
74,656,931
|
<p>I am trying to build a battleship game and using functions.
I wish to create and randomise 1 & 0 in my array every time I run the function as seen in the array below</p>
<p>Since it is a battlefield game, is there any way to make the 1s be in a row /column of 4/3/2/1? , to mimic the different sizes of the battleships</p>
<pre><code> let battelfield = [
[0,0,0,1,1,1,1,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,1,0,0,0],
[0,0,0,0,0,0,1,0,0,0],
[1,0,0,0,0,0,1,1,1,1],
[1,0,0,0,0,0,0,0,0,0],
[1,0,0,1,0,0,0,0,0,0],
[1,0,0,1,0,0,0,0,0,0],
[1,0,0,0,0,0,0,0,0,0]
]`
</code></pre>
|
[
{
"answer_id": 74657321,
"author": "Salketer",
"author_id": 1620194,
"author_profile": "https://Stackoverflow.com/users/1620194",
"pm_score": 0,
"selected": false,
"text": "continue; let battlefield = new Array(10*10).fill(0);\nplaceShip(3);\nplaceShip(4);\nplaceShip(4);\nplaceShip(5);\nconsole.log(battlefield);\n\nfunction placeShip(length){\n while(true){\n const start = Math.round(Math.random()*99);\n if(battlefield[start]==='1') continue;\n const orientation = Math.random() <=.5?'H':'V';\n // Fill the positions where the ship will be placed.\n const positions = new Array();\n if(orientation === 'H'){\n // First make sure we have room to place it\n if(10-((start+1) % 10) < length)continue;\n for(let p=start;p<start+length;p++){\n // Set for each length the position the ship will take.\n positions.push(p);\n }\n }else if(orientation === 'V'){\n // Same as for H but we divide by 10 because we want rows instead of cells.\n if(10-((start/10) % 10) < length)continue;\n for(let p=start;p<start+length*10;p+=10){\n // Set for each length the position the ship will take.\n positions.push(p);\n }\n }\n // Now let's check to make sure there is not a ship already in one of the positions\n for(let i=0,L=positions.length;i<L;i++){\n if(battlefield[positions[i]]!==\"0\")continue;\n }\n // Now let's put the ship in place\n for(let i=0,L=positions.length;i<L;i++){\n battlefield[positions[i]] = 1;\n }\n return;\n }\n}"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656931",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20667049/"
] |
74,656,967
|
<p>I am learning Jetpack compose of Android Development.</p>
<p>Sometimes, I use</p>
<p>MaterialTheme.colors
MaterialTheme.coloScheme</p>
<p>because one of them shows red.</p>
<p>For example,</p>
<pre><code>Surface(
color = MaterialTheme.colorScheme.primary,
modifier = Modifier.padding(vertical = 4.dp, horizontal = 8.dp)
) {
Row(modifier = Modifier.padding(24.dp)) {
Column(modifier = Modifier
.weight(1f)
.padding(bottom = extraPadding)
) {
Text(text = "Hello, ")
Text(text = name)
}
ElevatedButton(
onClick = { expanded.value = !expanded.value }
) {
Text(if (expanded.value) "Show less" else "Show more")
}
}
}
</code></pre>
<p>So, what's the difference and which one is better or how to use them properly?</p>
|
[
{
"answer_id": 74657216,
"author": "Code Poet",
"author_id": 5513788,
"author_profile": "https://Stackoverflow.com/users/5513788",
"pm_score": 0,
"selected": false,
"text": " Surface(\n color = MaterialTheme.colors.surface,\n contentColor = contentColorFor(color),\n // ...\n\nTopAppBar(\n backgroundColor = MaterialTheme.colors.primarySurface,\n contentColor = contentColorFor(backgroundColor),\n // ...\n Card(\n colors = CardDefaults.cardColors(\n containerColor =\n if (isSelected) MaterialTheme.colorScheme.primaryContainer\n else\n MaterialTheme.colorScheme.surfaceVariant)\n) {\n Text(\n text = “Dinner club”,\n style = MaterialTheme.typography.bodyLarge,\n color =\n if (isSelected) MaterialTheme.colorScheme.onPrimaryContainer\n else MaterialTheme.colorScheme.onSurface, ),\n ….\n ….\n}\n"
},
{
"answer_id": 74657219,
"author": "MoCoding",
"author_id": 11617754,
"author_profile": "https://Stackoverflow.com/users/11617754",
"pm_score": 0,
"selected": false,
"text": "colors MaterialTheme.colors MaterialTheme import androidx.compose.material.MaterialTheme colorScheme MaterialTheme.colorScheme MaterialTheme import androidx.compose.material3.MaterialTheme colorScheme color"
},
{
"answer_id": 74657232,
"author": "Gowtham K K",
"author_id": 9248098,
"author_profile": "https://Stackoverflow.com/users/9248098",
"pm_score": 0,
"selected": false,
"text": "MaterialTheme.colorScheme.primary MaterialTheme.colors.background"
},
{
"answer_id": 74657735,
"author": "Thracian",
"author_id": 5457853,
"author_profile": "https://Stackoverflow.com/users/5457853",
"pm_score": 1,
"selected": false,
"text": "androidx.compose.material.MaterialTheme.colors.x #FF00000 -> #c001000\n internal object FilledButtonTokens {\n val ContainerColor = ColorSchemeKeyTokens.Primary\n val ContainerElevation = ElevationTokens.Level0\n val ContainerHeight = 40.0.dp\n val ContainerShape = ShapeKeyTokens.CornerFull\n val DisabledContainerColor = ColorSchemeKeyTokens.OnSurface\n val DisabledContainerElevation = ElevationTokens.Level0\n const val DisabledContainerOpacity = 0.12f\n val DisabledLabelTextColor = ColorSchemeKeyTokens.OnSurface\n const val DisabledLabelTextOpacity = 0.38f\n val FocusContainerElevation = ElevationTokens.Level0\n val FocusLabelTextColor = ColorSchemeKeyTokens.OnPrimary\n val HoverContainerElevation = ElevationTokens.Level1\n val HoverLabelTextColor = ColorSchemeKeyTokens.OnPrimary\n val LabelTextColor = ColorSchemeKeyTokens.OnPrimary\n val LabelTextFont = TypographyKeyTokens.LabelLarge\n val PressedContainerElevation = ElevationTokens.Level0\n val PressedLabelTextColor = ColorSchemeKeyTokens.OnPrimary\n val DisabledIconColor = ColorSchemeKeyTokens.OnSurface\n const val DisabledIconOpacity = 0.38f\n val FocusIconColor = ColorSchemeKeyTokens.OnPrimary\n val HoverIconColor = ColorSchemeKeyTokens.OnPrimary\n val IconColor = ColorSchemeKeyTokens.OnPrimary\n val IconSize = 18.0.dp\n val PressedIconColor = ColorSchemeKeyTokens.OnPrimary\n}\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656967",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7877391/"
] |
74,656,968
|
<p>I have a component that needs to be rendered under the <code>Home</code> page component. Now I have nested, but the component is not rendered. Although if you do without nesting, then everything works. How can I do this?</p>
<pre><code>export default function App() {
return (
<div className="App">
<Routes>
<Route path="/" element={<Home />}>
<Route path="route1" element={<Route1 />} />
</Route>
</Routes>
</div>
);
}
</code></pre>
<pre><code>export default function Route1() {
return (
<>
<h2>Route1</h2>
<Outlet />
</>
);
}
</code></pre>
<pre><code>export default function Home() {
return (
<>
<h1>Home Page</h1>
</>
);
}
</code></pre>
|
[
{
"answer_id": 74657216,
"author": "Code Poet",
"author_id": 5513788,
"author_profile": "https://Stackoverflow.com/users/5513788",
"pm_score": 0,
"selected": false,
"text": " Surface(\n color = MaterialTheme.colors.surface,\n contentColor = contentColorFor(color),\n // ...\n\nTopAppBar(\n backgroundColor = MaterialTheme.colors.primarySurface,\n contentColor = contentColorFor(backgroundColor),\n // ...\n Card(\n colors = CardDefaults.cardColors(\n containerColor =\n if (isSelected) MaterialTheme.colorScheme.primaryContainer\n else\n MaterialTheme.colorScheme.surfaceVariant)\n) {\n Text(\n text = “Dinner club”,\n style = MaterialTheme.typography.bodyLarge,\n color =\n if (isSelected) MaterialTheme.colorScheme.onPrimaryContainer\n else MaterialTheme.colorScheme.onSurface, ),\n ….\n ….\n}\n"
},
{
"answer_id": 74657219,
"author": "MoCoding",
"author_id": 11617754,
"author_profile": "https://Stackoverflow.com/users/11617754",
"pm_score": 0,
"selected": false,
"text": "colors MaterialTheme.colors MaterialTheme import androidx.compose.material.MaterialTheme colorScheme MaterialTheme.colorScheme MaterialTheme import androidx.compose.material3.MaterialTheme colorScheme color"
},
{
"answer_id": 74657232,
"author": "Gowtham K K",
"author_id": 9248098,
"author_profile": "https://Stackoverflow.com/users/9248098",
"pm_score": 0,
"selected": false,
"text": "MaterialTheme.colorScheme.primary MaterialTheme.colors.background"
},
{
"answer_id": 74657735,
"author": "Thracian",
"author_id": 5457853,
"author_profile": "https://Stackoverflow.com/users/5457853",
"pm_score": 1,
"selected": false,
"text": "androidx.compose.material.MaterialTheme.colors.x #FF00000 -> #c001000\n internal object FilledButtonTokens {\n val ContainerColor = ColorSchemeKeyTokens.Primary\n val ContainerElevation = ElevationTokens.Level0\n val ContainerHeight = 40.0.dp\n val ContainerShape = ShapeKeyTokens.CornerFull\n val DisabledContainerColor = ColorSchemeKeyTokens.OnSurface\n val DisabledContainerElevation = ElevationTokens.Level0\n const val DisabledContainerOpacity = 0.12f\n val DisabledLabelTextColor = ColorSchemeKeyTokens.OnSurface\n const val DisabledLabelTextOpacity = 0.38f\n val FocusContainerElevation = ElevationTokens.Level0\n val FocusLabelTextColor = ColorSchemeKeyTokens.OnPrimary\n val HoverContainerElevation = ElevationTokens.Level1\n val HoverLabelTextColor = ColorSchemeKeyTokens.OnPrimary\n val LabelTextColor = ColorSchemeKeyTokens.OnPrimary\n val LabelTextFont = TypographyKeyTokens.LabelLarge\n val PressedContainerElevation = ElevationTokens.Level0\n val PressedLabelTextColor = ColorSchemeKeyTokens.OnPrimary\n val DisabledIconColor = ColorSchemeKeyTokens.OnSurface\n const val DisabledIconOpacity = 0.38f\n val FocusIconColor = ColorSchemeKeyTokens.OnPrimary\n val HoverIconColor = ColorSchemeKeyTokens.OnPrimary\n val IconColor = ColorSchemeKeyTokens.OnPrimary\n val IconSize = 18.0.dp\n val PressedIconColor = ColorSchemeKeyTokens.OnPrimary\n}\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656968",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20592580/"
] |
74,656,973
|
<p>I have an array of objects that I get from an api, I get the data but I want to remove the ones that have a finish status after x time.</p>
<p>First I must show all the records, after a certain time the records with FINISH status must be deleted</p>
<p><strong>I am using vue.</strong></p>
<p>This is the response I get:</p>
<pre><code>[
{
"id": "289976",
"status": "FINISH"
},
{
"id": "302635",
"status": "PROGRESS"
},
{
"id": "33232",
"status": "PROGRESS"
}
]
</code></pre>
<p>This is the method that obtains the information:</p>
<p>I use setTimeout to be able to delete the records with FINISH status after a certain time</p>
<pre><code>getTurns() {
fetch('ENPOINT', {
method: 'POST',
body: JSON.stringify({id: this.selected}),
headers: {
'Content-Type': 'application/json'
}
}).then(response => response.json())
.then(data => {
this.turns = data;
data.forEach(turn => {
if(turn.status == 'FINISH'){
setTimeout(() => {
this.turns = data.filter(turn => turn.status !== 'FINISH');
}, 6000);
}
});
})
.catch(error => console.error(error));
}
</code></pre>
<p>I have tried going through the array and making a conditional and it works for me, but when I call the method again I get the records with FINISH status again. I need to call the method every time since the data is updated</p>
<pre><code> mounted () {
this.getTurns();
setInterval(() => {
this.getTurns();
}, 5000);
}
</code></pre>
<p>maybe I need to order in another way, or that another javascript method I can use</p>
|
[
{
"answer_id": 74657051,
"author": "Valerij Dobler",
"author_id": 7082956,
"author_profile": "https://Stackoverflow.com/users/7082956",
"pm_score": 1,
"selected": false,
"text": "filter setInterval return data.filter(turn -> turn.status !== 'FINISHED');\n"
},
{
"answer_id": 74657171,
"author": "gureenkov56",
"author_id": 18470572,
"author_profile": "https://Stackoverflow.com/users/18470572",
"pm_score": 1,
"selected": false,
"text": "this.turns = data; data turns .then(data => {\n // get before filter\n this.turns = data;\n \n // filter data after 6 sec\n setTimeout(() => {\n data.forEach(turn => {\n this.turns = data.filter(turn => turn.status !== 'FINISH');\n });\n }, 6000)\n}) setTimeout fetch"
},
{
"answer_id": 74657522,
"author": "Carsten Massmann",
"author_id": 2610061,
"author_profile": "https://Stackoverflow.com/users/2610061",
"pm_score": 0,
"selected": false,
"text": "setTimeout() turns .company.catchphrase turns .then() getTurns() var turns; // global variable \nfunction getTurns() {\n return fetch(\"https://jsonplaceholder.typicode.com/users\")\n .then(r => r.json()).then(data =>\n turns=data.filter(turn=>!turn.company.catchPhrase.includes(\"zero\"))\n )\n .catch(error => console.error(error));\n}\ngetTurns().then(console.log);"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656973",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11429778/"
] |
74,656,987
|
<p>So I have a JSON File with multiple arrays "ID" that I want to extract.</p>
<pre><code>[
{
"ID": 318,
"Type": 0,
"Value": 3,
},
{
"ID": 580,
"Type": 5,
"Value": 8,
},
{
"ID": 23,
"Type": 3,
"Value": 40,
},
{
"ID": 13,
"Type": 2,
"Value": 58,
},
{
"ID": 60,
"Type": 54,
"Value": 22,
},
</code></pre>
<pre><code>function getID(address){
var url = 'https://data.com/api/v1/users/';
var res = UrlFetchApp.fetch(url);
var content = res.getContentText();
var json = JSON.parse(content);
var result = json[0]['ID']+", "+json[1]['ID']+", "+json[3]['ID'];
return result;
}
</code></pre>
<p>I have this code that parses the arrays one by one but I don't know how to get all the "ID" arrays at once. Anyone that can help?</p>
|
[
{
"answer_id": 74660004,
"author": "David Ranieri",
"author_id": 1606345,
"author_profile": "https://Stackoverflow.com/users/1606345",
"pm_score": 1,
"selected": false,
"text": "var result = json.map(({ ID }) => ID);\n return JSON.stringify(result);\n return JSON.stringify(result).slice(1, -1);\n"
},
{
"answer_id": 74660672,
"author": "Peter Seliger",
"author_id": 2627243,
"author_profile": "https://Stackoverflow.com/users/2627243",
"pm_score": 0,
"selected": false,
"text": "fetch Promise.prototype.then async await Array.prototype.map Array.prototype.join /*async */function getFetchedApiData(apiUrl) {\n return fetch(apiUrl)\n .then(response => response.json());\n}\n\ngetFetchedApiData('https://jsonplaceholder.typicode.com/users')\n .then(data => {\n console.log({ data });\n return data;\n })\n .then(data =>\n data.map(item => item.id)\n )\n .then(idList => {\n console.log({ idList });\n return idList;\n })\n .then(idList => {\n console.log({ concatenatedIds: idList.join(', ') });\n // return idList;\n }); .as-console-wrapper { min-height: 100%!important; top: 0; } async function getFetchedApiData(apiUrl) {\n return fetch(apiUrl)\n .then(response => response.json());\n}\n\n(async () => {\n\n const data = await getFetchedApiData('https://jsonplaceholder.typicode.com/users');\n const idList = data.map(({ id }) => id);\n const concatenatedIds = idList.join(', ');\n\n console.log({ data, idList, concatenatedIds });\n \n})(); .as-console-wrapper { min-height: 100%!important; top: 0; }"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656987",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20667017/"
] |
74,656,999
|
<p>I am very VERY new to all things coding, and I have run into a bit of trouble. I have this method that generates a random number between 1 - 6 (its supposed to simulate a dice roll), and what I want to do is through an input enable the user to change how many sides the dices has (The second parameter of the int nr in this case).</p>
<p>I want to be able to change the 7 to any number with a piece of code that is outside the method itself.
I can not wrap my head around how I am supposed to accomplish this.</p>
<pre><code>static int RullaTärning(Random slumpObjekt)
{
int nr = slumpObjekt.Next(1, 7);
return nr;
}
</code></pre>
<p>Any and all help is appreciated, and if there is some piece of information missing that is needed to solve this, please let me know.</p>
<p>Thanks</p>
<p>I've tried changing the 7 to an integer variable "sides", but I don't know how to change this integer variable later on in the program.
I have tried a load of random stuff without much thought, but I don't know how to accomplish this at all. I really am lost.</p>
|
[
{
"answer_id": 74657121,
"author": "kopagl",
"author_id": 19689833,
"author_profile": "https://Stackoverflow.com/users/19689833",
"pm_score": 1,
"selected": false,
"text": "static int RullaTärning(Random slumpObjekt, int sides)\n{\n int nr = slumpObjekt.Next(1, sides);\n return nr;\n}\n"
},
{
"answer_id": 74657125,
"author": "Karan Gehlod",
"author_id": 14322692,
"author_profile": "https://Stackoverflow.com/users/14322692",
"pm_score": 1,
"selected": false,
"text": "static int RullaTärning(Random slumpObjekt, int numberOfFaces){\nint nr = slumpObjekt.Next(1, numberOfFaces+1); \nreturn nr;\n}\n"
},
{
"answer_id": 74657148,
"author": "Fildor",
"author_id": 982149,
"author_profile": "https://Stackoverflow.com/users/982149",
"pm_score": 3,
"selected": true,
"text": "Next static int RullaTärning(Random slumpObjekt)\n{\n int sides = 6;\n int nr = slumpObjekt.Next(1, sides +1); \n return nr;\n}\n static int RullaTärning(Random slumpObjekt, int sides)\n{\n int nr = slumpObjekt.Next(1, sides+1); \n return nr;\n}\n static int RullaTärning(Random slumpObjekt, int sides = 6)\n{\n int nr = slumpObjekt.Next(1, sides+1); \n return nr;\n}\n\n// Can be used as\nint roll = RullaTärning(rnd); // no second param => 6 will be used\n// or\nint damage = RullaTärning(rnd, 16);\n static int RullaTärning(Random slumpObjekt, int sides = 6)\n{\n // Assuming we had a requirement to allow no less than 6 sides.\n if( sides < 6 ) throw new ArgumentException(\"Dice need at least 6 sides.\", nameof(sides));\n // Mind that I did not check `slumpObjekt` for null,\n // because a NullReferenceException will be thrown anyway\n // on the attempt to call `Next` on `null`.\n int nr = slumpObjekt.Next(1, sides+1); \n return nr;\n}\n\n// because there is always \"that guy\" who will try\nint nonsense = RullaTärning(rnd, -5);\n const int MINIMAL_ALLOWED_SIDES = 6; // Now we know why \"6\" and \n // we only need to change 1 place in code \n // if requirement of minimal allowed sides \n // changes\nstatic int RullaTärning(Random slumpObjekt, int sides = MINIMAL_ALLOWED_SIDES)\n{\n if( sides < MINIMAL_ALLOWED_SIDES) throw new ArgumentException($\"Dice need at least {MINIMAL_ALLOWED_SIDES} sides.\", nameof(sides));\n int nr = slumpObjekt.Next(1, sides+1); \n return nr;\n}\n\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74656999",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20667139/"
] |
74,657,022
|
<p>I have a circle after clicking on which a popup appears . This popup has a button to close it. But it doesn't work the way I want it to. I want the popup to close but not reload the page.</p>
<p>I tried using onclick="this.parentNode.parentNode.remove(); return false;" . But it doesn't work correctly. Please tell me how to do it!</p>
<p>HTML:</p>
<pre><code><main>
<div class="button">
<input onclick="check()" type="checkbox" name="popup__input" id="popup__input" class="popup__check">
</div>
<div class="popup" name="popup" id="popup">
<label class="popup__label">
<form>
<div class="form__input">
<input type="text" id="fname" name="fname"><br><br>
</div>
<button class="form__button" type="submit" form="nameform" value="Submit">Відправити</button>
<div class="close-button__container">
<button class="close__button">&times;</button>
</div>
</form>
</label>
</div>
<div class="overlay">
</div>
</main>
</code></pre>
<p>CSS:</p>
<pre><code>*,
*::before,
*::after {
margin: 0;
padding: 0;
border: none;
box-sizing: border-box;
}
main {
width: 100%;
height: 100%;
position: relative;
}
.button {
width: 200px;
height: 200px;
border-radius: 100%;
background: linear-gradient(#e66465, #9198e5);
position: absolute;
grid-area: "c";
transition: linear 4s;
}
input[type=text], select {
width: 100%;
height: 60px;
padding: 12px 20px;
margin: 40px 0;
font-size: 60px;
display: flex;
border: 1px solid #ccc;
box-sizing: border-box;
border-radius: 5px;
}
form {
position: absolute;
display: grid;
grid-template-areas:
"a"
"b"
"c";
grid-template-columns: repeat(12, 1fr);
}
.form__input{
display: grid;
grid-area: "b";
grid-column-start: 2;
grid-column-end: 12;
}
.close__button{
width: 50px;
position: absolute;
height: 50px;
cursor: pointer;
border: none;
outline: none;
font-size: 3rem;
font-weight: bold;
background-color: rgba(104, 99, 99, 0);
grid-column-start: 12;
grid-column-end: 12;
}
.close-button__container{
display: grid;
grid-area: "a";
place-items: start middle;
}
.form__button {
width: 100%;
height: 55px;
display: grid;
margin-top: 110px;
position: absolute;
font-size: 35px;
color: #fff;
align-items: center;
background-color:#2962d3;
grid-column-start: 3;
grid-column-end: 11;
border-radius: 5px;
cursor: pointer;
}
.form__button:hover {
background-color: #4a79d6;
transition: 0.5s;
}
.overlay {
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
}
.popup {
display: none;
position: fixed;
top: 50%;
left: 50%;
z-index: 10;
transform: translate(-50%, -50%);
border-radius: 10px;
width: 850px;
height: 200px;
background: rgba(104, 99, 99, 0.5);
justify-content: end;
align-items: end;
}
.popup__label {
}
.popup__check {
position: absolute;
width: 100%;
height: 100%;
border-radius: 100%;
cursor: pointer;
z-index: 3;
appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
}
@media (max-width: 1024.98px) {
.button {
width:80px;
height: 80px;
border-radius: 100%;
background: linear-gradient(#e66465, #9198e5);
position: absolute;
transition: linear 4s;
}
}
@media (max-width: 890.98px) {
.popup {
width: 750px;
}
.form__button {
width: 500px;
height: 45px;
grid-column-start: 3;
grid-column-end: 6;
}
}
@media (max-width: 768.98px) {
input[type=text], select {
padding: 12px 20px;
margin: 50px 0;
font-size: 40px;
display: flex;
border: 1px solid #ccc;
box-sizing: border-box;
}
.form__button {
width: 100%;
height: 45px;
grid-column-start: 3;
grid-column-end: 11;
margin-top: 125px;
}
.popup {
width: 600px;
}
}
@media (max-width: 620.98px) {
.popup {
width: 480px;
}
input[type=text], select {
height: 50px;
}
.form__button {
height: 35px;
grid-column-start: 3;
grid-column-end: 11;
font-size: 20px;
}
.close__button{
font-size: 2rem;
}
}
@media (max-width: 507.98px) {
input[type=text], select {
padding: 12px 20px;
margin: 45px 0;
}
.popup {
width: 330px;
}
.close__button{
width: 25px;
height: 25px;
}
}
@media (max-width: 400.98px) {
.form__button {
height: 30px;
position: absolute;
font-size: 15px;
grid-column-start: 3;
grid-column-end: 11;
margin-top: 100px;
}
.popup {
width: 350px;
height: 150px;
}
}
@media (max-width: 358.98px) {
input[type=text], select {
height: 30px;
padding: 12px 20px;
margin: 35px 0px;
}
.form__button {
height: 30px;
margin-top: 80px;
position: absolute;
font-size: 15px;
}
.popup {
width: 280px;
height: 150px;
}
.close__button{
width: 15px;
height: 15px;
}
}
@media (max-width: 300.98px) {
input[type=text], select {
width: 200px;
height: 30px;
padding: 12px 20px;
margin: 35px 0px;
font-size: 20px;
display: flex;
border: 1px solid #ccc;
box-sizing: border-box;
}
.form__button {
height: 30px;
margin-top: 80px;
position: absolute;
font-size: 15px;
}
.popup {
width: 240px;
height: 150px;
}
}
</code></pre>
<p>JS:</p>
<pre><code>let elem = document.querySelector('.button');
function check() {
const popup = document.getElementsByClassName('popup');
if (document.getElementById('popup__input').checked = true) {
for (var i=0;i<popup.length;i+=1){
popup[i].style.display = 'block';
}
} else {
popup.style.display = "none";
}
}
const changePosition = () => {
let randX = Math.random();
let randY = Math.random();
const circleSize = {
width: elem.clientWidth,
heigth: elem.clientHeight
};
const windowWidth = window.innerWidth - circleSize.width;
const windowheigth = window.innerHeight - circleSize.heigth;
let randXMult = windowheigth * randX;
let randXP = randXMult + 'px';
let randYMult = windowWidth * randY;
let randYP = randYMult + 'px';
elem.style.top = randXP;
elem.style.left = randYP;
};
setInterval(changePosition, 1000);
</code></pre>
|
[
{
"answer_id": 74657108,
"author": "Dylan Delobel",
"author_id": 8338464,
"author_profile": "https://Stackoverflow.com/users/8338464",
"pm_score": -1,
"selected": false,
"text": "window.close() window.close() <button onclick=\"window.close()\">Close Window</button>\n button onclick window.close() window.close() window.open() window.close()"
},
{
"answer_id": 74658640,
"author": "Will",
"author_id": 19389806,
"author_profile": "https://Stackoverflow.com/users/19389806",
"pm_score": 0,
"selected": false,
"text": "button button close__button <button id=\"close__button\" type=\"button\" class=\"close__button\">×</button> click \n function close() {\n const popup = document.getElementById('popup').style.display = \"none\";\n }```\n\n"
}
] |
2022/12/02
|
[
"https://Stackoverflow.com/questions/74657022",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20601932/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.