Posts

swift - How can I sort an array of strings based on the number of instances a string appears in an element? -

how can sort array of strings based on number of instances string appears in element? example: let str = "o" let arrayofstrings = ["hot", "only open on tuesdays", "people of earth"] //sort here //arrayofstring becomes ["only open on tuesdays", "people of earth", "hot"] import foundation let str = "o" var arrayofstrings = ["hot", "only open on tuesdays", "people of earth"] arrayofstrings.sort { return $0.components(separatedby: str).count < $1.components(separatedby: str).count } print(arrayofstrings) // ["hot", "only open on tuesdays", "people of earth"] note correct order if sort highest instances last. went least instances show this: string "o" , string "o" 2 different strings count in original array 1, 2, 2. if want compare strings case-insensitively have apply uppercase or lowercase operation compa...

python - What is the difference between the solution that uses defaultdict and the one that uses setdefault? -

in think python author introduces defaultdict . following excerpt book regarding defaultdict : if making dictionary of lists, can write simpler code using defaultdict. in solution exercise 12-2, can http://thinkpython2.com/code/anagram_sets.py , make dictionary maps sorted string of letters list of words can spelled letters. example, 'opst' maps list ['opts', 'post', 'pots', 'spot', 'stop', 'tops']. here’s original code: def all_anagrams(filename): d = {} line in open(filename): word = line.strip().lower() t = signature(word) if t not in d: d[t] = [word] else: d[t].append(word) return d this can simplified using setdefault, might have used in exercise 11-2: def all_anagrams(filename): d = {} line in open(filename): word = line.strip().lower() t = signature(word) d.setdefault(t, []).append(w...

bash - PS1 Style Formatting -

Image
i trying make bash profile cool, , outright stole example posted on internet (can't remember though; claim no credit it). managed of different quirks wanted work , got of color , syntax codes working on arch box, on macbook, terminal app shows huge space between bracket , number of files in pwd. appreciate in making pretty since kind of bums me out @ space. i have included ps1 below: export ps1="┌─[\`if [ \$? = 0 ]; echo \[\e[32m\]✔\[\e[0m\]; else echo \[\e[31m\]✘\[\e[0m\]; fi\`]───[\[\e[01;49;39m\]\u\[\e[00m\]\[\e[01;49;39m\]\[\e[00m\]]───[\[\e[1;49;39m\]\w\[\e[0m\]]───[\[\e[1;49;39m\]\$(ls | wc -l) files, \$(ls -lah | grep -m 1 total | sed 's/total //')\[\e[0m\]]\n└───▶ "

Android - How can I get the email from the online login and show it to next intent -

i created online login on mobile app, have online database, , use asynctask login. want display email user input app , display next intent how can that, how can pass email user input onpostexecute? here code in onpostexecute when user logged in. protected void onpostexecute(string result) { if (result.equals("login successfully!")) { toast.maketext(context, "welcome okshop", toast.length_short).show(); intent intent = new intent(context, main2activity.class); context.startactivity(intent); ((activity)context).finish(); } } and here login url else if (type.equals("login")) { string email = params[1]; string password = params[2]; try { url url = new url(login_url); httpurlconnection httpurlconnection = (httpurlconnection) url.openconnection(); httpurlconnection.setrequestmethod("post"); httpurlconnection.setdooutput(true);...

node.js - How to verify AWS Cognito Access Token on NodeJS -

i found example on how verify cognito access tokens python . how do same nodejs? there no sdk function this? so far have authorizecognitojwt(token) { const cognito_pool_id = 'ap-southeast-1_xxx' const cognito_jwt_set = { 'keys': [ { 'alg': 'rs256', 'e': 'aqab', 'kid': 'chkv+...=', 'kty': 'rsa', 'n': 'tkjexs...johc5q', 'use': 'sig' }, { 'alg': 'rs256', 'e': 'aqab', 'kid': 've...eb8dw6y=', 'kty': 'rsa', 'n': 'hw19h...0c9q', 'use': 'sig' } ] } const decodedjwt = jwt.decode(token, {complete: true}) console.log(decodedjwt) if (decodedjwt.payload.iss !== `https://cognito-idp.us-east-1.amazonaws.com/${cognito_pool_id}`) { ...

xml - Reading specific excel sheet into Python pandas dataframe without loading the whole workbook -

pd.read_excel(filepath, sheetname) , openpyxl.workbook(filepath) load whole workbook. have 30mb file on server , takes long time load. wondering if there method load specific sheet pandas dataframe without opening whole workbook. i have looked couple of methods. recently, converting workbook .zip , reading .xml files. know people have suggested using lxml. i'm not sure how go here. is there better way of doing this?

android - How to add floating action button one by one in Linearlayout -

Image
i'm developing attendance manager app. take attendance , i've create layout this i want make programatically. in below layout i've used add fab using xml. you can use recyclerview gridlayoutmanager achieve programatically, here example: http://abhiandroid.com/materialdesign/recyclerview https://inducesmile.com/android/android-gridlayoutmanager-with-recyclerview-in-material-design/ hope helps.