text:
Q: SpringBoot JPA repository saveAll throws write conflict in MongoDB I have a Spring Boot application code similar to one given below, it tries to save a list of entities in MongoDB, but I am getting this error:
Exception in thread "Thread-20" org.springframework.data.mongodb.UncategorizedMongoDbException: Command failed with error 112 (WriteConflict): 'WriteConflict error: this operation conflicted with another operation. Please retry your operation or multi-document transaction.' on server 127.X.X.X:XXXXX. The full response is {"errorLabels": ["TransientTransactionError"]
Caused by: com.mongodb.MongoCommandException: Command failed with error 112 (WriteConflict): 'WriteConflict error: this operation conflicted with another operation. Please retry your operation or multi-document transaction.' on server 127.X.X.X:XXXXX. The full response is {"errorLabels": ["TransientTransactionError"]

So, what should I do to avoid this error/exception?
Code:
@Transactional
public synchronized void myMethod(List<MyEntity> myEntities) {
    saveEntities(myEntities);
}

public void saveEntities(List<MyEntity> myEntities) {
    myRepository.saveAll(myEntities);
}

A: Java mongo driver (mongo-driver-sync-4.4.2) supports retry for WriteConflicts error:
ClientSessionImpl.withTransaction(final TransactionBody<T> transactionBody, final TransactionOptions options)
outer:
        while (true) {
            T retVal;
            try {
                startTransaction(options);
                retVal = transactionBody.execute();
            } catch (RuntimeException e) {
                if (transactionState == TransactionState.IN) {
                    abortTransaction();
                }
                if (e instanceof MongoException) {
                    if (((MongoException) e).hasErrorLabel(TRANSIENT_TRANSACTION_ERROR_LABEL)
                            && ClientSessionClock.INSTANCE.now() - startTime < MAX_RETRY_TIME_LIMIT_MS) {
                        continue;
                    }
                }
                throw e;
            }
            if (transactionState == TransactionState.IN) {
                while (true) {
                    try {
                        commitTransaction();
                        break;
                    } catch (MongoException e) {
                        clearTransactionContextOnError(e);
                        if (ClientSessionClock.INSTANCE.now() - startTime < MAX_RETRY_TIME_LIMIT_MS) {
                            applyMajorityWriteConcernToTransactionOptions();

                            if (!(e instanceof MongoExecutionTimeoutException)
                                    && e.hasErrorLabel(UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL)) {
                                continue;
                            } else if (e.hasErrorLabel(TRANSIENT_TRANSACTION_ERROR_LABEL)) {
                                continue outer;
                            }
                        }
                        throw e;
                    }
                }
            }
            return retVal;
        }

Notice if (e.hasErrorLabel(TRANSIENT_TRANSACTION_ERROR_LABEL) redirects logic to outer which is to start the whole block again.
However, Spring Boot doesn't make use of withTransaction to start a transaction, at least as far as I can see from using Transactional annotation.
The only way is to retry at application level. One way is Retryable
@Retryable(
        value = UncategorizedMongoDbException.class,
        exceptionExpression = "#{message.contains('WriteConflict error')}",
        maxAttempts = 12, backoff = @Backoff(delay = 500))

Make sure to apply it on methods that executes database logic only, otherwise, it can cause unwanted behaviour such as repeat certain non-database operation multiple times when WriteConflicts occurred


text:
Q: Объединение прозрачных объектов при наложении и полное экранирование одних другими Вывожу на карту много меток, использую геометрию метки круг (Circle).   Метки имеют прозрачность. При пересечение нескольких меток они наслаиваются друг на друга, в какой-то момент становятся совсем непрозрачными.
Метки выводятся из json представления с помощью geoQuery (ObjectManager по некоторым причинам использовать не могу).
Мне нужно сделать так, чтобы при пересечении метки не наслаивались, а как бы сливались друг с другом, если они одного цвета. Но у меня метки разного цвета и в случае пересечения меток разного цвета нужно, чтобы один цвет перекрывал другой (например есть синяя и красная метка и чтобы та часть красной, которая пересекается с синей была не видна вообще, видна только синняя, а остальная часть красной, которая ни с чем не пересекается была видна).
Идеальный пример того как мне нужно:  https://geo.minsvyaz.ru
Подскажите как такое реализовать

A: Если нужно как в идеальном примере, потребуется:

*

*Добавить подвижный полупрозрачный пейн чуть выше 'areas'.

*Добавлять все круги строго непрозрачными на созданный пейн, с нулевой обводкой, с  необходимым параметром zIndex.

Тогда перекрываться они будут друг другом полностью, а уже результирующий слой будет прозрачным.
Если после потребуется прозрачное наложение, можно будет добавить дополнительный такой пейн и распределять объекты по созданным пейнам.
var newPane = new ymaps.pane.MovablePane(myMap, {zIndex: 210, overflow: 'hidden', css:{opacity: 0.5}});
myMap.panes.append("circlePane", newPane);

myMap.geoObjects.options.set({'fillOpacity': 3, 'strokeWidth': 0, 'pane': 'circlePane'});

var myCircle1 = new ymaps.Circle([[55.76, 37.60], 10000], {}, {
    fillColor: "#FF0000",
    zIndex: 1
}),
myCircle2 = new ymaps.Circle([[55.76, 37.80], 10000], {}, {
    fillColor: "#0000FF",
    zIndex: 0
});

myMap.geoObjects.add(myCircle1).add(myCircle2);

Реализация на jsfiddle: https://jsfiddle.net/Coroner1st/ym1v5qbt/7/

redpajama_set_name: RedPajamaStackExchange


text:
Q: PYODBC to Pandas - DataFrame not working - Shape of passed values is (x,y), indices imply (w,z) I used pyodbc with python before but now I have installed it on a new machine ( win 8 64 bit, Python 2.7 64 bit, PythonXY with Spyder).
Before I used to (at the bottom you can find more real examples):
columns = [column[0] for column in cursor.description]
temp = cursor.fetchall()
data = pandas.DataFrame(temp,columns=columns)

and it would work fine. Now it seems like DataFrame is not able to convert from the data fetched from the cursor anymore. It returns:
Shape of passed values is (x,y), indices imply (w,z)
I kind of see where the issue is. Basically, imagine I fetch only one row. Then DataFrame would like to shape it (1,1), one element only. While I would like to have (1,X) where X is the length of the list.
I am not sure why the behavior changed. Maybe it is the Pandas version I have, or the pyodbc, but updating is problematic. I tried to update some modules but it screws up everything, any method I use (binaries--for the right machine/installation--pip install, easy-install,anything! etc.. which is very frustrating indeed. I would probably avoid Win 8 64 bit from now on for Python).
Real examples:
sql = 'Select * form TABLE'
cursor.execute(sql)
columns = [column[0] for column in cursor.description]
data    = cursor.fetchall()
        con.close()
            results = DataFrame(data, columns=columns)

Returns:
* ValueError: Shape of passed values is (1, 1540), indices imply (51, 1540)
Notice that:
ipdb> type(data)
<type 'list'>
ipdb> np.shape(data)
(1540, 51)
ipdb> type(data[0])
<type 'pyodbc.Row'>

Now, for example, if we do:
ipdb> DataFrame([1,2,3],columns=['a','b','c'])

* ValueError: Shape of passed values is (1, 3), indices imply (3, 3)
and if we do:
ipdb> DataFrame([[1,2,3]],columns=['a','b','c'])

a  b  c
0  1  2  3
However, even trying:
ipdb> DataFrame([data[0]], columns=columns)
*** ValueError: Shape of passed values is (1, 1), indices imply (51, 1)

or
ipdb> DataFrame(data[0], columns=columns)
*** PandasError: DataFrame constructor not properly called!

Please help :) Thanks!

A: As of Pandas 0.12 (I believe) you can do:
import pandas
import pyodbc

sql = 'select * from table'
cnn = pyodbc.connect(...)

data = pandas.read_sql(sql, cnn)

Prior to 0.12, you could do:
import pandas
from pandas.io.sql import read_frame
import pyodbc

sql = 'select * from table'
cnn = pyodbc.connect(...)

data = read_frame(sql, cnn)

A: This is because the cursor returns not a list of tuples but a list of the Row objects, which are similar to tuples, better, actually, but they confuse the pandas dataframe constructor. In the original example, do this before creating the data frame:
for i in range(0,len(temp)):
    temp[i]=tuple(temp[i])


text:
Q: How to set a specific picklist value on crm 4.0? i try to set selected value of my picklist while adding a new account.My code is :
        CrmService service = connectToCrm();
        PropertyCollection Prop = new PropertyCollection();
        DynamicEntity Firma = new DynamicEntity();

        // set table
        Firma.Name = EntityName.account.ToString();

        StringProperty accountName = new StringProperty();
        accountName.Name = "name";
        accountName.Value = aDict["name"].ToString();
        Prop.Add(accountName);

        StringProperty vendorCode = new StringProperty();
        vendorCode.Name = "new_bayikodu";
        vendorCode.Value = aDict["new_bayikodu"].ToString();
        Prop.Add(vendorCode);

        StringProperty VD = new StringProperty();
        VD.Name = "new_taxoffice";
        VD.Value = aDict["new_taxoffice"].ToString();
        Prop.Add(VD);

        StringProperty VN  = new StringProperty();
        VN.Name = "accountnumber";
        VN.Value = aDict["accountnumber"].ToString();
        Prop.Add(VN);

        StringProperty address = new StringProperty();
        address.Name = "address1_line1";
        address.Value = aDict["address1_line1"].ToString();
        Prop.Add(address);

        StringProperty tel = new StringProperty();
        tel.Name = "telephone1";
        tel.Value = aDict["telephone1"].ToString();
        Prop.Add(tel);

        StringProperty accountEmail = new StringProperty();
        accountEmail.Name = "emailaddress1";
        accountEmail.Value = aDict["emailaddress1"].ToString();
        Prop.Add(accountEmail);

        Firma.Properties = Prop;

        Guid CustomerGuid = service.Create(Firma);

Example i want to set city picklist to "istanbul"
can i use a picklistproperty ?

A: Here is a similar question asked in SO: Setting BusinessEntity picklist value using CRM 4.0 webservice
Please note that to set a picklist property on an entity, you need to know the value of the picklist item you wish to choose. This value property is of type integer. You may need to look at the attribute schema from within CRM to get this value. Or alternatively if this customization is going to be installed in multiple organizations and you believe this value might change, then you may need to retrieve the attribute metadata and determine the correct item programmatically based on the name. (This 2nd solution is not ideal as the picklist 'name' could be updated and would therefore break your code).
    PicklistProperty city = new PicklistProperty();
    city.Name = "new_city";
    city.Value = 23; // City Picklist Value for 'istanbul';
    Prop.Add(city);

A: PicklistProperty city = new PicklistProperty();
city.Name = "new_city";
city.Value = new Picklist();
city.Value.Value = 23; // City Picklist Value for 'istanbul';

Then you can use 'city' to set your picklist.


text:
Q: How to best secure s3 file for One User Only I made a dashboard where users can upload files. I want to make it so that users can only have access to S3 urls that are files that they uploaded. How can I achieve this?
The users are application based, meaning they are, in my case, Django users.
Thanks! Anything helps!!

A: As this is entirely application based there are a few steps you could take to try and mitigate against accidental exposure.
Firstly organise your S3 folder structure in a way that uses prefixes for usernames, this way from a hierarchical point of view you can limit the scope of where users objects are stored. By prefix I mean the key might look like this users/$USERNAME/file.txt where $USERNAME is actually the users username.
You could enhance this in in your application by expanding to use Cognito, with a seperate user for every user you have created. When the user logs into your application you could also have the login occur via the Cognito user (this can be done programmatically).
With a successful login you'll be provided temporary credentials for IAM, all users can be assigned to a Cognito group which can have an IAM role attached. When you login it will assume this role, which allows some special properties to be supported in IAM.
By using ${cognito-identity.amazonaws.com:sub} you can actually limit the IAM permissions to only access that prefix of the S3 bucket. This moves responsibility from your application to Cognito and IAM.
More information about this is available in: Amazon S3: Allows Amazon Cognito Users to Access Objects in Their Bucket.


text:
Q: Mongoose-mongoDB advanced query joins I have two models in my database, the Room model and Block model
The room schema
var RoomSchema = new Schema({
  name: String,
  floor: { type: Number, min: 0},
  capacity: { type: Number, min: 0},
  free: { type: Number, min: 0},
  block: {type: mongoose.Schema.Types.ObjectId, ref: 'Block'}
});

the block schema
var BlockSchema = new Schema({
  name: String,
  type: Boolean, // 0->man, 1->woman
  rooms: [{type: mongoose.Schema.Types.ObjectId, ref: 'Room'}]
});

I would like to retrieve all rooms that belong to a block where the type is false (rooms for men),
so if I was to write this in pseduo sql it would be like
select * from rooms
left join blocks on blocks.id = romms.block_id
where blocks.type = false;

filtering the rooms entities just after the query returns, won't work because it would change the pagination data.
Any help is appreciated!!

A: This has to be done as two separate queries in mongodb as it is not a relational database.
First do the blocks query:
db.blocksCollection.find({type : false})

This will return an array of blocks of type false.
This can be used to query the rooms collection for rooms in those blocks, using the $in operator: http://docs.mongodb.org/manual/reference/operator/query/in/
db.roomsCollection.find({block : { $in : [block1,block2,etc...]}})

A: You can do this with a single query when you use Mongoose's populate method which is the process of automatically replacing the specified paths in the document with document(s) from other collection(s). For example, you can populate your block's rooms using the query builder:
var query = { "type": false };
Block.find(query)
     .select('-_id -name -type')
     .poulate('rooms')
     .exec(function (err, res){
        console.log('The first room is %s', res[0].rooms[0].name);
     })


text:
Q: Pandas strftime running slow within multiprocessing I'm seeing a behavior when working with time stamps within pandas DataFrames. The project I'm working on requires I read in data, convert a date string to a date-time object, later the the date-time object is converted back to a string with a different format. I do the conversion using data_frame.dt.strftime(). When I move call my function using a multiprocessing pool, rather than calling it directly, I see a big slowdown when converting from a date-time to string. Below, I include some timing measurements, with and without multiprocessing. The code used to run these tests is at the bottom of the post.
No multiprocessing
Time to read: 0.286389112473
Time to convert to string: 0.160706996918
Total time: 0.4490878582 s

With multiprocessing
Time to read: 0.287585020065
Time to convert to string: 6.90422201157
Total time: 7.23801398277 s

This test shows that there is little difference in the time it takes to read in the DataFrame (converting string to date-time), but converting back out to a string takes much longer when calling from within multiprocessing. Is there a reason for this? Is there a way to work around it?
Edit:
Just to clarify, in this example, I'm intentionally supplying a single process to the multiprocessing pool. I'm interested in the difference in runtime when calling the testing function directly or via multiprocessing.
I certainly expect a small amount of overhead related to transferring data to the worker process, but I'm seeing added inefficiency when processing the DataFrame. That is, when I process the same data, with the same code, providing the same resources, it takes 40x longer to convert the column from date-time objects to strings. I take this hit again if I try and write the DataFrame to a file using to_csv()

My system configuration is the following:

*

*OS: Mac

*Python release: 2.7.11 |Anaconda 2.5.0

*Pandas version: 0.18.1

*Multiprocessing version: 0.70a1

Code to run timing test:
from __future__ import print_function

import time
import pandas as pd
import multiprocessing

# ------------------------------------------------------------------------------
def test_timing(file_name):
    date_format = '%a %b %d %H:%M:%S %Z %Y'
    date_parser = lambda x: pd.to_datetime(x, format=date_format)

    tic = time.time()
    df = pd.read_csv(file_name,
                     names=['date_time'],
                     parse_dates=['date_time'],
                     date_parser=date_parser,
                     nrows=50000)
    print('Time to read: {}'.format(time.time() - tic))

    tic = time.time()
    date_format = '%Y-%m-%d'
    df['date'] = df['date_time'].dt.strftime(date_format)
    print('Time to convert to string: {}'.format(time.time() - tic))

    return df

# ------------------------------------------------------------------------------
print('No multiprocessing')
tic = time.time()
df = test_timing('sample_data.csv')
# print(df.head())
print('Total time: {} s'.format(time.time() - tic))
print()

# ------------------------------------------------------------------------------
print('With multiprocessing')
tic = time.time()
pool = multiprocessing.Pool(1)
df = pool.map(test_timing, ['sample_data.csv'])
# print(df[0].head())
print('Total time: {} s'.format(time.time() - tic))


text:
Q: Stepper motor stalling when ramping down and then back up? I'm driving a NEMA34 bipolar geared stepper motor with the following specifications: Rated Current 4A, Voltage 24-60V. It is being driven by a MA860H driver with output current of 2.6-7.2A 24-80VAC. I have the driver configured for a peak current of 4.45A, and using a microstep of 5 (1000 pulses / rev). This is connected to a gearbox that results in an input of around ~4000 steps / rev.
(http://www.leadshine.com/UploadFile/Down/MA860m.pdf)
The driver is being controlled by a PLC that drives the stepper motor to a desired position. The motion control allows for a desired position, steps/second, and a ramp up/down time (ms).
This particular use case requires a new motion command to be issued while the motor may be in travel. There are no issues if i move the motor from standstill, or issue a new move command while the motor has reached its max steps/second.
However, if the motor is moving, and is nearing its desired position, it will begin to ramp down, if during this ramp a new move command is issued with an increased desired position, the motor should ramp back up and continue to move. Instead, the motor will seize up and makes a high pitch squeal. The longer i set the ramp-up/down time the easier this condition is to reproduce. Oddly enough if i perform the same function but the new move command tells the motor to reverse, this condition does not occur.
I'm not sure what the exact issue i am facing, or how to narrow it down to a particular component. Could it be counter EMF from the motor that is causing the strange behavior, or have i sized the motor incorrectly?

A: The problem of course is in the PLC trajectory generator. The stepper driver itself only outputs the setpoint frequency (step/dir) to the motor. It seems that upon changing the setpoint position, your PLC program doesn't gradually decrease or increase the frequency, rather it jumps. Look for PLC documentation how to overcome this bug.


text:
Q: Postfix: reject_unknown_client_hostname doesn't effect in main.cf, nor in master.cf I'm trying to set smtpd_client_restrictions = reject_unknown_client_hostname to prevent a lot of spam connections, like postfix/smtpd[28054]: connect from unknown[185.143.72.16].
I set this value in main.cf and master.cf, then restart dovecot and postfix services, but it doesn't effect at all. Am I miss something?
The smtpd_client_restrictions value is existing in my master.cf file:
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject

I modified it like this:
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject_unknown_client_hostname,reject

Unfortunately without any positive result. The mail.info log says nothing special.
master.cf:
#
# Postfix master process configuration file.  For details on the format
# of the file, see the master(5) manual page (command: "man 5 master" or
# on-line: http://www.postfix.org/master.5.html).
#
# Do not forget to execute "postfix reload" after editing this file.
#
# ==========================================================================
# service type  private unpriv  chroot  wakeup  maxproc command + args
#               (yes)   (yes)   (no)    (never) (100)
# ==========================================================================
smtp      inet  n       -       y       -       -       smtpd
smtps     inet  n       -       y       -       -       smtpd
  -o syslog_name=postfix/smtps
  -o smtpd_tls_wrappermode=yes
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_enforce_tls=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject

pickup    unix  n       -       y       60      1       pickup
cleanup   unix  n       -       y       -       0       cleanup
qmgr      unix  n       -       n       300     1       qmgr
tlsmgr    unix  -       -       y       1000?   1       tlsmgr
rewrite   unix  -       -       y       -       -       trivial-rewrite
bounce    unix  -       -       y       -       0       bounce
defer     unix  -       -       y       -       0       bounce
trace     unix  -       -       y       -       0       bounce
verify    unix  -       -       y       -       1       verify
flush     unix  n       -       y       1000?   0       flush
proxymap  unix  -       -       n       -       -       proxymap
proxywrite unix -       -       n       -       1       proxymap
smtp      unix  -       -       y       -       -       smtp
relay     unix  -       -       y       -       -       smtp
showq     unix  n       -       y       -       -       showq
error     unix  -       -       y       -       -       error
retry     unix  -       -       y       -       -       error
discard   unix  -       -       y       -       -       discard
local     unix  -       n       n       -       -       local
virtual   unix  -       n       n       -       -       virtual
lmtp      unix  -       -       y       -       -       lmtp
anvil     unix  -       -       y       -       1       anvil
scache    unix  -       -       y       -       1       scache
maildrop  unix  -       n       n       -       -       pipe
  flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}

uucp      unix  -       n       n       -       -       pipe
  flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
#
# Other external delivery methods.
#
ifmail    unix  -       n       n       -       -       pipe
  flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
bsmtp     unix  -       n       n       -       -       pipe
  flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient
scalemail-backend unix  -   n   n   -   2   pipe
  flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
mailman   unix  -       n       n       -       -       pipe
  flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py
  ${nexthop} ${user}

policyd-spf  unix  -       n       n       -       0       spawn
    user=policyd-spf argv=/usr/bin/policyd-spf

main.cf
# See /usr/share/postfix/main.cf.dist for a commented, more complete version

# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# See http://www.postfix.org/COMPATIBILITY_README.html -- default to 2 on
# fresh installs.
compatibility_level = 2

# TLS parameters
smtpd_tls_cert_file = /etc/letsencrypt/live/mail.blogginger.com/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/mail.blogginger.com/privkey.pem
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination,check_policy_service unix:private/policyd-spf,reject_invalid_hostname,reject_non_fqdn_hostname,reject_non_fqdn_sender,reject_non_fqdn_recipient,reject_unknown_sender_domain
smtpd_client_restrictions = reject_unknown_client_hostname
myhostname = mail.blogginger.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = blogginger.com
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_command =
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
home_mailbox = Maildir/
mydomain = blogginger.com
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous
smtp_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_sasl_auth_enable = yes
milter_default_action = accept
milter_protocol = 6
smtpd_milters = local:/opendkim/opendkim.sock
non_smtpd_milters = $smtpd_milters

smtp_tls_security_level = may
smtpd_tls_security_level = may
smtp_tls_note_starttls_offer = yes
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
virtual_alias_maps = hash:/etc/postfix/virtual

policyd-spf_time_limit = 3600
disable_vrfy_command=no
smtpd_client_connection_rate_limit = 20
smtpd_error_sleep_time             = 10s
smtpd_soft_error_limit             = 3
smtpd_hard_error_limit             = 5
smtpd_tls_auth_only = yes

A: You don't seem to have defined any IPs to permit or reject.
From the postix manual (http://www.postfix.org/access.5.html):
This example permits access by  the client at address 1.2.3.4 but rejects all other clients in 1.2.3.0/24.
/etc/postfix/main.cf:
smtpd_client_restrictions =
  check_client_access hash:/etc/postfix/access

/etc/postfix/access:
1.2.3   REJECT
1.2.3.4 OK

Execute  the  command  "postmap  /etc/postfix/access" after editing the file.


text:
Q: rails: has_and_belongs_to_many not saving associated objects (null in join table) Rails 4. I got an Authentication model
class Authentication < ActiveRecord::Base
  ...
  has_and_belongs_to_many :posting_groups
  ...
end

and a PostingGroup model
class PostingGroup < ActiveRecord::Base
  ...
  has_and_belongs_to_many :authentications
  ...
end

The migration for the join table look like this:
def change
  create_table :authentications_posting_groups, id: false do |t|
    t.belongs_to :posting_group
    t.belongs_to :authentication
  end
end

Neither the Authentication nor the PostingGroup tables need references to each other or to the join table, so there's no relevant information in them. When updating the PostingGroups of an Authentication I do the following:
def update
  @authentication.update_attributes(authentication_params)
end
def authentication_params
    params.require(:other_unimportant_stuff, posting_groups: [])
end

During the execution of the update action, params is as follows:

{"authentication"=>{"posting_groups"=>["17", "18"]},
  "stuff"=>"more stuff}

...where, 17 and 18 are the ids of the posting groups which should be saved. And, indeed, the @authentication variable in update contains the desired PostingGroups and update_attributes returns true. However, Authentication.find(id).posting_groups (i.e. what actually was stored in the db) returns an empty set. Additionally, checking the authentications_posting_groups table shows the following:
posting_group_id    authentication_id
              17    NULL
              18    NULL

For some weird reason the authentication_id is never making it to the db, which is funny because the save was triggered on this object in the first place. It's not the first time I encounter this problem but rather the second, the first time we noticed that everything worked fine (that is, those NULL didn't pop up in the db) when creating what in this scenario is the Authentication, but the same happened on update. On that occasion a hack was implemented re-creating the object (on create everything is OK!!), but here that's not an option. I'd immensely appreciate any pointers because this is driving us mad. Thanks.
Edit - here's the form which is triggering the whole thing:
= form_for authentication, remote: true do |f|
  = f.select :posting_groups, options_for_select(@posting_groups.map {|pg| [ pg.name, pg.id ] }), {}, multiple: true, class: "form-control posting_groups_select"

A: You should permit posting_group_ids and pass posting_group_ids
Controller
def update
  @authentication.update_attributes(authentication_params)
end
def authentication_params
    params.require(:other_unimportant_stuff, posting_group_ids: [])
end

View
= form_for authentication, remote: true do |f|
  = f.select :posting_group_ids, options_for_select(@posting_groups.map {|pg| [ pg.name, pg.id ] }), {}, multiple: true, class: "form-control posting_groups_select"

A: params.require(:other_unimportant_stuff, posting_group_ids: [])

Notice the ids.
You're passing in posting_group_ids as per your params but your parameters are set to posting_groups so strong parameters will filter it out.


text:
Q: Fatal Error in MPI_Irecv: Aborting Job The following sequence of errors is received when I try to run a problem on four processors. The MPI command I use is mpirun -np 4
I apologize for posting the error message as is (Primarily due a lack of knowledge on deciphering the information given). Would appreciate your input on the following:

*

*What does the error message mean? At what point does one receive it? Is it because of the system memory (hardware) or is it due to a communication error (something related to MPI_Isend/Irecv?, i.e. Software issue).

*Finally, how do I fix this?
Thanks!
ERROR message received follows below:: - -
*PLEASE NOTE: This error is received only when the time is large*.
Code computes fine when time required to compute data is small (i.e, 300 time steps compared to 1000 time steps)
aborting job:
Fatal error in MPI_Irecv: Other MPI error, error stack:
MPI_Irecv(143): MPI_Irecv(buf=0x8294a60, count=48, MPI_DOUBLE, src=2, tag=-1, MPI_COMM_WORLD, request=0xffffd68c) failed
MPID_Irecv(64): Out of memory
aborting job:
Fatal error in MPI_Irecv: Other MPI error, error stack:
MPI_Irecv(143): MPI_Irecv(buf=0x8295080, count=48, MPI_DOUBLE, src=3, tag=-1, MPI_COMM_WORLD, request=0xffffd690) failed
MPID_Irecv(64): Out of memory
aborting job:
Fatal error in MPI_Isend: Internal MPI error!, error stack:
MPI_Isend(142): MPI_Isend(buf=0x8295208, count=48, MPI_DOUBLE, dest=3, tag=0, MPI_COMM_WORLD, request=0xffffd678) failed
(unknown)(): Internal MPI error!
aborting job:
Fatal error in MPI_Irecv: Other MPI error, error stack:
MPI_Irecv(143): MPI_Irecv(buf=0x82959b0, count=48, MPI_DOUBLE, src=2, tag=-1, MPI_COMM_WORLD, request=0xffffd678) failed
MPID_Irecv(64): Out of memory
rank 3 in job 1  myocyte80_37021   caused collective abort of all ranks
  exit status of rank 3: return code 13
rank 1 in job 1  myocyte80_37021   caused collective abort of all ranks
  exit status of rank 1: return code 13
EDIT:
    (SOURCE CODE)
Header files
Variable declaration
TOTAL TIME =
...
...
double *A = new double[Rows];
double *AA = new double[Rows];
double *B = new double[Rows;
double *BB = new double[Rows];
....
....
int Rmpi;
int my_rank;
int p;
int source;
int dest;
int tag = 0;
function declaration

int main (int argc, char *argv[])
{
MPI_Status status[8];
MPI_Request request[8];
MPI_Init (&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &p);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);

//PROBLEM SPECIFIC PROPERTIES. VARY BASED ON NODE
if (Flag = 1)
{
if (my_rank == 0)
{
Defining boundary (start/stop) for special elements in tissue (Rows x Column)
}
if (my_rank == 2)
..
if (my_rank == 3)
..
if (my_rank == 4)
..
}

//INITIAL CONDITIONS ALSO VARY BASED ON NODE
for (Columns = 0; Columns<48; i++) // Normal Direction
{
for (Rows = 0; Rows<48; y++)  //Transverse Direction
{
if (Flag =1 )
{
if (my_rank == 0)
{
Initial conditions for elements
}
if (my_rank == 1) //MPI
{
}
..
..
..
//SIMULATION START

while(t[0][0] < TOTAL TIME)
{
for (Columns=0; Columns ++) //Normal Direction
{
for (Rows=0; Rows++) //Transverse Direction
{
//SOME MORE PROPERTIES BASED ON NODE
if (my_rank == 0)
{
if (FLAG = 1)
{
Condition 1
}
 else
{
Condition 2
}
}

if (my_rank = 1)
....
 ....
  ...

//Evaluate functions (differential equations)
Function 1 ();
Function 2 ();
...
...

//Based on output of differential equations, different nodes estimate variable values. Since
 the problem is of nearest neighbor, corners and edges have different neighbors/ boundary
 conditions
if (my_rank == 0)
{
If (Row/Column at bottom_left)
{
Variables =
}

if (Row/Column at Bottom Right)
{
Variables =
}
}
...
 ...

 //Keeping track of time for each element in Row and Column. Time is updated for a certain
 element.
 t[Column][Row] = t[Column][Row]+dt;

  }
  }//END OF ROWS AND COLUMNS

 // MPI IMPLEMENTATION. AT END OF EVERY TIME STEP, Nodes communicate with nearest neighbor
 //First step is to populate arrays with values estimated above
 for (Columns, ++)
 {
 for (Rows, ++)
 {
 if (my_rank == 0)
 {
 //Loading the Edges of the (Row x Column) to variables. This One dimensional Array data
 is shared with its nearest neighbor for computation at next time step.

 if (Column == 47)
 {
 A[i] = V[Column][Row];
 …
 }
 if (Row == 47)
 {
 B[i] = V[Column][Row];
 }
 }

...
...

 //NON BLOCKING MPI SEND RECV TO SHARE DATA WITH NEAREST NEIGHBOR

 if ((my_rank) == 0)
 {
 MPI_Isend(A, Rows, MPI_DOUBLE, my_rank+1, 0, MPI_COMM_WORLD, &request[1]);
 MPI_Irecv(AA, Rows, MPI_DOUBLE, my_rank+1, MPI_ANY_TAG, MPI_COMM_WORLD, &request[3]);
 MPI_Wait(&request[3], &status[3]);
 MPI_Isend(B, Rows, MPI_DOUBLE, my_rank+2, 0, MPI_COMM_WORLD, &request[5]);
 MPI_Irecv(BB, Rows, MPI_DOUBLE, my_rank+2, MPI_ANY_TAG, MPI_COMM_WORLD, &request[7]);
 MPI_Wait(&request[7], &status[7]);
 }

if ((my_rank) == 1)
{
MPI_Irecv(CC, Rows, MPI_DOUBLE, my_rank-1, MPI_ANY_TAG, MPI_COMM_WORLD, &request[1]);
MPI_Wait(&request[1], &status[1]);
MPI_Isend(Cmpi, Rows, MPI_DOUBLE, my_rank-1, 0, MPI_COMM_WORLD, &request[3]);

MPI_Isend(D, Rows, MPI_DOUBLE, my_rank+2, 0, MPI_COMM_WORLD, &request[6]);
MPI_Irecv(DD, Rows, MPI_DOUBLE, my_rank+2, MPI_ANY_TAG, MPI_COMM_WORLD, &request[8]);
MPI_Wait(&request[8], &status[8]);
}

if ((my_rank) == 2)
{
MPI_Isend(E, Rows, MPI_DOUBLE, my_rank+1, 0, MPI_COMM_WORLD, &request[2]);
MPI_Irecv(EE, Rows, MPI_DOUBLE, my_rank+1, MPI_ANY_TAG, MPI_COMM_WORLD, &request[4]);
MPI_Wait(&request[4], &status[4]);

MPI_Irecv(FF, Rows, MPI_DOUBLE, my_rank-2, MPI_ANY_TAG, MPI_COMM_WORLD, &request[5]);
MPI_Wait(&request[5], &status[5]);
MPI_Isend(Fmpi, Rows, MPI_DOUBLE, my_rank-2, 0, MPI_COMM_WORLD, &request[7]);
}

if ((my_rank) == 3)
{
MPI_Irecv(GG, Rows, MPI_DOUBLE, my_rank-1, MPI_ANY_TAG, MPI_COMM_WORLD, &request[2]);
MPI_Wait(&request[2], &status[2]);
MPI_Isend(G, Rows, MPI_DOUBLE, my_rank-1, 0, MPI_COMM_WORLD, &request[4]);

MPI_Irecv(HH, Rows, MPI_DOUBLE, my_rank-2, MPI_ANY_TAG, MPI_COMM_WORLD, &request[6]);
MPI_Wait(&request[6], &status[6]);
MPI_Isend(H, Rows, MPI_DOUBLE, my_rank-2, 0, MPI_COMM_WORLD, &request[8]);
}

 //RELOADING Data (from MPI_IRecv array to array used to compute at next time step)
 for (Columns, ++)
 {
 for (Rows, ++)
 {
 if (my_rank == 0)
 {
 if (Column == 47)
 {
 V[Column][Row]= A[i];
 }
 if (Row == 47)
 {
 V[Column][Row]=B[i];
 }
  }

  ….
 //PRINT TO OUTPUT FILE AT CERTAIN POINT
 printval = 100;
 if ((printdata>=printval))
 {
 prttofile ();
 printdata = 0;
 }
 printdata = printdata+1;
 compute_dt ();

 }//CLOSE ALL TIME STEPS

 MPI_Finalize ();

  }//CLOSE MAIN

A: Are you repeatedly calling MPI_Irecv?  If so, you may not realize that each call allocates a request handle - and these are freed when the message is received and tested for completion with (eg.) MPI_Test.  It's possible you could exhaust memory with over-use of MPI_Irecv - or the memory assigned by an MPI implementation for this purpose.
Only seeing the code would confirm the problem.

A: Now that the code has been added to the question: this is indeed dirty code. You only wait for the request from the Irecvcall. Yes, if the message is received you know that the send has completed, so you don't have to wait for it. But skipping the wait gives a memory leak: the Isend allocates a new request, which the Wait would deallocate. Since you never wait, you don't deallocate and you have a memory leak.


text:
Q: Strange behavior in chrome (using a gameloop) with canvas I have the following code:
    var gameStateRender = function (game) {

    var t = new Date();
    /* time passed since last frame */
    game.timePassed = t.getTime() - game.timeFrameStart;
    /* time when frame starts */
    game.timeFrameStart = t.getTime();
    /* time passed total */
    game.timeTotal += game.timePassed;
    game.update();
    game.draw();
    };

    /* set the default game-state */
    var gameState = gameStateRender;

I use requestAnimFrame and a fallback (setTimeout) with 60 fps.
    window.requestAnimFrame = (function () {

    return  window.requestAnimationFrame    ||
    window.webkitRequestAnimationFrame  ||
    window.mozRequestAnimationFrame     ||
    window.oRequestAnimationFrame       ||
    window.msRequestAnimationFrame      ||
    function(callback) {

    window.setTimeout(callback, 1000 / game.fps);
    };
    })();

    (function gameloop () {

    requestAnimFrame(gameloop);
    gameState(game);

    })();

The game runs smooth in FF, IE9 and has a constant frame-rate of ~60 fps.
In chrome the game also has ~60 fps, but stutters. Some facts:

*

*While I move the mouse in chrome, the whole animation is smooth and when I stop moving the mouse the animation starts to stutter. The game always has ~60 fps (while I move the mouse and while not).

*While I use console.log(...), the game runs smoothly, without printing stuff to the console, the game is stuttering again. (???)
var gameStateRender = function (game) {

var t = new Date();
/* time passed since last frame */
game.timePassed = t.getTime() - game.timeFrameStart;
/* time when frame starts */
game.timeFrameStart = t.getTime();
/* time passed total */
game.timeTotal += game.timePassed;

console.log(game.timeTotal);

game.update();
game.draw();
};

While I run the above code, the animation is smooth.
The game has in fact, always a frame-rate of ~60 (16ms per frame), which I've verified.
Has anyone had this (strange) behavior before? Sounds pretty strange to me.


text: Q: How can I receive browser notifications from Stackoverflow from changes in questions I am active in? I would like to receive browser notifications for all regular alerts (points, new message replies) as well as for new questions (but for defined tags only). Is that possible? I can't find any documentation regarding such thing.


text:
Q: Meteor for each on template? In jQuery I have the following:
var dis = $('.dis').children();
for (var i = 0; i <= dis.length; i++){
$(dis.find('.somediv')[i]).text(funk.list[i].api.response);}

I am trying to change the formatting of my code to be reactive with Meteor. To that end, I am trying to convert my code like so:
this.mete = new ReactiveVar();
var self = this;
self.mete[i].set('funk.list[i].api.response');

The gist of all of this is that, in my jQuery code, I have a for-each loop that needs to be reflected in the [i] tags surrounding each div.
My HTML is something like so:

The self.mete[i].set does not accomplish this. I would like to know how to go about this. Also, I understand that, in Meteor, the HTML would look something more like:

{{mete}}

{{mete}}

A: You probably want something like this:
Template.mytemplate.onCreated(function(){
    this.mete = new ReactiveVar();
    var self = this;
    self.mete.set(YourListHere); //assuming your list is an array of object like {api: {response: "some response"}}
});
Template.mytemplate.helper({
   "myList": function() {
      return Template.instance().mete.get();
   }
});

and in the template:
{{#each myList}}

{{this.api.response}}

{{/each}}


text:
Q: Should I use an Observable or a BindingList for exposing changing data that I want to put into a UI I'm trying to get myself into using Rx (Xamarin Forms) in a ViewModel first approach. What I'm slightly unsure about is the best way of exposing changing information that my data model needs to provide to the view models.
I have a service that provides my client a snapshot of data and then provides updated events via signalr that indicate add, update and remove. I've written an application wrapper for my client data model that logs in, manages state and general connectivity and has a local database (SqlLite in my case).
What I would like is to expose the data on my application wrapper with changing events so that I can then bind to the events and create an observable collection that I can then use in WPF/Xamarin.
I can use Rx for this or more traditional approaches such as BindingList. I'm finding it hard to decide what I should do. My use case is this:

*

*I want to get a full list of all of my local items after login

*I want to be notified of changes (adds, updates and removes) and react

*I want to convert the above into view models and an observable collection as appropriate.

I would want to be able to subscribe to a given collection and get all of the entries currently local to me, but to also monitor changes that could happen via SignalR. Should this be Rx? Or should I hide Rx behind a BindingList (for example).
So is it:
IObservable<MyOrder> Orders { get; } // What kind of subject?

Or
BindingList<MyOrder> Orders { get; }

Or something else?
And if its the Rx one, what should I do to make sure that each subscriber gets the current orders list and then gets changes?

A: On the ViewModel you want to expose your data as state. So ViewModels that implement INotifyPropertyChanged or expose readonly properties that themselves expose INPC (INotifyPropertyChanged) is good. In this case the VM (ViewModel) would have an Orders property
BindingList<MyOrder> Orders { get; }

Then the VM I would think would subscribe to an Observable Sequence of change notifications. This sounds like your SignalR channel provides you this already. In previous projects we conflated Add/Insert and Update into a single "upsert" message, and then had Remove/Delete and Clear/Reset messages too.
The difficulty you will get by trying to manage state locally is the "State of the World" problem. If you try to get the current snapshot first, then subscribe to live values, you can miss a value while reading the snapshot. If however, you subscribe first then get the snapshot, you may receive a value twice. In this case you will also have to deal with queuing the live data until you have processed the snapshot.
With this in mind, you can either try to move everything to a single threaded and predictable sequence model, or just get something else that does this for you (Akavache?). If you do think it is worth doing yourself, then it is probably worth trying a model that uses checkpoints/sequenceIds, so the client can just resubscribe from a known point. This will allow the service to either give them just the recent changes, or a full snapshot if their checkpoint is suffciently stale.
So, yeah expose it as an
IObservable<ChangeNotification<MyOrder>> OrderChanges { get;}

Where ChangeNotification conveys either an Upsert (with new items), Deletion (with ids/keys to delete) or Reset.
You wont use a subject anywhere if it is done properly ;-)


text:
Q: If you paid attention, you'll do well As I was watching The Affair, I came across a dialogue which seems poor English to me. The dialogue is spoken by a person who is a native American in the series. The dialogue is as follows:

If you paid attention in class, and done the work, you'll do well.

First, why is done used here and not did even though there is no had in the conditional sentence?
And secondly, why the result/outcome of the conditional sentence is in future tense (you'll)?

A: It's a mess of a sentence, as you surmise.
Here are the possibilities, depending on the context:
At the start of the year, the teacher advises the pupils:

If you pay attention in class and do the work, you will do well.

Before the exam, the teacher says:

If you have paid attention in class and done the work, you will do well.

Also possible:

If you paid attention in class and did the work, you would do well.

After the exam, the teacher advises a disappointed pupil:

If you had done the work and paid attention in class, you would have done well.

A: While I'm not certain what the correct grammar is here, I would like to point out that this show very well could be using poor English on purpose. It is very common in television to portray Native Americans as poor English speakers--at least it was in older shows. So that is a possibility.


text:
Q: Perform multiple actions in same time I want to perform multiple loops in the same time using async Task (I don't want use Parallel.ForEach)
I do :
static async void Run()
{
    await MultiTasks();
}

static async Task MultiTasks()
{
    var Loop1 = Loop1Async();
    var Loop2 = Loop2Async();

    await Loop1;
    await Loop2;
}

static async Task Loop1Async()
{
    for (int i = 0; i < 500; i++)
    {
        Console.WriteLine("Loop 1 : " + i);
    }
}

static async Task Loop2Async()
{
    for (int i = 0; i < 500; i++)
    {
        Console.WriteLine("Loop 2 : " + i);
    }
}

Run() is called in my Main method.
But the two loop is not executed in the same time. Once the first lap is completed, the second begins
Why and how to do this ?

A: You have the fundamental misunderstanding common to beginner users of await.
Let me be very clear about this.  Await does not make something asynchronous.  It asynchronously waits for an asynchronous operation to complete.
You are awaiting a synchronous operation. There is absolutely nothing asynchronous about the methods you are calling; await does not make them asynchronous. Rather, if they were asynchronous, then the await would return control to the caller immediately, so that the caller could continue to do work.  When the asynchronous work finishes, then at some point in the future the remainder of the method is executed, with the awaited result.

A: Try .WhenAll(...)
static async Task MultiTasks()
{
    var Loop1 = Loop1Async();
    var Loop2 = Loop2Async();

    await Task.WhenAll(Loop1, Loop2);
}

As others have noted your async methods do not currently yield execution.
You need something that will allow threads to yield back to the system so they can actually run in parallel. Something like this...
static async Task Loop1Async()
{
    for (int i = 0; i < 500; i++)
    {
        Console.WriteLine("Loop 1 : " + i);
        await Task.Yield();
    }
}

static async Task Loop2Async()
{
    for (int i = 0; i < 500; i++)
    {
        Console.WriteLine("Loop 2 : " + i);
        await Task.Yield();
    }
}

A: Loop1Async and Loop2Async in fact are synchronous. Consider using WriteLineAsync method.
You can also use Task.WhenAll in MultiTasks.

A: Your Loop1Async and Loop2Async methods does not have an await inside. For a method to be async it needs to have 1 or more await


text:
Q: How to make toeplitz matrix constraint in cvxpy? Using cvxpy( convex optimisation solver in python), there are options to make a matrix variable to be symmetric or positive semidefinite, but I require that the matrix be toeplitz (all left to right diagonals have the same element is each diagonal entry). Is there an efficient way of doing this?

A: One way would be to add the constraint:
a[i,j] = a[i-1,j-1]

for all i,j>0. The presolver (part of a solver) would exploit this and reduce the size of the model.


text:
Q: how to go from windows 10 enterprise (unactivated) to windows 10 pro using windows 8.1 pro keys I have windows 10 enterprise on a laptop. This is not activated and I want to change to windows 10 pro using my windows 8 pro keys.
TIA,
PS

A: You have to have upgraded from Windows 8 with the system already activated using those keys in order to activate the free Windows 10 Upgrade. It sounds as though you have done a fresh installation of Windows 10. Your best bet is to reinstall the original OS and do activate the product then proceed with the upgrade process.


text:
Q: JSON Data conversion client or server side I'm working on a project where sever is sending one format of json response .
Consider I have x pages and for each page I need to convert the json to accommodate UI needs.
Approaches:

*

*format the JSON on server side as per UI

*format the JSON on UI side

Please guide me Which approach would be better with some pros and cons .

A: You should always stick with the server-side rendering as possible for the following reasons,

*

*A server-side rendered application enables pages to load faster, improving the user experience.

*When rendering server-side, search engines can easily index and crawl content because the content can be rendered before the page is loaded, which is ideal for SEO.

*Webpages are correctly indexed because web browsers prioritize web pages with faster load times.

*Rendering server-side helps efficiently load webpages for users with a slow internet connection or outdated devices.


text:
Q: I do not know why my implementation of this scroll bar will not work I am making an image deepfryer and need a scrollbar because if the image is bigger than 500x500, then the download button will not display as the image takes up the entire window.
I tried the following implementation and it did not work
function to display the given image using Tkinter
def display_image(image):
    # convert the image to Tkinter format
    image = ImageTk.PhotoImage(image)

    # create a canvas with a scrollbar
    canvas = tk.Canvas(root, width=500, height=500)
    canvas.pack(side="left", fill="both", expand=True)

    scrollbar = tk.Scrollbar(root, orient="vertical", command=canvas.yview)
    scrollbar.pack(side="right", fill="y")

    canvas.configure(yscrollcommand=scrollbar.set)
    canvas.bind("<Configure>", lambda e: canvas.configure(scrollregion=canvas.bbox("all")))

    # display the image in the canvas
    canvas_image = canvas.create_image(0, 0, anchor="nw", image=image)
    canvas.config(scrollregion=canvas.bbox("all"))

    # add a button to save the image
    save_button = tk.Button(canvas, text="Save", command=lambda: save_image(image))
    canvas.create_window(10, 10, anchor="nw", window=save_button)

A: Your scrollbars need to have the Frame as a canvas, not the    root.
This is what you see my example as I so workaround. The scrollbar is activated That you can see.
Snippet:
import tkinter as tk

root=tk.Tk()

image = tk.PhotoImage(file='p1.png')
def display_image(image):

    # convert the image to Tkinter format

    # create a canvas with a scrollbar
    canvas = tk.Canvas(root, width=500, height=500)
    canvas.pack(side="left", fill="both", expand=True)

    scrollbar = tk.Scrollbar(canvas, orient="vertical", command=canvas.yview)
    scrollbar.pack(side="right", fill="y")

    canvas.configure(yscrollcommand=scrollbar.set)
    canvas.bind("<Configure>", lambda e: canvas.configure(scrollregion=canvas.bbox("all")))

    # display the image in the canvas
    canvas_image = canvas.create_image(0, 0, anchor="nw", image=image)
    canvas.config(scrollregion=canvas.bbox("all"))

    # add a button to save the image
    save_button = tk.Button(canvas, text="Save").pack()
    canvas.create_window(10, 10, anchor="nw", window=save_button)

display_image(image)

root.mainloop()

Screenshot:


text:
Q: SQL Server Group By I have a table that contains a reference and a name. There are some issues with the data whereby there are more than 2 distinct names for a reference which isn't allowed.
Is there a quick query I can write to find all references that have more than 1 associated name?
Sorry, just to clarify:
I can have many names, and many references but only one name associated with each reference. If there are 2 different names associated with a single reference, I need to show these.

A: You can group it by referenceand then select all the entries that have more than one:
select reference, count(*)
from myTable
group by reference
having count(*) > 1;

A: Query:
SELECT reference, COUNT(name)
FROM @table
GROUP BY reference
HAVING COUNT(name) > 1

Sample data:
declare @table table(reference varchar(5), name int)
INSERT INTO @table values('Ref#1', 1)
INSERT INTO @table values('Ref#1', 2)
INSERT INTO @table values('Ref#2', 3)
INSERT INTO @table values('Ref#2', 3)
INSERT INTO @table values('Ref#3', 4)

Output:
| Ref#1 | 2 |
| Ref#2 | 2 |

A: I managed it like this:
SELECT ref, COUNT(name)
FROM table
GROUP BY ref
HAVING COUNT(DISTINCT(name)) > 1

A: Well, if the minimal name and maximal name for a particular reference are different, then there must be at least two names associated with that reference:
SELECT Reference, MIN(Name), MAX(Name)
FROM Table
GROUP BY Reference
HAVING MIN(Name) < MAX(Name)


text:
Q: Airflow Xcom: How to cast byte array for value into text or json text in SQL? I'm investigating which data processing jobs are taking longer over their respective use over time (for installations of our system where it's been running for many months).  The sizes of the data files it processes varies in size up to a few orders in magnitude, so I want to normalize the comparison between the processing times, and the number of records in the payload which is locked inside an XCOM variable value.
I would like to build a SQL view that I can use to correlate the processing duration (end-start), vs. file size vs. execution date, to see how stable the processing is over it's life cycle.
In documentation online, there's examples about serializing into JSON for Python, but, our metadata store for Airflow is in PostGres, and I want to create a SQL view that can provide metrics that associated statistics from processing the dags/tasks and associate metadata from the processing itself nested inside XCOM values.
Does anyone now how to cast XCOM byte value into something parseable in PostGres SQL?

A: I'm facing the same issue. After digging through airflow source, found this:
https://github.com/apache/airflow/blob/2bea3d74952d0d68d90e8bbc307ac3dfe8fcf2ff/airflow/models/xcom.py#L221]
When setting an XCOM variable in the database it will serialize it. In airflow.cfg  there is a setting enable_xcom_pickling = True.
if conf.getboolean('core', 'enable_xcom_pickling'):
    return pickle.dumps(value)

Looks like the byte array is getting pickled and then stored. This is annoying because I don't think there is a way to unpickle the byte array straight from postgres.
There is also another flag you can set called donot_pickle = False. Not sure what this does yet - looking into it more

A: You should be able to create a python user defined function in postgres in which you can unpickle the value, manipulate it further if you need, and then return it to SQL.
Psuedo code udf definition:
CREATE FUNCTION pyunpickle (a varchar)
  RETURNS varchar
AS $$
  from pickle import loads
  return loads(a)
$$ LANGUAGE plpython3u;

https://www.postgresql.org/docs/current/plpython-funcs.html


text:
Q: Wix installer not picking up the installation path I am completely new to WIX and just trying to debug an issue.
I have a text box for installation path but when user chooses a new installation directory, WIX doesn't pick it up and doesn't install it in that path.
What are the areas I should be even looking into?
Here is something in the Bundle I saw:
<DirectoryRef Id="INSTALLDIR">
  <Component Id="cmpOnlineSupport.url" Guid="{somethingHere}">
    <File Id="filOnlineSupport.url" Source="$(var.ResourcesDir)\Online Support.url" KeyPath="yes"/>
  </Component>
</DirectoryRef>


text:
Q: How Commit works in a transactional push replication with updatable subscribers I want to know if in a transactional push replication with updatable subscribers, a commit is only done when all subscribers have succeeded to make it, or if it only guarantees the correct commit in the publisher and the subscriber that generated the change in the database.
I've found this in msdn, but I don't know if the two-phase commit protocol is referring to all instances (publisher and subscribers, or just one subscriber and the publisher)

When data is updated at a Subscriber, it is first propagated to the
  Publisher and then propagated to other Subscribers. If immediate
  updating is used, the changes are propagated immediately using the
  two-phase commit protocol. If queued updating is used, the changes are
  stored in a queue; the queued transactions are then applied
  asynchronously at the Publisher whenever network connectivity is
  available. Because the updates are propagated asynchronously to the
  Publisher, the same data may have been updated by the Publisher or by
  another Subscriber and conflicts can occur when applying the updates.
  Conflicts are detected and resolved according to a conflict resolution
  policy that is set when creating the publication.

A: To paraphrase the quoted block, with immediate update the only guarantee is that the commit is immediately updated to the publisher.  The changes will be sent to the other subscribers in due course.
Without immediate updating, your changes are only committed to the local subscriber, and queued for distribution back to the publisher, and following that, the other subscribers.
In both cases there is a period of time when a stale record is still at the other subscribers, and one of those subscribers may update the stale record and cause a conflict.


text:
Q: Git: "Cannot 'squash' without a previous commit" error while rebase I have the following in the to-do text of git rebase -i HEAD~2:
pick 56bcce7 Closes #2774
pick e43ceba Lint.py: Replace deprecated link

# Rebase 684f917..e43ceba onto 684f917 (2 command(s))
#
...

Now, when I try to squash the first one(56bcce7) and pick the second one by adding "s" before the first, I get the following error:
Cannot 'squash' without a previous commit

Can someone explain me what it means, and how do I do it?
I want to squash the first commit(56bcce7) and "select and reword" the second(e43ceba) commit

A: Squash with the reverse logic. You'll be able to select the desired commit message at the later step.

*

*pick the first commit that you don't want the commit-message for.

*squash or fixup the commit(s) that you want to merge, until the one that has the commit message that you actually wanted.

pick 56bcce7 Closes #2774
squash e43ceba Lint.py: Replace deprecated link

*

*confirm the change (:x)

*delete the commit message(s) that you don't want and leave only the message from the commit that you desire (in this case: Lint.py: Replace deprecated link).

*confirm the choice (:x)

Hope it's clearer for somebody ✌

A: It will be best to just say in the interactive editor containing the commits, git always squash from bottom to top and one should leave a "pick" entry at the top to receive the squashes from below.

A: I had this problem and the reason why it happened in my case was that, you cannot squash older commits onto a new commit. Here is an example say you have 3 commits:
1 pick 01mn9h78 The lastest commit
2 pick a2b6pcfr A commit before the latest
3 pick 093479uf An old commit i made a while back

Now if you say git rebase -i HEAD~3 and you do something like
1 pick 01mn9h78 The lastest commit
2 s a2b6pcfr A commit before the latest
3 s 093479uf An old commit i made a while back

This will result in the error:

error: cannot 'squash' without a previous commit
      You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'.
      Or you can abort the rebase with 'git rebase --abort'.

Solution :
When squashing commits, you should squash recent commits to old ones not vice versa thus in the example it will be something like this:
1 s 01mn9h78 The lastest commit
2 s a2b6pcfr A commit before the latest
3 pick 093479uf An old commit i made a while back

This will work fine, incase you want all your commit messages, I would suggest fixup instead of squash.

A: I just tried this approach.

git log -n3

This would show the last 3 commits which would give me the idea of what is the latest commit and which one went previously. Now stated rebasing,

git rebase -i HEAD~3

Choose the lastest commit on top of which we need to squash the other two. The commit id which is choosen as base commit would be like,

pick commit_id

For the other two commit ids, change them into,

squash commit_id

or simply,

s commit_id

A: I had a similar problem which I solved as follows:
This is the commit group I wanted to squash:
1 s 01cc5a08 Removes open div
2 s a2b6eecf Restores old fonts
3 s 603479ff Cleans left out div
4 pick 5afdbc33 Update: show logo on landing page
5 s 04c1cb13 change version of dev and prod from 1 to 2
6 s bbe6a8f8 Update: show logo on landing page if they have one
7 s c0d6008a Adds check for C users

As you can see, I wanted no. 4, but 1, 2 and 3 had no previous commit to squash into. Hence the Cannot 'squash' without a previous commit error.
My solution was to use the r option for # r, reword = use commit, but edit the commit message
So my commits list looked like this:
1 r 01cc5a08 Removes open div
2 s a2b6eecf Restores old fonts
3 s 603479ff Cleans left out div
4 s 5afdbc33 Update: show logo on landing page
5 s 04c1cb13 change version of dev and prod from 1 to 2
6 s bbe6a8f8 Update: show logo on landing page if they have one
7 s c0d6008a Adds check for C users

After saving, the interactive shell asked me for the rewording of the chosen commit.
After that, my commit log resulted in a single commit which resulted in a cleaner commit history.

A: Interactive rebase presents commits in the reverse order of what you are used to when using git log. git rebase -i replays the selected commits in the exact (top-down) order they are listed in the saved rebase instructions file. When squashing, the commit selected for squashing is combined with the commit that precedes it in the (edited) list, i.e. the commit from the previous line. In your case - there is no previous commit for  56bcce7. You have to do one of the following

*

*git rebase -i HEAD~3 (if you want to squash 56bcce7 into 684f917)

*If you mean to combine 56bcce7 with e43ceba, and e43ceba doesn't depend on 56bcce7, then simply reorder them:
r e43ceba Lint.py: Replace deprecated link
s 56bcce7 Closes #2774

UPDATE: Gus's answer below suggests a better way of doing the same, without reordering the two commits:
r 56bcce7 Closes #2774
s e43ceba Lint.py: Replace deprecated link

This will squash/merge the two commits into one. When the interactive rebase asks for a reworded  commit message for 56bcce7, provide the commit message that describes the union of 56bcce7 and e43ceba.

A: I also have already meet with this problem just now,that's just careless.you can solve the problem like next:when you try to squash the first one(56bcce7) and pick the second one you should add "s" before the second line but not the first one. you can also reference the next web site:http://backlogtool.com/git-guide/en/stepup/stepup7_5.html


text:
Q: How can I see how many numbers I put in a vector c# I have a vector: int[,] leg = new int[100, 2]; and I put some numbers in it. Is there a function beside v.Length that shows how many numbers I put in my vector?(v.Length shows me that I have 200 numbers which is wrong because I put in just a few)

A: What you have is a 2-dimensional array.  The Length property reports its size, which is fixed over its lifetime.  When you create an array, the members are default initialized; in the case of an int array everything is set to 0.  What you seem to be asking about is how many elements you have written to.  This is not tracked anywhere.  You could either count every time you assign to an element or count the non-zero elements.  Note that these measure different things and could give different answers.


text:
Q: How to identify and concatenate fragmented long SMS messages into a complete SMS in PDU mode? I am working with GSM modem via AT Command interface to read all the messages stored on SM memory, PDU mode.
AT+CMGF=1
AT+CMGL=4

The return is
+CMGL: 1,"REC READ","53030303","","2017/07/10 13:04:37+24"
050003FF0301A66FB93C0FCABFEB72103AEC26CFCB7410F95D9E83DC6FBA625E87C3DF723A285
CA7BFDB617A7A0C9A97E9F4B4FB3C7781B2EF3AC85D2E9341F43788FC06D1D165D0BC4CA7A7DD
E739A81D76D7C36C76DEA530BEE5A0A4935A943A8B549D022A7F9BD3EC32C8196E977520D1110
A4A3AA945A9B34815298250A70E243AC3D36E7A59EE2ED345

+CMGL: 2,"REC READ","53030303","","2017/07/10 13:04:37+24"
050003FF030214C6B71CD46C4E750AA8FC6D4EB3CB2067B85DD681444728A8D99C8A1450F91B9
FD781DC75365B017DCBE93A90BBCE662BAA52A60E2442D3E970DDEBD56ECFC7AEB33CDC2E97DD
70F4DB5D768DDFEDD7BC2CB7B3CBF4F9ABDD9E8B1441A85307129DE1EDF65CA480B2CBE179196
44FCFD37450FE5D9783DCE5B0BC3CA7838ED021C8FC9683D0

+CMGL: 3,"REC READ","53030303","","2017/07/10 13:04:37+24"
050003FF0303CA6C38

Here 1,2,3 number messages are multipart. And I want to combine the three parts of this message into one complete message. Especially supports both unicode characters.

A: The Wikipedia article is helpful for this. In a nutshell, bytes 5 and 6 of each message denote the placement:

*

*050003FF0301...  3 parts, part 1

*050003FF0302...  3 parts, part 2

*050003FF0303...  3 parts, part 3

There are other things to consider with the header, and any PDU spec will go into detail on them, but this message header answers your question of how to identify and concat them in the right order


text:
Q: ASP.NET Provide Styling for TextBox I am using a multiline textbox as following:
<asp:TextBox runat="server" TextMode="MultiLine" Height="200" Width="500" ReadOnly="true" Font-Names="calibri" Text="Terms and Conditions Next text will go over.. >

What I need to do is to only make Terms and Conditions in bold. Rest of the sentence is not in bold. I tried using a span with a style of bold but that did not affect anything.
How do I do styling for a Textbox? Keep in mind this is a read only textbox.

A: If i understand you right, u need this
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/HTMLEditorExtender/HTMLEditorExtender.aspx
 <script>
        function onContentsChange() {
            alert('contents changed');
        }
    </script>

    <asp:TextBox runat="server"
        ID="txtBox1"
        TextMode="MultiLine"
        Columns="50"
        Rows="10"
        Text="Hello <b>world!</b>" />

    <ajaxToolkit:HtmlEditorExtender
        ID="htmlEditorExtender1"
        TargetControlID="txtBox1"
        OnClientChange="onContentsChange"
        runat="server" >
    </ajaxToolkit:HtmlEditorExtender>

A: what you need is more than a regular textbox, you should either use devexpress or ajax toolikt, or some other ajax libraries.
you might consider looking for library that gives you rich formatting abilities


text:
Q: How define charset for HTMLhelp? My C++ windows program uses htmlhelp. Structure HH_POPUP includes field pszFont in format: "Facename[, point size[, CHARSET[, color[, PLAIN BOLD ITALIC UNDERLINE]]]]", but I cannot find any info about way to define the charset. My russian popup help is totally unreadeable.
HH_POPUP popupAttr;
memset(&popupAttr, 0, sizeof(popupAttr));
popupAttr.cbStruct = sizeof(popupAttr);
popupAttr.clrBackground    = COLORREF(-1);
popupAttr.clrForeground    = COLORREF(-1);
popupAttr.rcMargins.left   = -1;
popupAttr.rcMargins.bottom = -1;
popupAttr.rcMargins.right  = -1;
popupAttr.idString = UINT(helpInfo->dwContextId);
popupAttr.pt       = helpInfo->MousePos;
popupAttr.pszFont = _T("Arial,18,HOW_TO_DEFINE_THIS_CHARSET"); // please!!!
CWnd::GetDesktopWindow()->HtmlHelp(reinterpret_cast<DWORD>(&popupAttr), HH_DISPLAY_TEXT_POPUP);

A: (Just a guess.) It might be that the charset needs to be defined in your HTML Help rather than the HH_POPUP structure. Is the charset specified in the META tags of your HTML Help topics? E.g.:
<META http-equiv="Content-Type" content="text/html" charset="Windows-1251">

Also, is the corresponding language specified for your help file? E.g.:
<Project.hhp>

[OPTIONS]
Language=0x419 Russian (Russia)

A: The problem has solved by converting txt file with popup labels from UNICODE to ANSI. Thank you everyone for your help


text:
Q: How do I ask AngularJS to recalculate the value of a complex function? I have an AngularJS controller with the following function:
$scope.getExampleValue = function(exampleId) {
  // calculate a value using underscore's _.where()
  // clause against two JSON arrays on the $scope
  // and the exampleId parameter passed in

  return computedValue;
}

The function's parameter (exampleId) is rendered from the server, so the resulting HTML looks like this:

  ...
  {{ getExampleValue(3) }}
  {{ getExampleValue(4) }}
  {{ getExampleValue(5) }}
  ...

The problem I have is that AngularJS doesn't know to call getExampleValue() again when the JSON arrays used in the function have changed: they're 2 simple JSON arrays, new JSON items can be added or removed, or properties of existing JSON items in either array can be modified which affect the result.
I've looked at $scope.watch() and $scope.watchCollection() but I'm unsure how I can use them without changing my approach to bind against already computed values rather than against the function I prefer.
Essentially I think I'm asking how to notify AngularJS that a complicated bound value has changed, then I could wrap that notification up in a $scope.watch()..
Thanks for your help.

A: You are looking for $scope.$apply:
When you change the JSON asyncly, run:
$scope.$apply(function () {
    // update the properties on $scope
});


text:
Q: How can I change the nametag of a villager using commands Is it possible to change the nametag of a villager using commands in Minecraft?

A: You need to use the NBT component CustomName
So to change name of an already existing villager you do entitydata @e[type=villager,c=1] {CustomName:"New Name"}
Also, to make the name always visible and not only when looked at you can add CustomNameVisible:1b to the NBT as well.


text:
Q: Multiple MAIN signatures I have a package with multiple main and I want to define several options:
My code is something like this:
package Perl6::Documentable::CLI {
    proto MAIN(|) is export {*}
    my %*SUB-MAIN-OPTS = :named-everywhere;

    multi MAIN(
        "setup"
    ) { ... }

    multi MAIN (
        "start"                           ,
        Str  :$topdir              = "doc",
        Bool :v(:verbose($v))      = False
    ) { ... }

But when I try to actually execute it with:
perl6 -Ilib bin/documentable start -v --topdir=ss

It outputs this line:
Usage:
  bin/documentable [--topdir=<Str>] [-v|--verbose] start

I am using %*SUB-MAIN-OPTS but it looks like it does not work neither.

A: The simplest solution would be to export the dynamic variable %*SUB-MAIN-OPTS, but that is still Not Yet Implemented completely: the export works sorta, but winds up being an empty hash.  So not very useful.
Rakudo will call a subroutine called RUN-MAIN when it decides there is a MAIN sub to be run.  You can actually export a RUN-MAIN from your module, and set up the dynamic variable, and then call the original RUN-MAIN:
sub RUN-MAIN(|c) is export {
    my %*SUB-MAIN-OPTS = :named-anywhere;
    CORE::<&RUN-MAIN>(|c)
}

For more information about RUN-MAIN, see: https://docs.raku.org/language/create-cli#index-entry-RUN-MAIN


text:
Q: Generating NPV estimates in Powerquery for PowerBI So I am looking to generate NPVs for a number of different cases. Assume the discount rate is 10%.
Below is some sample data and I was hoping to get NPVs for all cases both for costs and for revenues.
So in this case, what would be ideal is to get:
-Neptune & Mars NPV Revenues
-Neptune & Mars NPV Costs
Ideally, in different tables ie. NPV cost table with all projects and the NPVs of each their costs and the same for the revenue NPV table.
Hope you can help.

Case
Profile
Year
Value

Neptune
Cost
2021
7

Neptune
Cost
2022
7

Neptune
Cost
2023
5

Neptune
Cost
2024
6

Neptune
Revenue
2021
7

Neptune
Revenue
2022
7

Neptune
Revenue
2023
5

Neptune
Revenue
2024
6

Mars
Cost
2021
6

Mars
Cost
2022
6

Mars
Cost
2023
6

Mars
Cost
2024
8

Mars
Revenue
2021
7

Mars
Revenue
2022
7

Mars
Revenue
2023
5

Mars
Revenue
2024
6


text:
Q: Is MongoDB WiredTiger using clustered index? Is WiredTiger using clustered index on _id or just non-clustered index when it is as the storage engine of MongoDB? Is there any way to manage it?

A: As of MongoDB 4.0.6, WiredTiger does not use clustered index for the _id field.
Actually there is no facility to create clustered index in MongoDB using WiredTiger currently.
See SERVER-3294 for the discussion regarding adding this feature to MongoDB.
EDIT: As Arjun mentioned in the other answer, it is possible to create a clustered index from MongoDB 5.3 (thanks Arjun!). However it comes with a set of limitations: https://www.mongodb.com/docs/v5.3/core/clustered-collections/#limitations but it also comes with certain advantages as well. So if you're thinking about using this feature, please do test it extensively before deploying it in production.

A: From MongoDB 5.3 onwards, you can create a collection with a clustered index.
https://www.mongodb.com/docs/v5.3/core/clustered-collections/


text:
Q: gRPC - Use of ContextPropagatingExecutorService and currentContextExecutor Since gRPC makes service call on new thread and gRPC context is Thread Local, how can I propagate this gRPC context? I found that Context.currentContextExecutor() and ContextPropagatingExecutorService can be used but I haven't found enough resources or example for these 2 options. Can someone help to implement these?

A: ClientInterceptors shouldn't change the context instance seen by the application. The Context behavior shouldn't really change whether using blocking, async, or future stubs and a blocking API would not be able to change the current context.
While an interceptor is free to modify a pre-existing (mutable) value in the Context, there's generally little need. It is normally easier to create a new interceptor instance each RPC and communicate with the interceptor directly, or communicate via a custom CallOption.
If you have just a single call site that needs access to response headers, then MetadataUtils.newCaptureMetadataInterceptor() is a convenient (although roundabout) way to get the Metadata. It was designed for testing, but is appropriate for small-scale use outside of testing situations.
AtomicReference<Metadata> headers = new AtomicReference<>();
AtomicReference<Metadata> trailers = new AtomicReference<>();
// Using blocking for simplicity, but applies equally to futures
stub.withInterceptors(MetadataUtils.newCaptureMetadataInterceptor(headers, trailers))
    .someRpc();
Metadata headersSeen = headers.get();

If you need to access the same header from multiple callsites, it is better to create a custom interceptor that does what you need.
CustomInterceptor interceptor = new CustomInterceptor();
stub.withInterceptors(interceptor)
    .someRpc();
... = interceptor.getWhateverValue();

This is demonstrating a "general" use case. Specific instances commonly can tweak their API further to be more convenient and natural.


text:
Q: Jinja-like for Pdf in Python I am looking for the best accurate tool for PDF in Python that works like Jinja does for HTML.
What are your suggestions?

A: Have a look at ReportLab Toolkit.
You can use templates only with the commercial version, though.

A: There's now a new kid on the block called WeasyPrint.

A: I had exactly the same requirement as the OP. Unfortunately WeasyPrint wasn't a viable solution, because I needed very exact positioning and barcode support. After a few days of work I finished a reportlab XML wrapper with Jinja2 support.
The code can be found on GitHub
including an example XML wich generates the following PDF.

A: What about python/jinja to rst/html and html/rst to pdf using either rst2pdf or pandoc.
Both of these have worked well for me but. like plaes, I may try Weasyprint in the future.

A: As answered by jbochi, ReportLab is the foundation for almost all Python projects that generate PDF.
But for your needs you might want to check out Pisa / xhtml2pdf.  You would generate your HTML with a Jinja template and then use Pisa to convert the HTML to PDF. Pisa is built on top of ReportLab.
Edit: another option I'd forgotten about is wkhtmltopdf

A: If you want to use existing PDF as template, without altering original document, you can use Dhek template editor, which allows to define area (bounds, name, type) in a separate template file.
Template is saved in JSON format so that it can be parsed in Python, to fill areas over PDF and generate the final document (e.g. with values from Web form).
See documentation at https://github.com/applicius/dhek .
[EDIT]
Initial answer was from the author of dhek.
I have used this tool and this is great if your form has not been generated in the usual way (it even works on PDF done from images).
After you downloaded, unzipped, and run DHEK (no install needed, it is portable), you can select areas and given them a name:

You can then save the "mapping" to JSON so you can get the positions and dimensions of the areas:
{
    "pages": [
        {
            "areas": [
                {
                    "name": "FirstName",
                    "x": 198.48648648648648,
                    "type": "text",
                    "y": 151.22779922779924,
                    "height": 15.75289575289574,
                    "width": 181.15830115830119
                },
                {
                    "name": "LastName",
                    "x": 195.33590733590734,
                    "type": "text",
                    "y": 176.43243243243245,
                    "height": 18.115830115830107,
                    "width": 185.0965250965251
                }
            ]
        }
    ],
    "format": "dhek-1.0.13"
}

You can then use these positions with reportlab to create a PDF that contains the text:
from reportlab.pdfgen.canvas import Canvas

def write_text(
    canvas: Canvas, txt: str, x: float, y: float, height: float, in_middle: bool = True
) -> None:
    """Write text in a form (in middle of height)"""
    if canvas.bottomup:
        y = canvas._pagesize[1] - y
    canvas.drawString(x, y + height / 2, txt)

def create_overlay(overlay_path: str):
    """
    Create the data that will be overlayed on top
    of the form that we want to fill
    """
    c = Canvas(overlay_path, bottomup=0)  # DHEK has (0,0) at top-left
    write_text(c, "Mike", 198.48648648648648, 151.22779922779924, 15.75289575289574)
    write_text(c, "Jagger", 195.33590733590734, 176.43243243243245, 18.115830115830107)

    c.save()

create_overlay("form_overlay.pdf")

You can then use any tool / pdf library (e.g. pdfrw) to merge the two in a single page:
import pdfrw

def merge_pdfs(form_pdf, overlay_pdf, output):
    """
    Merge the specified fillable form PDF with the
    overlay PDF and save the output
    """
    form = pdfrw.PdfReader(form_pdf)
    olay = pdfrw.PdfReader(overlay_pdf)

    for form_page, overlay_page in zip(form.pages, olay.pages):
        merge_obj = pdfrw.PageMerge()
        overlay = merge_obj.add(overlay_page)[0]
        pdfrw.PageMerge(form_page).add(overlay).render()

    writer = pdfrw.PdfWriter()
    writer.write(output, form)

merge_pdfs("form.pdf", "form_overlay.pdf", "form_filled.pdf")

(last part of code to create Overlay and Merge is coming from the Excellent blog "Mouse vs Python": https://www.blog.pythonlibrary.org/2018/05/22/filling-pdf-forms-with-python/)

A: What more accurate tool for PDF in Python that works like Jinja than Jinja itself?
You just have to make sure that the Jinja block, variable, and comment identification strings do not conflict with the LaTeX commands. Once you change the Jinja environment to mimic the LaTeX environment you're ready to go!
Here's a snippet that works out of the box:
Python Source: ./create_pdf.py
import os, jinja2
from jinja2 import Template

latex_jinja_env = jinja2.Environment(
    block_start_string    = '\BLOCK{',
    block_end_string      = '}',
    variable_start_string = '\VAR{',
    variable_end_string   = '}',
    comment_start_string  = '\#{',
    comment_end_string    = '}',
    line_statement_prefix = '%%',
    line_comment_prefix   = '%#',
    trim_blocks           = True,
    autoescape            = False,
    loader                = jinja2.FileSystemLoader(os.path.abspath('./latex/'))
)
template = latex_jinja_env.get_template('latex_template.tex')

# populate a dictionary with the variables of interest
template_vars  = {}
template_vars['section_1'] = 'The Section 1 Title'
template_vars['section_2'] = 'The Section 2 Title'

# create a file and save the latex
output_file = open('./generated_latex.tex', 'w')
# pass the dictionary with variable names to the renderer
output_file.write( template.render( template_vars ) )
output_file.close()

Latex Template: ./latex/latex_template.tex
\documentclass{article}
\begin{document}
\section{Example}
An example document using \LaTeX, Python, and Jinja.

% This is a regular LaTeX comment
\section{\VAR{section_1}}
\begin{itemize}
\BLOCK{ for x in range(0,3) }
  \item Counting: \VAR{x}
\BLOCK{ endfor }
\end{itemize}

\#{This is a long-form Jinja comment}
\BLOCK{ if subsection_1_1 }
\subsection{ The subsection }
This appears only if subsection_1_1 variable is passed to renderer.
\BLOCK{ endif }

%# This is a short-form Jinja comment
\section{\VAR{section_2}}
\begin{itemize}
%% for x in range(0,3)
  \item Counting: \VAR{x}
%% endfor
\end{itemize}

\end{document}

Now simply call: $> python ./create_pdf.py
Resulting Latex Source: ./generated_latex.tex
\documentclass{article}
\begin{document}
\section{Example}
An example document using \LaTeX, Python, and Jinja.

% This is a regular LaTeX comment
\section{The Section 1 Title}
\begin{itemize}
  \item Counting: 0
  \item Counting: 1
  \item Counting: 2
\end{itemize}

\section{The Section 2 Title}
\begin{itemize}
  \item Counting: 0
  \item Counting: 1
  \item Counting: 2
\end{itemize}

\end{document}

Generated Pdf:

References:

*

*About Django's syntax conflict with LaTex

*About latex templates

*About passing a dict to render_template

A: ... There is also the library pdfjinja that is for this purpose: https://github.com/rammie/pdfjinja
It is using annotations to create template values.
In my use case, I didn't have a PDF with proper form fields so the solution suggested by cchantep was more suitable.


text:
Q: How to sort by / order by a field of a nested entity? How could something like this be done?
context.Subscriptions
.Include("TvShow.News")
.Include("User")
.Where(s => s.UserId == userId)
.OrderByDescending(t => t.TvShow.News.CreatedOnDatetime)
.ToList();

The OrderByDescending doesn't work in this case, i put it there just for easier understanding of the problem.

A: I finally got it to work with this spaghetti code:
// NASTY NASTY ENTITY FRAMEWORK
var anonymousObjects = context.Subscriptions
    .Where(c => c.UserId == userId)
    .Select(s => new
    {
        SubscriptionId = s.Id,
        TvShowId = s.TvShowId,
        TvShow = s.TvShow,
        TvShowNews = s.TvShow.News.OrderByDescending(n => n.CreatedOnDatetime),
        UserId = s.UserId,
        User = s.User
    });

anonymousObjects = anonymousObjects.OrderByDescending(x => x.TvShowNews.Max(n => n.CreatedOnDatetime));
var subscriptions = new List<Subscription>();
foreach (var oneAnonymousObject in anonymousObjects)
{
    var subscription = new Subscription
    {
        Id = oneAnonymousObject.SubscriptionId,
        TvShowId = oneAnonymousObject.TvShowId,
        UserId = oneAnonymousObject.UserId,
        TvShow = new TvShow
        {
            Id = oneAnonymousObject.TvShow.Id,
            Title = oneAnonymousObject.TvShow.Title,
            CreatedOnDatetime = oneAnonymousObject.TvShow.CreatedOnDatetime,
            IsPrivate = oneAnonymousObject.TvShow.IsPrivate,
            TotalSubscriptions = oneAnonymousObject.TvShow.TotalSubscriptions,
            News = oneAnonymousObject.TvShowNews.ToList()
        },
        User = oneAnonymousObject.User
    };
    subscriptions.Add(subscription);
}

Entity Framework team, if you see this, please please please make this easier.


text:
Q: Name already numbered vertices in an undirected graph using R So I've been able to develop a graph of entities based on text, a sample is below.
                                  X1 X2
              PERSON Sherlock Holmes  1
       PERSON Sir Arthur Conan Doyle  1
              PERSON Sherlock Holmes  2
                       PERSON Watson  2
                     PERSON Moriarty  2

I've been successful at creating an undirected graph with the relationships between the entities in column X1 and column X2. The numbers in column X2 are group numbers. Sherlock Holmes and Sir Arthur Conan Doyle are in the same group. Ideally I'd like to create and undirected graph not between the entity in column X1 and the group number in Column X2 but the entity and the other members of the group like below.
                                  X1 X2
              PERSON Sherlock Holmes  PERSON Sherlock Holmes
              PERSON Sherlock Holmes  PERSON Sir Arthur Conan Doyle
       PERSON Sir Arthur Conan Doyle  PERSON Sir Arthur Conan Doyle
       PERSON Sir Arthur Conan Doyle  PERSON Sherlock Holmes
              PERSON Sherlock Holmes  PERSON Sherlock Holmes
              PERSON Sherlock Holmes  PERSON Watson
              PERSON Sherlock Holmes  PERSON Moriarty
                       PERSON Watson  PERSON Watson
                       PERSON Watson  PERSON Sherlock Holmes
                       PERSON Watson  PERSON Moriarty
                     PERSON Moriarty  PERSON Moriarty
                     PERSON Moriarty  PERSON Sherlock Holmes
                     PERSON Moriarty  PERSON Watson

It would also be really nice to be able to remove the duplicates within the graph so that I got the result below.
                                  X1 X2
              PERSON Sherlock Holmes  PERSON Sir Arthur Conan Doyle
       PERSON Sir Arthur Conan Doyle  PERSON Sherlock Holmes
              PERSON Sherlock Holmes  PERSON Watson
              PERSON Sherlock Holmes  PERSON Moriarty
                       PERSON Watson  PERSON Sherlock Holmes
                       PERSON Watson  PERSON Moriarty
                     PERSON Moriarty  PERSON Sherlock Holmes
                     PERSON Moriarty  PERSON Watson

I used the below code to get the text into the data frame with the group numbers.
num.el <- sapply(entities.list, length)
association.matrix <- cbind(unlist(entities.list), rep(1:length(entities.list), num.el))

So here is the actual code I get the errors with as requested by Mr. Flick. The data is an enron email.
entities.list <-
$all4
[1] " "           "PERSON kaye"

$all9
[1] "MISC Content-Type : text plain; charset=us-ascii" "ORGANIZATION X-From"
"PERSON Kaye Ellis"
[4] "PERSON Lisa Mackey"                               "MISC X-bcc"

Conform list to dataframe
association.matrix <- data.frame(matrix(unlist(entities.list), byrow=T))
association.matrix

Conform list to a list where entities in same list item are grouped by association in a number
num.el <- sapply(entities.list, length)
association.matrix <- cbind(unlist(entities.list), rep(1:length(entities.list), num.el))

remove empty string entries
 association.matrix <- association.matrix[!apply(association.matrix, 1, function(x)
 any(x==" ")),]

Coerce matrix to dataframe and remove strings as factors
    association.matrix <- data.frame(association.matrix, stringsAsFactors = FALSE)
So the data looks like this now
                                                X1 X2
1                                      PERSON kaye  1
2 MISC Content-Type : text plain; charset=us-ascii  2
3                              ORGANIZATION X-From  2
4                                PERSON Kaye Ellis  2
5                               PERSON Lisa Mackey  2
6                                       MISC X-bcc  2

Here is Mr. Flick's script that I'm trying to get working
association.matrix <- do.call(rbind, lapply(tapply(association.matrix$X1,
association.matrix$X2, combn, 2), function(x)
  rbind(t(x), t(x)[,2:1])))

And here's the error I get.
Error in FUN(X[[1L]], ...) : n < m

A: So if your input data is
dd<- data.frame(X1 = c("PERSON Sherlock Holmes", "PERSON Sir Arthur Conan Doyle",
    "PERSON Sherlock Holmes", "PERSON Watson", "PERSON Moriarty"),
    X2 = c(1L, 1L, 2L, 2L, 2L), stringsAsFactors=FALSE
)

It seems like you can generate the results you want with
mm <- do.call(rbind, lapply(tapply(dd$X1, dd$X2, combn, 2), function(x)
    rbind(t(x), t(x)[,2:1]))
)

which gives
     [,1]                            [,2]
[1,] "PERSON Sherlock Holmes"        "PERSON Sir Arthur Conan Doyle"
[2,] "PERSON Sir Arthur Conan Doyle" "PERSON Sherlock Holmes"
[3,] "PERSON Sherlock Holmes"        "PERSON Watson"
[4,] "PERSON Sherlock Holmes"        "PERSON Moriarty"
[5,] "PERSON Watson"                 "PERSON Moriarty"
[6,] "PERSON Watson"                 "PERSON Sherlock Holmes"
[7,] "PERSON Moriarty"               "PERSON Sherlock Holmes"
[8,] "PERSON Moriarty"               "PERSON Watson"

And you can make that a directed graph with
library(igraph)
gg <- graph.edgelist(mm)


text:
Q: How do you split export of large query result to multiple CSVs in MySQL Workbench Is there a way to efficiently split a large query result over excels max row limit (1,048,576) automatically on export in MySQL Workbench?
I see it's possible to do this with MySQLDump, but is there are way to do this without writing results to a table and then exporting that table?
On export I would like results over 1,000,000 lines to split at line 1,000,000 and create a new file with remaining results.
I could possibly split files post export, but would like to see if it's possible to have this done on export to reduce number of steps.


text:
Q: iOS 13 only occasionally suggests a strong password after switching from previous textfield I'm struggling with adding a strong password generation to a UITextField on iOS 13. It doesn't work for my main new password field at all despite of adding textContentType to .newPassword. However, it works for my confirm password field only if I select it after my main password field.
Here's the setup for these textfields, which happens in controller's init.
    valueTextfield.font = .boldSystemFont(ofSize: 28)
    valueTextfield.autocapitalizationType = .none
    valueTextfield.autocorrectionType = .no
    valueTextfield.textColor = .black
    valueTextfield.textAlignment = .center
    valueTextfield.borderStyle = .none
    valueTextfield.tintColor = .primary
    valueTextfield.sizeToFit()valueTextfield.textContentType = .newPassword
    valueTextfield.placeholder = "Password".localized

    confirmationTextField.font = .boldSystemFont(ofSize: 28)
    confirmationTextField.textColor = .black
    confirmationTextField.textAlignment = .center
    confirmationTextField.autocapitalizationType = .none
    confirmationTextField.autocorrectionType = .no
    confirmationTextField.textContentType = .newPassword
    confirmationTextField.borderStyle = .none
    confirmationTextField.tintColor = .primary
    confirmationTextField.placeholder = "Confirm".localized

Even adding a textfield to a blank controller doesn't help. Is that an iOS 13 bug?

A: Make sure that you have these 3 properties of UITextField to be set correctly for password autofill to work:
textField.isSecureTextEntry = true
textField.autocapitalizationType = .none
textField.textContentType = .password

And most importantly, enable password autofilling:
Settings > Passwords & Accounts > AutoFill Passwords

A: Apparently, the way I want autogenerated password to work is not possible at this moment.
For strong password suggestion to work, username textfield should be on the same screen as password textfield.
This is bizarre, but after researching apps like Twitter I discovered that non of them have strong password suggestion for a single password textfield. It's unknown whether it's a bug or a feature.
I'll have to go with reimplementing this feature manually.


text:
Q: How to find the primitive elements of $F_{13}$ I am trying to work out how to find the primitive elements of $F_{13}$.
I know the primitive element are $2,-6,6,2$ but I am not sure how to get to this answer.
Does it have something to do with the inverses of the elements of $F_{13}$?
What is the general method to find the primitive elements?


text:
Q: PHP MYSQL How to automated Add Value to table I want to create program to automated create class, and every class created then the program automated insert the data to the class.
here my code :
$range = range('A', 'Z');
$quota = 100;
$quotaperclass = 25;

for ($x = 0; $x < $quota/$quotaperclass ; $x++) {
        // Automated Create Class
        $sql= "INSERT INTO class(class_id,class_name,prodi_name) values('A25$x','".$range[$x]."','TK')";

        $subquery = "select student_id from alocatedclass"; //Check student already in class
        $sql = "SELECT * FROM student WHERE student.prodi_name='TK' and student.student_id not in ({$subquery}) ORDER by student.student_id ASC LIMIT $quotaperclass";
        $result = mysql_query($sql);
        while($data = mysql_fetch_array($result)){
            // Should insert data to every class
            $sql = "insert into alocatedclass(student_id,class_id) values ('$data[student_id]','A25$x')";
        }
    }

Automated Create Class work well, but insert student data to the class is not work. i want like
Create Class A
insert student 1
insert student 2
insert student 3
.....
insert student 25

Create Class B
insert student 26
insert student 27
insert student 28
.....
insert student 50

any have solution?
or have better code?
let me know.
or if can add random student, should be better.
and please explain the code, because iam noob in php.
thanks.

A: Replace the below line
$sql = "insert into alocatedclass(student_id,class_id) values ('$data[student_id]','A25$x')";
to
$sql = "insert into alocatedclass(student_id,class_id) values (".$data['student_id'].",'A25".$x."')";


text:
Q: PHP header image-type output vs Location redirect to binary in fs I'm trying to determine if I should just directly
1) have PHP fetch an image binary and output (with header as image-type) image, eg:
/* $image = ... insert curl function to fetch image */

header('Content-Type: image/png');

echo $image;

or if I should have
2) a header redirect to the URL path of the image
header('Location: http://domain.com/pathtoimage/image.png');

Some initial questions:
In the first, would that amount to any overhead with PHP having to have the image in memory in order to output it?
In the second, would this lead to any errors on clients that somehow cannot follow the PHP header redirect?

A: I'm against header -> location solution as you will add an extra request to your server.
Try this solution instead:
if (file_exists($file)) {
        header('Content-Type: image/png');
        readfile($file);
        exit;
    }

This solution should have minimal overhead and memory occupation.


text:
Q: Details about window.stop() I just came across the window.stop()

The stop() method is exactly equivalent to clicking the stop button in the browser. Because of the order in which scripts are loaded, the stop() method cannot stop the document in which it is contained from loading, but it will stop the loading of large images, new windows, and other objects whose loading is deferred.
  https://developer.mozilla.org/en-US/docs/Web/API/Window.stop

I am wondering:

*

*What do 'windows' and 'other objects whose loading is deffered' refer to? Can somebody give me a practical example?

*If I append an image to the body and call window.stop() when 30% has been loaded, and then append the same image at a later time; will the latter image only have 70% left load?

A:
What do 'windows' and 'other objects whose loading is deffered' refer
  to? Can somebody give me a practical example?

new windows could be iframes or regular frames.  Scripts themselves can be marked as defer which loads them after the document and after other inline scripts so these could also be stopped with window.stop().  So practical examples of objects that might have their loading stopped are: iframes, embedded objects (like Adobe Flash), scripts marked defer and images.  The idea here is that if you're going to call window.stop() from a script in the page, it can only apply to resources that have not yet completed loading.  By definition, at least part of the document and your script have already completed loading or the script wouldn't be running so you could call window.stop() so it is primarily going to apply to resources that are loaded later in the load process such as the ones above.

If I append an image to the body and call window.stop() when 30% has
  been loaded, and then append the same image at a later time; will the
  latter image only have 70% left load?

The browser cache is very unlikely to cache 30% of an image and then resume loading only the remaining 70% the next time you ask for that resource.  Most caches just refuse to cache an object if it is not completely loaded.  In any case, this would be entirely browser dependent as this type of behavior of the cache is outside of the standards.

A:
What do 'windows' and 'other objects whose loading is deffered' refer
  to? Can somebody give me a practical example?

I use to do a practical to keep window calm when page reloading like this example.
    window.stop();
    (do some staff here..)
    window.location.reload(true);

The window will automatically active by itself when page is reloaded.
So it stop only the browser, not the script.