python – Dynamically configurable ZMQ filter with Flask API

I have a stream of ZMQ messages. I have to filter the right ones and save them in MongoDB. The trick is to have an option to set the filter conditions dynamic,

I came with this solution multiprocessing and bottle, Basically, I use the Flask HTTP API to change the global one filter_parameters Dictionary given by Manager and shared with another process executing the zmq filter itself. My question is – Is it a good solution and what is the best practice in this regard?

from the multiprocessing import process, Manager
bottle import, jsonify, request
from Pymongo import MongoClient

app = bottle (__ name__)
Manager = Manager ()
filter_parameters = manager.dict ()
filter_parameters['addresses'] = ['']

Def Scan (q, filter_parameters):
import zmq
context = zmq.Context ()
socket = context.socket (zmq.SUB)
socket.connect ("tcp: // localhost: 5556")
socket.setsockopt_unicode (zmq.SUBSCRIBE, & # 39; tx & # 39;
client = MongoClient () # localhost
db = client.transactions_db
tx_collection = db.tx_collection
while true:
recv_str = socket.recv_string ()
recv_str = recv_str.split ()
filter (recv_str, filter_parameters, tx_collection)

def filter (recv_str, filter_parameters, tx_collection):
if recv_str[0] == & # 39; tx & # 39 ;:
if recv_str[7] == & # 39; 0 & # 39 ;:
if recv_str[2] in filter_parameters['addresses']:
tx_collection.insert_one ({& 39; tx & # 39;: recv_str}). insert_id

p = process (target = scan, arguments = (filter parameter))
p.daemon = true
p.start ()

@app.route (& # 39; / zmq_buffer / set_filter_addresses & # 39 ;, Methods =["POST"])
def set_filter_addresses ():
data_jsn = request.json
filter_parameters['addresses'] = data_jsn['addresses']
    Return Jsonify ({# address; #: filter_parameters['addresses']}), 200

@app.route (& # 39; / zmq_buffer / get_filter_addresses & # 39 ;, Methods =["GET"])
def get_filter_addresses ():
if filter_parameters['addresses']:
resp = jsonify (filter_parameters['addresses'])
otherwise:
resp = & # 39; no & # 39;
Return or 200

If __name__ == & # 39; __ main __ & # 39 ;:
App.Run (Port = 7050)
p.terminate ()

c ++ wrapper of the subset of the auto_ptr API, which redirects to unique_ptr

I read an interesting old question about the transition from software to Software Engineering SE std :: auto_ptr, So I wrote a wrapper around the general subset of std :: auto_ptr and std :: unique_ptr,

The task of the wrapper at runtime is to clean up the pointers you have created New when the scope ends, regardless of how the scope is exited. Its task at compile time is to make the compilation as informative as possible, though fake_autoptr is used in a way that is not at the lowest common denominator.

fake_autoptr should facilitate the transition from std :: auto_ptr and support both C ++ 11 and C ++ 03 until the support for C ++ 03 is dropped. It should behave the same way if it is supported by one auto_ptr or a unique_ptr,

The example in the old question is this. This example does not use many of the things that one auto_ptr can do. I think I am not 100% sure that the auto_ptr# 39; s job here is just to run Clear when his destructor is called and steals no resources from others auto_ptrs.

// DO NOT CHECK MINE

Foo * GetFoo ()
{
auto_ptr ptr (new foo);

// initialize Foo
ptr-> Initialize (...);

// Now configure the remaining attributes
ptr-> SomeSetting (...);

return ptr.release ();
}

Here's the wrapper I came up with.

#ifndef FAKE_AUTOPTR_FAKE_AUTOPTR_INCLUDED
#define FAKE_AUTOPTR_FAKE_AUTOPTR_INCLUDED 1

#include 
#if __cplusplus> = 201103L
#include 
#endif

Namespace fake_autoptr_ns {
Namespace detail {
template 
    Destroy empty (T * goner) {
clear goner;
}
}

template 
  Class fake_autoptr {
Public:
#if __cplusplus> = 201103L
std :: unique_ptr <T, decltype (& detail :: destroy)> smartptr_;
typedef declptype (smartptr_) smartptr_type;
#otherwise
std :: auto_ptr smartptr_;
typedef std :: auto_ptr smartptr_type;
#endif


#if __cplusplus> = 201103L
fake_autoptr () = delete;
~ fake_autoptr () = default;
#otherwise
Private:
fake_autoptr ();
Public:
#endif


#if __cplusplus> = 201103L
template 
      explicit fake_autoptr (CtorArg something): smartptr_ (something, detail :: destroy) {
static_assert (std :: is_same:: value, "constructor argument must be T *");
}
#otherwise
template 
      explicit fake_autoptr (CtorArg something): smartptr_ (something) {}
#endif


// delete special element functions
#if __cplusplus> = 201103L
explicit fake_autoptr (const fake_autoptr&) = delete;
explicit fake_autoptr (fake_autoptr&&) = delete;
fake_autoptr & operator = (const fake_autoptr.)&) = delete;
fake_autoptr & operator = (fake_autoptr &&) = delete;
#otherwise
Private:
explicit fake_autoptr (const fake_autoptr&);
fake_autoptr & operator = (const fake_autoptr.)&);
Public:
#endif

#if __cplusplus> = 201103L
T & operator * () = delete;
T * get () = delete;
#endif

const smartptr_type & operator -> () const {
return smartptr_;
}

smartptr_type & operator -> () {
return smartptr_;
}

T * release () {
return smartptr_.release ();
}

#if __cplusplus> = 201103L
const T * release () const = delete;

void reset () = delete;

void reset () const = delete;
#endif
};
}

#endif // FAKE_AUTOPTR_FAKE_AUTOPTR_INCLUDED

This is less interesting, but here's a smoke test to make sure it works

#include "fake_autoptr.hpp"
#include 

struct TwoInts {
int int1;
int int2;
void print_first_int () {
printf ("1st% d  n", int1);
}
void print_second_int () {
printf ("2nd% d  n", int2);
}
};


TwoInts * GetInt ()
{
with the namespace fake_autoptr_ns;
TwoInts * t = new TwoInts ();
t -> int1 = 3;
t -> int2 = 7;
fake_autoptr ptr (t);
ptr-> print_first_int ();
ptr-> print_second_int ();
return ptr.release ();
}

int main () {
TwoInts * t = GetInt ();
delete t;
Return 0;
}

Blockchain API limit workaround

Are there ways to avoid the limitation for API calls (5 / sec)?

I need the info over transactions and balance (certain accounts), UTXOs and the opportunity to spread my transaction.

Currently I use public blockchain explorer like

https://www.blockcypher.com/

https://chain.so/

https://etherscan.io

However, you have a limit on their calls, which is unacceptable for cases where my service requires at least 1000-2000 people.

I'm a beginner, so after some surfing I understood that the only way to tackle this problem is to store the information in my own database or run my own full nodes (for every currency I have – eth / etc / bitcoin / btc / doge / hyphen etc.
This can be quite expensive and time consuming.

Can you suggest a good solution?

Many Thanks!

HAProxy-to-Amazon API with custom domain

Hello, we tried to process an incoming request from HAProxy and use API Gateway to handle the request.

The flow is domain1.com is the endpoint at HAProxy.

HAProxy should then redirect to an API gateway on Amazon that uses a custom domain domain2.com

If we try, we get an error message from Cloudfront. I think that's because of the SNI API Gatway request to know where the request should go. That's why we've implemented the following

Backend api_gateway

http request set header host domain2.com
server api domain2.com:443 ssl sni str (domain2.com) check to verify none

That does not work, we get a 403 error. Interestingly, if we use the non-custom domain and reference the Amazon-provided stage URL, it works! Well, somehow it does not work because the stage URL needs the stage in the path, so we can not fix it.

Does anyone know how we can fix this so that the custom URL works when submitted by HAProxy?

Many Thanks,

Tom

php – api cakephp and app react natively

Hi what's up? I have a problem with a request from React native to an API in cakephp. When I make the request from Postman, it gives me back what I expected, but by doing it from React native, I miss the "missing csrf token cookie" error.

INDEX FUNCTION IN CAKEPHP

    public function index ()
{

if ($ this-> request-> is (& # 39; post & # 39;)) {
$ user = $ this-> request-> getData (& # 39; user & # 39;);
$ password = $ this-> request-> getData (& # 39; password & # 39;);
$ users = $ this-> Users-> find (& # 39; all & # 39;);

$ this-> set ([
        'usuario' => $usuario,
        'password' => $password,
        'users' => $users,
        '_serialize' => ['users','usuario','password']
    ]);
$ this-> RequestHandler-> renderAs ($ this, & # 39; json & # 39;);
}

LOGIN FUNCTION IN REACT NATIVE

    login = (user, pass) => {

if (! user == & # 39; &&! pass == & # 39; & # 39;) {

fetch (& # 39; http: //192.168.0.14:80 / accessGoApi / Users & # 39;), {
Method: "POST",
Headers: {
& # 39; Accept & # 39;: & # 39; application / json & # 39 ;,
& # 39; Content-Type & # 39;: & # 39; application / json & # 39 ;,
& # 39; X-CSRF token & # 39 ;: token,

},
Credentials: "Include",
body: JSON.stringify ({
User: this.state.usuario,
Password: this.state.password

})

}). then ((answer) => answer.text ())
.then ((responseJson) => {
if (responseJson == "ok") {
this.props.navigation.navigate (& # 39; Main & # 39;);
this.textInput.clear ();
} else {
Alarm (AnswerJson);
}
}). catch ((error) => {
Alert.alert ("Wrong username or password" + error);
});

} else {
Alert.alert (& # 39; insert data & # 39;);
}
}

At the postman I send exactly the same and go, any idea? I think the solution would be to create a cookie in native response, but I tried it and can not solve it. Thank you

ubuntu – If you set up Laravel as an API site block on Nginx, you get a 404

I am trying to create a website with React as frontend and Laravel as backend. My server is an AWS instance setup with nginx on Ubuntu.

At the moment I have Laravel in / var / www / laravel and my reaction code in / var / www / html, When I access the website http://www.website.com I can see my responding wildcard, but when I try to access Laravel http://www.website.com./api I get a 404.

I have set all permissions in Laravel correctly and all PHP loads as it should. I can get Laravel running if I set everything to root in my default file.

Here is what my default File looks like:

Server {

listen 80 default_server;
listen [::]: 80 default_server;

index index.html index.htm index.php;

Server name _;

location / api {
root / var / www / laravel / public;
try_files $ uri $ uri / @laravel;
location ~  .php $ {
fastcgi_split_path_info ^ (. + . php) (/.+) $;
fastcgi_pass unix: /var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $ realpath_root $ fastcgi_script_name;
}
}

location @laravel {
/api/(.*)$/index.php?/Recode Last$$;
}

Location / {
root / var / www / html;
try_files $ uri $ uri / = 404;
}

Location ~ /.(?!well-known).* {
deny everything;
}
}

I'm trying to learn Nginx and Laravel, so I've put some things into Googlefoo.

Is it a use case for a factory pattern when loading configuration files into a constructor for an API call?

I called a class GatewayAPIwhich, when used, must load the configuration files from a file. I first wanted to include the get_config () method in the constructor, but I do not like this design for testing purposes.

Now I plan to create a factory that creates this GatewayObject. Is this a typical application for the factory design?

Second question: Is it enough to put a method called "create" in the APIGateway class or should the factory be independent?

Enter the image description here

nodejs – Error in the REST node API

I'm trying to request a listing of my properties, but when I do, I get an error 500 and it tells me exactly the following: "CastError: Cast to ObjectId for value" mine "failed on path" _id "for model" Property " , The problem is that the ID does not take it well, but I do not know why, it should not Enter the description of the picture here

Architecture – Recommended Installation Method for an Open Source Web Application and API?

I am currently working on my own open source project.

There are currently two parts, a .NET Core Web API and an Angular Client App.

I want to get your views on installation / setup for my users. What I currently have is an installation endpoint in the API itself and an installation component / page in the Angle app.

It all works well, but after much thought it does not feel right. I feel like I've paired the app and the API if they were to be completely separate and independent of each other. The client app should not really have to worry about installing the API.

Would it be better to create a CLI responsible for installing / updating the API and APP that can be downloaded and run separately?

magento2 – Magento 2 how to add product dimensions using rest api

I can simply supplement magento 2 with simple products, and adding the weight is no problem at all. I do the following:

                $ data = & # 39; {
"Product": {
"sku": "& # 39;. $ row["item_number"] , ""
"name": "& # 39;. $ row["name"] , & # 39; "
"attributeSetId": 4,
"Price": & # 39; , $ row["price"] , & # 39 ;,
"Status": 1,
"Visibility": 4,
"typeId": "simple",
"createdAt": "& # 39; date (& # 39; Y-m-d H: i: s & # 39;). & # 39;",
"updatedAt": "& # 39; date (& # 39; Y-m-d H: i: s & # 39;). & # 39;",
"Weight": & # 39; , $ row["weight"] , & # 39 ;,
"custom_attributes": {
"description": "& # 39;. $ row["condition_description"] , & # 39;
& # 39 ;. & # 39; Brand: & # 39; , $ row["brand"] , & # 39;
& # 39 ;. & # 39; MPN: & # 39 ;. $ row["mpn"] , & # 39;
& # 39 ;. "Domestic equipments:". & # 39;
& # 39 ;. $ setup. "" "short_description": "& # 39;. $ row["condition_description"] , "" "MPN": "& # 39; $ Row["mpn"] , "" "brand": "& # 39;. $ row["brand"] , & # 39; " },

Adding "Length": 10 "below the weight attribute will result in an error. Magento 2 allows you to add height, width, and length when adding a product manually. This must be possible. I would like to avoid storing them in a custom attribute to simplify the shipping calculations.

is not length called length but something else? I tried ts_dimensions_length, packed dimensions and dimension length.