I wanted to do a custom ordering for marketing_status_id in this:
$prospect = $this->filterProspect($request->all())
->select([
'student_marketings.*',
'students.name',
'students.identification_type_id',
])
->distinct('student_marketings.id')
->orderBy('student_marketings.marketing_status_id');
How to order it in this sequence: ('marketing_status_id', 5, 20, 4, 1, 3, 18, 6) ?
Use mysql inbuilt-method field() like this:
$prospect = $this->filterProspect($request->all())
->select([
'student_marketings.*',
'students.name',
'students.identification_type_id',
])
->distinct('student_marketings.id')
->orderBy(DB::raw('FIELD(marketing_status_id, 5, 20, 4, 1, 3, 18, 6)'));
Related
I was wondering if I can merge 2 sass maps at a specific index of the first map.
$numbers: (
"one": 1,
"two": 2,
"three": 3,
"six": 6,
"seven": 7,
);
$more-numbers: (
"four": 4,
"five": 5,
);
#debug map.merge($numbers, $more-numbers);
// ("one": 1, "two": 2, "three": 3, "six": 6, "seven": 7, "four": 4, "five": 5)
Instead, I want:
("one": 1, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7)
I tried with the list module functions list.index() list.set-nth() but it replaces the index
$index: list.index($numbers, (three 3));
#debug list.set-nth($numbers, $index, $more-numbers);
// "one" 1, "two" 2, ("four": 4, "five": 5), "six" 6, "seven" 7
Even if that worked I am not sure how I can convert it back to a map.
Edit because someone asked the reason behind my question..
I am experimenting with generating utility classes.
u-padding-1: { padding: 0.375rem; }
I have already a map with the values:
$padding: (
"properties": (
"-padding": padding,
),
"directions": (
null: null,
"-horizontal": "-left" "-right",
"-vertical": "-top" "-bottom",
"-top": "-top",
"-right": "-right",
"-bottom": "-bottom",
"-left": "-left",
),
"values": (
"-none": 0rem,
"-tiny": t.rem(t.spacing(tiny)),
"-small": t.rem(t.spacing(small)),
null: t.rem(t.spacing(base)),
"-large": t.rem(t.spacing(large)),
"-huge": t.rem(t.spacing(huge)),
"-auto": auto,
),
) !default;
Now instead of manually adding all the utility key value pairs in the $padding->"values"
"-0": 0,
"-1": 1,
...
I generate them with a while loop and merge them. That would not be an issue but I need these utility classes to be added just before the keyword values like auto, full, etc. for cascading reasons.
I don't want to add another key value pair to my map, for example
"keywords: (
"-auto": auto,
"-full": 100%,
....
),
because I also generate responsive classes and it gets messy.
This is an example of a partial file.
#use "sass:map";
#use "sass:math";
#use "../settings/index.settings" as s;
#use "../tools/index.tools" as t;
$margin: (
"properties": (
"-margin": margin,
),
"directions": (
null: null,
"-horizontal": "-left" "-right",
"-vertical": "-top" "-bottom",
"-top": "-top",
"-right": "-right",
"-bottom": "-bottom",
"-left": "-left",
),
"values": (
"-none": 0px,
"-tiny": t.rem(t.spacing(tiny)),
"-small": t.rem(t.spacing(small)),
null: t.rem(t.spacing(base)),
"-large": t.rem(t.spacing(large)),
"-huge": t.rem(t.spacing(huge)),
"-auto": auto,
),
) !default;
// Populate map with values
$margin-arithmetic-progress: ();
$m: 0;
#while $m <= (t.strip-unit(s.$global-baseline) * 5) {
$converted: t.rem($m);
$margin-arithmetic-progress: map.set($margin-arithmetic-progress, "values", "-#{math.div($m, t.strip-unit(s.$global-baseline))}", $converted);
$m: $m + t.strip-unit(s.$global-baseline);
}
$margin: map.deep-merge($margin, $margin-arithmetic-progress);
#include t.generate-classes($margin);
#include t.generate-responsive-classes($margin);
I have a lot of amplify apps which I want to manage via Lambdas. What is the equivalent of the cli command aws amplify list-apps in boto3, I had multiple attempts, but none worked out for me.
My bit of code that was using nextToken looked like this:
amplify = boto3.client('amplify')
apps = amplify.list_apps()
print(apps)
print('First token is: ', apps['nextToken'])
while 'nextToken' in apps:
apps = amplify.list_apps(nextToken=apps['nextToken'])
print('=====NEW APP=====')
print(apps)
print('=================')
Then I tried to use paginators like:
paginator = amplify.get_paginator('list_apps')
response_iterator = paginator.paginate(
PaginationConfig={
'MaxItems': 100,
'PageSize': 100
}
)
for i in response_iterator:
print(i)
Both of the attempts were throwing inconsistent output. The first one was printing first token and second entry but nothing more. The second one gives only the first entry.
Edit with more attemptsinfo + output. Bellow piece of code:
apps = amplify.list_apps()
print(apps)
print('---------------')
new_app = amplify.list_apps(nextToken=apps['nextToken'], maxResults=100)
print(new_app)
print('---------------')```
Returns (some sensitive output bits were removed):
EVG_long_token_x4gbDGaAWGPGOASRtJPSI='}
---------------
{'ResponseMetadata': {'RequestId': 'f6...e9eb', 'HTTPStatusCode': 200, 'HTTPHeaders': {'content-type': 'application/json', 'content-length': ...}, 'RetryAttempts': 0}, 'apps': [{'appId': 'dym7444jed2kq', 'appArn': 'arn:aws:amplify:us-east-2:763175725735:apps/dym7444jed2kq', 'name': 'vesting-interface', 'tags': {}, 'repository': 'https://github.com/...interface', 'platform': 'WEB', 'createTime': datetime.datetime(2021, 5, 4, 3, 41, 34, 717000, tzinfo=tzlocal()), 'updateTime': datetime.datetime(2021, 5, 4, 3, 41, 34, 717000, tzinfo=tzlocal()), 'environmentVariables': {}, 'defaultDomain': 'dym7444jed2kq.amplifyapp.com', 'customRules': _rules_, 'productionBranch': {'lastDeployTime': datetime.datetime(2021, 5, 26, 15, 10, 7, 694000, tzinfo=tzlocal()), 'status': 'SUCCEED', 'thumbnailUrl': 'https://aws-amplify-', 'branchName': 'main'}, - yarn install\n build:\n commands:\n - yarn run build\n artifacts:\n baseDirectory: build\n files:\n - '**/*'\n cache:\n paths:\n - node_modules/**/*\n", 'customHeaders': '', 'enableAutoBranchCreation': False}]}
---------------
I am very confused, why next iteration doesn't has nextToken and how can I get to the next appId.
import boto3
import json
session=boto3.session.Session(profile_name='<Profile_Name>')
amplify_client=session.client('amplify',region_name='ap-south-1')
output=amplify_client.list_apps()
print(output['apps'])
I have a program that when I press a pushbutton it loads the options of my combombox, I have three, but for a unknown reason only two works. This function read a .txt file, and then put the strings in the combobox. I tried with addItem() and addItems(), made function again and it didn't work. The function read another two combobox and then loads the options.This is the function:
def cargar_combobox_flujos2(self,event):
anho = int(self.ui.combobox_anho.itemText(self.ui.combobox_anho.currentIndex()))
mes_input = self.ui.combobox_mes.itemText(self.ui.combobox_mes.currentIndex())
dic = {'Enero': 1, 'Febrero': 2, 'Marzo': 3, 'Abril': 4, 'Junio': 5, 'Julio': 7, 'Agosto': 8, 'Septiembre': 9,
'Octubre': 10, 'Noviembre': 11, 'Diciembre': 12}
mes = int(dic.get(mes_input))
lista_ssee=[]
nombre_txt='Graficos Flujos/lista_cbbx_'+str(anho)+'_'+str(mes)+'.txt'
if os.path.isfile(nombre_txt)==True:
archivo = open(nombre_txt, 'r')
c=archivo.read()
lista=c.split(',')
for i in lista:
lista_ssee.append(i)
archivo.close()
option_barras= self.ui.comboBox_barras_CMg2.count()
if option_barras > 1:
self.ui.comboBox_barras_CMg2.clear()
for barra in lista_ssee:
self.ui.comboBox_barras_CMg2.addItems(barra)
Say I have the following table:
[
{numberOfRedStripes: 7, numberOfBlueStripes: 6, stars: 50, foo: "bar"},
{numberOfRedStripes: 1, numberOfBlueStripes: 1, stars: 0, something: "else"}
]
How can I use regex in order to pluck only the docs which their KEYS start with the string 'numberOf', so that the result would be:
[
{numberOfRedStripes: 7, numberOfBlueStripes: 6},
{numberOfRedStripes: 1, numberOfBlueStripes: 1}
]
?
Does this work?
table.map {|row|
row.pluck(r.args(row.keys().filter{|key| key.match("^numberOf")}))
}
I have an import script that imports well over 2000+ products including their images. I run this script via CLI because I feel that this is the best way to go speed-wise even though I have the same import script available and executable at the magento admin as an extension. The script runs pretty well. Almost perfect! However, sometimes the addToImageGallery somehow malfunctions and results into some images having No Image as the default product image and the only other image as not selected as defaults at all. How do I mass-update all products to set the first image in the media gallery for the product to the default 'base', 'image' and 'thumbnail' image(s)?
I found a couple of tricks on doing this (and more) on this link:
http://www.magentocommerce.com/boards/viewthread/59440/ (Thanks transio!)
Although, for Magento 1.6.2.0 (which I use), the first SQL trick there (Trick 1 - Auto-set default base, thumb, small image to first image.) needs a bit of modification.
On the second-to-the last-line there is a AND ev.attribute_id IN (70, 71, 72) part. This should point to attribute ID's which will probably not be relevant in Magento 1.6.2.0 anymore. To fix this, using any MySQL query tool (PHPMyAdmin or MySQL Query Browser), I took a look at the catalog_product_entity_varchar table. There should be entries like:
value_id, entity_type_id, attribute_id, store_id, entity_id, value
..
146649, 4, 116, 0, 1, '2'
146650, 4, 76, 0, 1, ''
146651, 4, 78, 0, 1, ''
146652, 4, 79, 0, 1, '/B/0/B05-01.jpg'
146653, 4, 80, 0, 1, '/B/0/B05-01.jpg'
146654, 4, 81, 0, 1, '/B/0/B05-01.jpg'
146655, 4, 96, 0, 1, ''
146656, 4, 100, 0, 1, ''
146657, 4, 102, 0, 1, 'container2'
..
My money was on the group of three image paths as possible replacements. So the resulting SQL now should be:
UPDATE catalog_product_entity_media_gallery AS mg,
catalog_product_entity_media_gallery_value AS mgv,
catalog_product_entity_varchar AS ev
SET ev.value = mg.value
WHERE mg.value_id = mgv.value_id
AND mg.entity_id = ev.entity_id
AND ev.attribute_id IN (79, 80, 81) # <-- attribute IDs updated here
AND mgv.position = 1;
So I committed to it, ran it and.. presto! All fixed! You might also want to encapsulate this in a transaction if you want. But this is out of this question's scope.
Well, this is the fix that worked for me so far! If there are any more out there, please share!
There was:
146652, 4, 79, 0, 1, '/B/0/B05-01.jpg'
146653, 4, 80, 0, 1, '/B/0/B05-01.jpg'
146654, 4, 81, 0, 1, '/B/0/B05-01.jpg'
So it should be:
AND ev.attribute_id IN (79, 80, 81) # <-- attribute IDs updated here
instead of:
AND ev.attribute_id IN (78, 80, 81) # <-- attribute IDs updated here
Is looking for something similar.
UPDATE catalog_product_entity_media_gallery AS mg,
catalog_product_entity_media_gallery_value AS mgv,
catalog_product_entity_varchar AS ev
SET ev.value = mg.value
WHERE mg.value_id = mgv.value_id
AND mg.entity_id = ev.entity_id
AND ev.attribute_id IN (79, 80, 81) # <-- attribute IDs updated here
AND mgv.position = 1;