Categories
Development

Python function to append a list to a key in a dictionary

I have a dictionary with keys. The corresponding value of the key can be a list / dictionary / string. If it is a list, the objective is : append another list( which will be acquired from another dictionary key) to the existing list against the key. If it is a string / dict, the […]

Categories
Development

In python3, using ‘set’ on a zipped object, prevents using ‘list’ on that same object

# initializing lists name = [ “Alice”, “Bob”, “Sam” ] roll_no = [ 4, 1, 3 ] marks = [ 40, 50, 60 ] print(“using zip() to map values”) mapped = zip(name, roll_no, marks) print(“mapped = zip(name, roll_no, marks) “,mapped,”\n”*2 ) print(“FIRST RUN:”) print(“converting values to print as list”) mappedL = list(mapped) print(“mappedL = list(mapped)\n”,mappedL) […]

Categories
Development System & Network

Manage user & open ports with Ansible

I’m getting started with Ansible. I have few hosts in my /etc/ansible/hosts. This file and my playbooks are versioned with git. Members of my team are versioned in git like $cat users/john.json { login: ‘john.johnson’, firstName: ‘John’, lastName : ‘Johnson’, sshPubKey: ‘….’ } I want to grant access to some users to some machine like: […]

Categories
Development

SQLite transaction vs sqlBatch

db.transaction(function(tx) { tx.executeSql(‘CREATE TABLE IF NOT EXISTS DemoTable (name, score)’); tx.executeSql(‘INSERT INTO DemoTable VALUES (?1,?2)’, [‘Alice’, 101]); tx.executeSql(‘INSERT INTO DemoTable VALUES (?1,?2)’, [‘Betty’, 202]); }, function(error) { console.log(‘Transaction ERROR: ‘ + error.message); }, function() { console.log(‘Populated database OK’); }); Can you tell me why should I choose sqlBatch instead of transaction? db.sqlBatch([ ‘CREATE TABLE IF […]

Categories
Development

Tenant wide consent in IdentityServer4

We have an instance of IdentityServer4 running and use it internally for our apps. Those app clients have the property RequireConsent set to false. The result is, you go to the apps website (app1.website), you are redirected to the identity server website (identity.website), where you log in, and redirected back to app1.website. We also allow […]

Categories
Development Python

Repeat calculations by subset of data frame in Python

Looking to obtain a calculation for each user opposed to the whole data frame from df1. import pandas as pd import numpy as np df = pd.DataFrame({‘user’: [‘Mike’, ‘Mike’, ‘Mike’,’Mike’, ‘Mike’, ‘Mike’,’Mike’, ‘Mike’, ‘Mike’,’Mike’,’Mike’, ‘Mike’,’Mike’, ‘Mike’, ‘Mike’,’Mike’,’Mike’, ‘Mike’,’Mike’, ‘Mike’, ‘Mike’, ‘Mike’, ‘Mike’,’Mike’], ‘income’: [47559,70850,60081,73353,52043,69038,55156,54532, 64937,73780,69577,68116,42777,55733,44923,51096, 74317,75160,52160,56356,74077,70007,69407,79659]}) df1 = pd.DataFrame({‘user’: [‘Bob’, ‘Jane’, ‘Alice’,’Bob’, ‘Jane’, ‘Alice’,’Bob’, ‘Jane’, […]

Categories
Development

How to compute different ranges of quantiles of columns in a dataframe based on percentage of missing values?

I’m trying to compute the quantiles of columns A and B from dataframe df but I would like to calculate different quantiles according to the percentage of missing value of these columns. df = pd.DataFrame({‘A’: [‘Bob’, ‘Jane’, ‘Alice’, NA, NA, NA, ‘Rob’, ‘Max’], ‘B’: [‘Example’, NA, NA, ‘Test’, ‘Check’, NA, NA, NA]}) Additionally, since A […]

Categories
Development

Python in worker has different version: environmental variables are set correctly

I’m running a Python script on a Jupyter notebook on Linux Mint. The code is hardly important but here it is (it’s a tutorial for graphframes): import pandas import pyspark from functools import reduce from graphframes import * from IPython.display import display, HTML from pyspark.context import SparkContext from pyspark.sql import SQLContext from pyspark.sql.functions import col, […]

Categories
Development

Lining up people based on tuples inside list

A group of students need to line up for the procession of an event. We only have the information about every pair of students who are next to each other. We use a list of tuples to represent this line-up information: Each element of the list is a tuple that contains the name of a […]

Categories
Development

How to use downloadHandler for the download button create inside shiny datatable?

I created download button inside each row of shiny datatable as shown here. The table is inside one of the shiny module. I wonder which id should be attached to output while using downloadHandler for any of the download button ? I have shown questionable value as XXXXXXXXXXXX in the code below. library(shiny) library(DT) #> […]