How to sort "AttributeError: 'BertTokenizer' object has no attribute 'encode_plus'"? Posted: 11 Nov 2021 07:54 AM PST I am trying to run a BERT model. The issue I face is that I don't manage to call tokenizer.encode_plus() . This is my script which, by the ways, follows this tutorial: from transformers import BertTokenizer PRE_TRAINED_MODEL = 'C:/Users/Administrator/Desktop/Knowsis/Classification' # folder where I stored the files tokenizer = BertTokenizer.from_pretrained(PRE_TRAINED_MODEL, do_lower_case=True) sentences = ["Our friends won't buy this analysis, let alone the next one we propose.", "I don't understand why I get the issue I get.", "I am not a Python expert and this is not making things easier."] # Print the original sentence. print(' Original: ', sentences[0]) # Print the sentence split into tokens. print('Tokenized: ', tokenizer.tokenize(sentences[0])) # Print the sentence mapped to token ids. print('Token IDs: ', tokenizer.convert_tokens_to_ids(tokenizer.tokenize(sentences[0]))) # Tokenize all of the sentences and map the tokens to thier word IDs. input_ids = [] attention_masks = [] # For every sentence... for sent in sentences: # `encode_plus` will: # (1) Tokenize the sentence. # (2) Prepend the `[CLS]` token to the start. # (3) Append the `[SEP]` token to the end. # (4) Map tokens to their IDs. # (5) Pad or truncate the sentence to `max_length` # (6) Create attention masks for [PAD] tokens. encoded_dict = tokenizer.encode_plus( sent, # Sentence to encode. add_special_tokens = True, # Add '[CLS]' and '[SEP]' max_length = 64, # Pad & truncate all sentences. pad_to_max_length = True, return_attention_mask = True, # Construct attn. masks. return_tensors = 'pt', # Return pytorch tensors. ) When I try to apply tokenizer.encode_plus() , I get the following error AttributeError: 'BertTokenizer' object has no attribute 'encode_plus' . Can anyone help me understand what's wrong? Thanks! |
Why postValue does not post Value? Posted: 11 Nov 2021 07:54 AM PST I called postValue() but MutableLivdata does not update its value. When I print Log in UserInfoViewModel at setNetworkObj() and setUserName() , value from parameter nothing wrong(parameter arrived well). But userName.getValue() print null. So I tried postValue() in Handler and runOnUiThread but nothing work either. I'd really appreciate it if you could tell me how to figure it out. this is my code.. UserInfoViewModel.java public class UserInfoViewModel extends ViewModel { private MutableLiveData<NetworkObj> networkObj = new MutableLiveData<>(); private MutableLiveData<String> userName = new MutableLiveData<>(); public MutableLiveData<NetworkObj> getNetworkObj() { return networkObj; } public void setNetworkObj(NetworkObj networkObj) { this.networkObj.postValue(networkObj); } public MutableLiveData<String> getUserName() { return userName; } public void setUserName(String userName) { this.userName.postValue(userName); } } LoginActivity.java public class LoginActivity extends AppCompatActivity { private ActivityLoginBinding binding; private UserInfoViewModel userInfoViewModel; public Socket socket; public ObjectInputStream ois; public ObjectOutputStream oos; private NetworkUtils networkUtils; private NetworkObj networkObj; private String userName =""; final String ip_addr = "10.0.2.2"; // Emulator PC의 127.0.0.1 final int port_no = 30000; Handler mHandler = null; @Override protected void onCreate(Bundle savedInstanceState) { binding = ActivityLoginBinding.inflate(getLayoutInflater()); super.onCreate(savedInstanceState); setContentView(binding.getRoot()); userInfoViewModel = new ViewModelProvider(this).get(UserInfoViewModel.class); mHandler = new Handler(); binding.btnLogin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { userName = binding.etName.getText().toString(); new Thread() { public void run() { try { socket = new Socket(ip_addr, port_no); oos = new ObjectOutputStream(socket.getOutputStream()); ois = new ObjectInputStream(socket.getInputStream()); networkObj = new NetworkObj(socket, ois, oos); networkUtils = new NetworkUtils(networkObj); mHandler.post(new Runnable() { @Override public void run() { userInfoViewModel.setNetworkObj(networkObj); userInfoViewModel.setUserName(userName); } }); ChatMsg obj = new ChatMsg(userName, "100", "Hello"); networkUtils.sendChatMsg(obj, networkObj); startMainActivity(); } catch (IOException e) { Log.w("Login", e); } } }.start(); } }); } public void startMainActivity() { startActivity(new Intent(this, MainActivity.class)); } } |
Error when trying to connect to SQL Server Posted: 11 Nov 2021 07:55 AM PST I am working to connect to a SQL server from ServiceNow. I am getting an error and I am unsure as to what it means. Any help is appreciated. Connection URL: jdbc:sqlserver://TESTSCCMSQL01;selectMethod=cursor;databaseName=TEST_ASH;integratedSecurity=true Error: java.sql.SQLException: com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'CAMBRIDGE\svc-p-SCCM-SN-CMDB'. ClientConnectionId:e9216fed-c737-4f09-b27b-a63f6b66b925 com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:262) com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:283) com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:129) com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:37) com.microsoft.sqlserver.jdbc.SQLServerConnection$1LogonProcessor.complete(SQLServerConnection.java:4786) com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:5068) com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:3731) com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:94) com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:3675) com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7194) com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2979) com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2488) com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:2142) com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1993) com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1164) com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:760) java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677) java.sql/java.sql.DriverManager.getConnection(DriverManager.java:189) com.service_now.mid.connections.jdbc.JDBCConnection.establishConnection(JDBCConnection.java:110) com.service_now.mid.connections.jdbc.JDBCConnection.connect(JDBCConnection.java:82) com.service_now.mid.connections.jdbc.JDBCConnectionFactory.create(JDBCConnectionFactory.java:65) com.service_now.mid.connections.ConnectionCachePool.getAvailableConnection(ConnectionCachePool.java:82) com.service_now.mid.connections.ConnectionCache.get(ConnectionCache.java:94) com.service_now.mid.probe.JDBCProbe.getJDBCConnection(JDBCProbe.java:784) com.service_now.mid.probe.JDBCProbe.probe(JDBCProbe.java:119) com.service_now.mid.probe.AProbe.process(AProbe.java:102) com.service_now.mid.queue_worker.AWorker.runWorker(AWorker.java:122) com.service_now.mid.queue_worker.AWorkerThread.run(AWorkerThread.java:20) com.service_now.mid.threadpool.ResourceUserQueue$RunnableProxy.run(ResourceUserQueue.java:649) java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) java.base/java.lang.Thread.run(Thread.java:834) at com.service_now.mid.probe.JDBCProbe.getJDBCConnection(JDBCProbe.java:788) at com.service_now.mid.probe.JDBCProbe.probe(JDBCProbe.java:119) at com.service_now.mid.probe.AProbe.process(AProbe.java:102) at com.service_now.mid.queue_worker.AWorker.runWorker(AWorker.java:122) at com.service_now.mid.queue_worker.AWorkerThread.run(AWorkerThread.java:20) at com.service_now.mid.threadpool.ResourceUserQueue$RunnableProxy.run(ResourceUserQueue.java:649) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:834) |
Django CreateView not working with custom auth model Posted: 11 Nov 2021 07:54 AM PST I have a simple application with a very simple custom user auth model and base manager. When I try to create a user using CreateView, I get no errors and no user entries are made in the database. Here is what I have. models.py: from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager from django.contrib.auth.models import PermissionsMixin from django.db import models class AccountManager(BaseUserManager): def create_user(self, email, username, password, **other_fields): .... .... email = self.normalize_email(email) user = self.model(username=username, email=email, **other_fields) user.set_password(password) user.save() def create_superuser(self, email, username, password, **other_fields): .... return self.create_user(email, username, password, **other_fields) class UserAccount(AbstractBaseUser, PermissionsMixin): email = models.EmailField(max_length=60, unique=True) username = models.CharField(max_length=30, unique=True) first_name = models.CharField(max_length=30, blank=True) last_name = models.CharField(max_length=30, blank=True) date_joined = models.DateTimeField(default=timezone.now) last_login = models.DateTimeField(default=timezone.now) is_admin = models.BooleanField(default=False) is_active = models.BooleanField(default=True) is_staff = models.BooleanField(default=False) is_superuser = models.BooleanField(default=False) objects = AccountManager() USERNAME_FIELD = 'username' REQUIRED_FIELDS = ['email'] def __str__(self): return self.username Here is my forms.py: class CreateUserForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(CreateUserForm, self).__init__(*args, **kwargs) for visible in self.visible_fields(): # If it's a checkbox, add form-check-input css class, else form-control class if visible.field.widget.__class__.__name__ == forms.CheckboxInput().__class__.__name__: visible.field.widget.attrs['class'] = 'form-check-input' else: visible.field.widget.attrs['class'] = 'form-control' class Meta: model = get_user_model() fields = ('username', 'email', 'password') And here is how I am calling the form in views.py: from .forms import CreateUserForm class CreateNewUser(CreateView): form_class = CreateUserForm template_name = 'Users/create_user.html' I do have AUTH_USER_MODEL pointing to the UserAccount class in settings.py, and I can create users from the /admin/ panel, but when I try to create a user using this CreateView, it just doesn't do anything. No errors or success messages either in console or in the front-end (I'm using {{ form.errors }} to look for them). I did try using the form_valid function of CreateView to manually save the object, but that doesn't work either. I also tried using the save() method in the form class, but it had the same problem. Other posts I have come around similar to my issue did not help either. |
Consuming Azure DevOps REST API Service in .NET 5 Posted: 11 Nov 2021 07:54 AM PST I have some folders with data files stored as a project repository on Azure DevOps. What I want to do is to create an API service in .NET 5.0 that will allow to manipulate these files (basically upload, read, download & delete). There is not much information on this topic in internet and I have some questions in mind wondering how to handle certain things: - How can I configure the Personal Access Token from Azure for AddHttpClient in Startup.cs?
- In case someone uploads a file to this repo, will it show me as the committer of this change? (If so, is there a way to make it kind a generic?)
|
Authenticating SOAP call via HTTP headers Posted: 11 Nov 2021 07:54 AM PST I am looking to integrate with a 3rd party using their SOAP API. I have tested SOAP calls via SoapUI successfully and I am now trying to do the same in my .NET core application. I am looking to use basic authentication by passing an address header with the call. I am currently doing the following: string credential = "UserName" + ":" + "Password"; AddressHeader authAddressHeader = AddressHeader.CreateAddressHeader("Authorization", string.Empty, "Basic " + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(credential))); AddressHeader[] addressHeaders = new AddressHeader[] { authAddressHeader }; EndpointAddress endpointAddress = new EndpointAddress(new Uri("https://dm-delta.metapack.com/dm/services/ConsignmentService"), addressHeaders); // passing in authentication via address header // instantiating 3rd party client service reference code generated via WCF and passing in endpoint with authentication var client = new ConsignmentServiceClient(ConsignmentServiceClient.EndpointConfiguration.ConsignmentService, endpointAddress); When I attempt to call a client method I receive the following error message: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Basic realm="default"'. I have compared the authorization header string when debugging my application and it is the exact same as the authorization in the headers from my SOAP request in SoapUI so unsure why it is complaining? This is the first time I have attempted a SOAP API integration in .NET core, any help or suggestions on what I may be doing wrong is greatly appreciated. Thanks in advance |
How can i save redux state while i'm routing in next js? Posted: 11 Nov 2021 07:54 AM PST How can i save my redux state in application while i'm routing? Route example: main to about. If i use redux store reset is happen but i need to save it. Option with local storage doesn't fit because i have secure data there |
How to protect public APIs (no credentials) from being exploited? Posted: 11 Nov 2021 07:54 AM PST It's more of a general question, but What is the recommended way to protect APIs used in SIGN UP processes? Let's say there is these public APIs (No user credential required, only API KEYs); - find_person(Data about the person trying to sign up), returns if a person already exists or not (no user credentials required AND no sensible information returned).
- create_person(Data about the person trying to sign up), creates this person into the system (no user credentials required)
Can we have "anonymous" users that have a short-lived JWT token? For example, how can the SPA Web application or Mobile application securely obtain a "per-session" anonymous user? Are Captchas actually helpful in this scenario? We are already considering: - API KEY for every application (not per session)
- Rate limiting
- DDoS services to protect the APIs
Any help would be much appreciated. Thanks |
How can execute operations sequentially and update UI Posted: 11 Nov 2021 07:53 AM PST I'm trying to execute a bunch of operations sequentially and update my UI every time an operation it starts and it finishes (I have to update an operation status icon color). Below my (working) code: class SyncManager { private let disposeBag = DisposeBag() // MARK: - Private Init private init() { } // MARK: - Public Constants static let shared = SyncManager() let refreshTokenStatus = BehaviorRelay<SyncStatus>(value: .todo) let updateCatalogDataStatus = BehaviorRelay<SyncStatus>(value: .todo) let insertDataStatus = BehaviorRelay<SyncStatus>(value: .todo) let getDataStatus = BehaviorRelay<SyncStatus>(value: .todo) func startDatabaseSync(completion: @escaping ((Result<Void, Error>) -> Void)) { refreshTokenStatus.accept(.todo) updateCatalogDataStatus.accept(.todo) insertDataStatus.accept(.todo) getDataStatus.accept(.todo) RefreshTokenManager.shared.refreshToken().do(onSuccess: { [self]_ in print("RefreshTokenManager onSuccess") refreshTokenStatus.accept(.completed) }, onError: { [self] error in print("RefreshTokenManager onError: \(error)") refreshTokenStatus.accept(.error) }, onSubscribe: { [self] in print("RefreshTokenManager onSubscribe") refreshTokenStatus.accept(.running) }).asObservable().concatMap { result in UpdateCatalogDataSyncManager.shared.updateCatalogData().do(onSuccess: { [self] in print("UpdateCatalogDataSyncManager onSuccess") updateCatalogDataStatus.accept(.completed) }, onError: { [self] error in print("UpdateCatalogDataSyncManager onError: \(error)") updateCatalogDataStatus.accept(.error) }, onSubscribe: { [self] in print("UpdateCatalogDataSyncManager onSubscribe") updateCatalogDataStatus.accept(.running) }).asObservable().concatMap { result in GetDataSyncManager.shared.getData().do { [self] in print("GetDataSyncManager onSuccess") getDataStatus.accept(.completed) } onError: { [self] error in print("GetDataSyncManager onError: \(error)") getDataStatus.accept(.error) } onSubscribe: { [self] in print("GetDataSyncManager onSubscribe") getDataStatus.accept(.running) } onDispose: { print("GetDataSyncManager onDispose") }.asObservable().concatMap { _ in InsertDataWorkSyncManager.shared.insertData().do { [self] in print("InsertDataWorkSyncManager onSuccess") insertDataStatus.accept(.completed) } onError: { [self] error in print("InsertDataWorkSyncManager onError: \(error)") insertDataStatus.accept(.error) } onSubscribe: { [self] in print("InsertDataWorkSyncManager onSubscribe") insertDataStatus.accept(.running) } onDispose: { print("InsertDataWorkSyncManager onDispose") } } } }.subscribe { _ in print("SyncManager onNext") } onError: { error in print("SyncManager onError: \(error)") completion(.failure(error)) } onCompleted: { print("SyncManager onCompleted") completion(.success(())) } onDisposed: { print("SyncManager onDisposed") }.disposed(by: disposeBag) } } enum SyncStatus { case todo case completed case error case running case partial } My ViewController : SyncManager.shared.refreshTokenStatus.skip(1).subscribe(onNext: { status in // Update UI }).disposed(by: disposeBag) SyncManager.shared.updateCatalogDataStatus.skip(1).subscribe(onNext: { status in // Update UI }).disposed(by: disposeBag) SyncManager.shared.insertDataStatus.skip(1).subscribe(onNext: { status in // Update UI }).disposed(by: disposeBag) I'm new to RxSwift (I've been using it for only a week) so I would like to know if there's a better approach to achieve my above goal. |
Is there any API endpoint to see the current maximum supply for EGLD? Posted: 11 Nov 2021 07:53 AM PST According to Elrond Economics paper the maximum supply for EGLD is 31,415,926 (theoretical). However, this theoretical cap is actually decreased with each processed transaction and generated fees. Is there any API endpoint that returns the actual maximum supply (adjusted based on the economics)? The closest endpoint that I found is: which returns: ... "totalSupply": 22711653, "circulatingSupply": 20051653, "staked": 12390333, ... |
How to draw a dotted circle using python Turtle package Posted: 11 Nov 2021 07:53 AM PST Something similar to the picture attached. I tried modifying the code I got online. But my code goes to infinity loop [1]: https://i.stack.imgur.com/HfKog.png def draw_circle(radius): turtle.up() turtle.goto(0, radius) # go to (0, radius) turtle.pendown() # pen down times_y_crossed = 0 x_sign = 1.0 while times_y_crossed <= 1: turtle.dot(5, "Red") turtle.forward(5) # move by 1/360 turtle.right(1.0) turtle.penup() turtle.forward(5) # move by 1/360 turtle.right(1.0) x_sign_new = math.copysign(1, turtle.xcor()) if x_sign_new != x_sign: times_y_crossed += 10 x_sign = x_sign_new turtle.up() # pen up return |
Hover is disturbing Posted: 11 Nov 2021 07:54 AM PST When I hover on the total-contents so the picture moves from its real place and the whole content in the div moves a bit and leaves its position .total-contents:hover .content-products { border: 2px solid #BC463A; } .total-contents:hover .content-products-text { background-color: #BC463A; transition: all .4s ease-in-out 0s; } .total-contents:hover .content-products-text a { color: #ffffff; text-decoration: none; } <div class="col-md-4 total-contents"> <div class="row"> <div class="col-12 content-products m-auto"> <img class="img-fluid d-inline mx-auto product-img-height" src="{{asset('images/products/14.jpg')}}" width="80%"> </div> <div class="col-12 text-center p-3 content-products-text"> <p class="text-capitalize m-auto"><a href="#" class="color-black">Partial Covered Rigid Boxes</a></p> </div> </div> </div> |
How to make TypeError: object of type 'NoneType' has no len() with hangman game go away Posted: 11 Nov 2021 07:55 AM PST import random #from words_txt import words # How the game is able to loop if user wants to play again hangmanGame = True while hangmanGame: def wordsPickedBank(): with open('words.txt', 'r') as file: allText = file.read() words = list(map(str, allText.split())) wordsPickedBank(random.choice(words)) wordPicked = wordsPickedBank() word_length = len(wordPicked) guesses = str.split("") end_of_game = False lives = 6 display = [] # Showing the user the number of spaces in the word for _ in range(word_length): display += "_" while not end_of_game: guess = str(input("Guess a letter: ")) guesses += guess # How the guessed letters are stored in a list for the user to see if guess: print(guesses) # Assigning the position of the word for position in range(word_length): letter = wordPicked[position] if letter == guess: display[position] = letter # Count down of how many times the user gets it wrong if guess not in wordPicked: lives -= 1 print(f"Lives = {lives}") if lives == 0: end_of_game = True print("you lose.") # Joining the word into one single string print(f"{' '.join(display)}") if "_" not in display: end_of_game = True print("you win") # Asking if they want to play again choice = input("New game? For yes, input: y or Y ." "\nWant to quit? Input: n or N\n") # Assigning the characters that define yes or no (caps included) if choice == 'y' or choice == 'Y': hangmanGame = True else: hangmanGame = False ** Having an error on line 14, can you please help in making this work? I am trying to make the word appear as "_" with the word selected at random from a text file. Can you show how to fix this so that the loop continues without showing the word to the user? ** |
EF Core IQueryable ordering by child property Posted: 11 Nov 2021 07:54 AM PST I'm trying to build an extension method to IQueryable which can sort a collection by entity child property. I have the following class: public class ViewPaymentOrder : Entity { public string ClientName { get; set; } // ... other properties public PaymentOrderME PaymentOrderME { get; set; } } And I need to sort by PaymentOrderME.RegisterDate . I have this function that works fine to sort by ViewPaymentOrder properties: public static IQueryable<T> OrderByField<T>(this IQueryable<T> source, string field, bool isDescending = true) { var type = typeof(T); var property = type.GetProperty(field); var parameter = Expression.Parameter(type, "p"); var propertyAccess = Expression.MakeMemberAccess(parameter, property); var arguments = Expression.Lambda(propertyAccess, parameter); var resultExp = Expression.Call(typeof(Queryable), isDescending ? "OrderByDescending" : "OrderBy", new[] { type, property.PropertyType }, source.Expression, arguments); return source.Provider.CreateQuery<T>(resultExp); } For example, by calling IQueryable<ViewPaymentOrder> query; //... query.OrderByField(nameof(ViewPaymentOrder.ClientName), isDescending); It sort perfectly. How can I adapt this function to be able to sort by PaymentOrderME class properties? Something like this IQueryable<ViewPaymentOrder> query; //... query.OrderByField(nameof(ViewPaymentOrder.PaymentOrderME.RegisterDate), isDescending); |
VBA code to take chart maximum and place it in a cell Posted: 11 Nov 2021 07:54 AM PST I have a chart sheet, from this I want to be able to take the maximum value of the primary axis and place the value in a cell in a different sheet. I have no idea how to tackle this |
Vue JS - variable from javascript module is not reactive Posted: 11 Nov 2021 07:53 AM PST I created a small module as a validator inspired from vee-validate and I would like to use this in conjunction with the composition api. I have a list of errorMessages that are stored in a reactive array, however when I retrieve this variable in my vue component, despite the error messages being stored in the array accordingly, the variable is not updating in the vue template. I'm not very savvy with this so I might not be concise with my explanation. The refs in the module seem to be working properly. Can someone kindly indicate what I might be doing wrong? I'm completely stuck and I don't know how else I can proceed. Validator.js (Npm module - located in node_modules) import Vue from 'vue'; import VueCompositionAPI from '@vue/composition-api' import {ref} from '@vue/composition-api' Vue.use(VueCompositionAPI) class Validator { …. register({fieldName, rules, type}) { if (!fieldName || rules === null || rules === undefined) { console.error('Please pass in fieldName and rules'); return false; } let errorMessages = ref([]); // define callback for pub-sub const callback = ({id, messages}) => { if (fieldId === id) { errorMessages.value = Object.assign([], messages); console.log(errorMessages.value); // this contains the value of the error messages. } }; return { errorMessages, }; } …… InputField.vue <template> <div :style="{'width': fieldWidth}" class="form-group"> <label :for="fieldName"> <input ref="inputField" :type="type" :id="fieldName" :name="fieldName" :class="[{'field-error': apiError || errorMessages.length > 0}, {'read-only-input': isReadOnly}]" @input="handleInput" v-model="input" class="form-input"/> </label> <div> <p class="text-error">{{errorMessages}}</p> // Error messages not displaying </div> </div> </template> <script> import {ref, watch} from '@vue/composition-api'; import Validator from "validator"; export default { props: { fieldTitle: { required: true }, fieldName: { required: true }, type: { required: true }, rules: { default: 'required' } }, setup(props) { // The error messages are returned in the component but they are not reactive. Therefore they only appear after its re-rendered. const {errorMessages, handleInput, setFieldData} = Validator.register(props); return { errorMessages, handleInput, } } } </script> |
Altering hdfs replication factor dynamically in spark Posted: 11 Nov 2021 07:54 AM PST In a Spark (3.2.0) application, i need to change the replication factor for different files written to HDFS. For instance, i write some temporary files, and i want them to be written with a replication factor 1. Then, i write some files that are going to be persistent, and i want them to be written with a replication factor 2, sometimes 3. However, as i tested; dfs.replication in SparkContext.hadoopConfiguration does not affect the replication factor of the file at all, whilst spark.hadoop.dfs.replication sets it (or changes the default replication that is set in HDFS side) only when the SparkSession is created with a previously defined SparkConf as below. val conf = new SparkConf() conf.set("spark.hadoop.dfs.replication", "1")) // works but cannot be changed later. val sparkSession: SparkSession = SparkSession.builder.config(conf).getOrCreate() Having made some search on the documentation, i came across with the configuration spark.sql.legacy.setCommandRejectsSparkCoreConfs that is added to core conf in Spark 3.0, and by default is set to true , and to change some other core confs it is needed to be set to false explicitly while the SparkSession is created. Even if i did that and prevent the errors like org.apache.spark.sql.AnalysisException: Cannot modify the value of a Spark config , setting replication factor to a different value by setting both configs in a function like below def setReplicationFactor(rf: Short): Unit = { val activeSparkSession = SparkSession.getActiveSession.get activeSparkSession.conf.set("spark.hadoop.dfs.replication", rf.toString) activeSparkSession.sparkContext.hadoopConfiguration.set("dfs.replication", rf.toString) } does not change the files being written with the updated SparkConf and SparkContext.hadoopConfiguration . Is there any way to achieve writing files to HDFS with different replication factors within the same spark session? |
mvn build failed with error Failed to execute goal [closed] Posted: 11 Nov 2021 07:54 AM PST Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile (default-compile) on project running on docker 3.6.3 deleting folder m2 didnt helped adding pom file <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.test.common</groupId> <artifactId>rabbitMqMessages-api</artifactId> <name>rabbitMQ Messages</name> <packaging>jar</packaging> <version>1.113.0.15</version> <parent> <groupId>com.test.common</groupId> <artifactId>common-parent</artifactId> <version>1.73.0.2</version> </parent> <dependencies> <dependency> <groupId>com.test.common</groupId> <artifactId>messageQueueApi</artifactId> <version>1.57.0.1</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.9.3</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.9.3</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>2.9.3</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.datatype</groupId> <artifactId>jackson-datatype-jsr310</artifactId> <version>2.10.3</version> </dependency> </dependencies> </project> |
react.js BEST WAY: show or hide html element on state change [closed] Posted: 11 Nov 2021 07:53 AM PST What is the best way to hide or show a div (or whatever element) on a state change. Here is what I did: React.useEffect(()=>{ (async () => { alert(props.changeVisibiltyEvent) })() },[props.changeVisibiltyEvent]) This effect is called whenever something else happens in my app. The alert displays a 0 or a 1. If it is zero, the element should be invisible, if it is one, I want it to become visible. Easy. This is the element: <td style={{ visibility: 'hidden' }}> <Button variant="contained" onClick={() => changeCase('closeCase')}>fall schließen</Button> </td> I managed to find the attribute 'hidden' to hide it and 'visible' to show it. What is the best practice to bind the state changed 0 or 1 to visible to hidden in the element? |
How to remove all but the unversioned git files from a directory? Posted: 11 Nov 2021 07:54 AM PST I wanted to put a lot of files in a repository. However, their size exceeds 10GB. And they are a lot of files. The total storage is around 13gb. I am thinking of ways to go about this. Now I am thinking of creating a separate repository where I could push the rest of the files. But since there are many files, it would be too tedious to do that manually. Is there some way to see which files have not been added to git (maybe they are called unversioned files)? and then remove all but the unadded files. And then init a new repo on the same folder and push the rest to the other repository. Please let me know if this is possible. I am open to using shell or a python wrapper around git if that exists. The files are unrelated to each other so it's not a big deal that they would be saved in two separate repositories. |
The PM value is not set in the Material Ui DateTimePicker. How can I fix it? Posted: 11 Nov 2021 07:54 AM PST <Grid> <DateTimePicker renderInput={(params) => <TextField {...params} />} label='공구 시작일' value={startDt} onChange={(newValue) => { setStartDt(format(newValue, 'yyyy-MM-dd hh:mm:ss')) }} inputFormat='yyyy-MM-dd hh:mm a' /> </Grid> I try to get the time value using the material Ui, but AM and PM are not working. Only AM is brought ex) PM 11:11 -> AM 11:11 is automatically changed. I don't know what the problem is. I clicked PM, but value is only AM: |
How to build Aggregations on Apache Solr with Spark Posted: 11 Nov 2021 07:54 AM PST I have a requirement to build aggregations on the data that we receive to our Apache Kafka... I am little bit lost which technlogical path to follow... It seems people see the standard way, a constellation of Apache Kafka <-> Apache Spark <-> Solr Bitnami Data Platform I can't find concrete examples how this actually functions, but I am also asking myself would any solution von Apache Kafka <-> Kafka Connect Solr <-> Solr would not do the trick becasue solr supports aggregations also... Solr Aggregation but I saw some code snippets that aggregate the Data in Spark and write under special index to Solr..... Also probably aggregation mit Kafka <-> Kafka Connect Solr <-> Solr will only function for only one Topic from Kafka, so if I have to combine the data from 2 or more, different Topics and aggregate, then Kafka, Spark, Solr is way to go.... (or this viable at all) So as you may read, I am little bit confused, so I like to ask here, how are you approching this problem with your real life solutions.... Thx for answers... |
Power BI - Date slicer not working on merge queries Posted: 11 Nov 2021 07:54 AM PST Hi I have a report that has a left join merge queries based on report name so i can count the total number of executions of a particular report, but it not refreshing the table once a select a relative date from the date slicer. Is it because the total execution is aggregated by report name? or is there i way i can add the execution date in the merge query? Merge Queries List of fields (Merge New Query - Left join on ReportName) |
Firebase Function that looks into child collection documents for update and returns sum of values in parent collection Posted: 11 Nov 2021 07:54 AM PST My Firestore database is setup as follow: /users/{userId}/tenants/{tenantId}/invoices/{invoiceId} In each invoice document (InvoiceId), there are ["status"] and ["amount"] fields. ["status"] can be either "Pending" or "Paid". Every time there is an update to "status" inside of an invoiceId document, I would like to get the sum of all "amounts" where "status" == "Pending" from the respective invoice collection that was just updated. Then I want to set this new balance data to the respective tenantId document. The following script calculates the sum for all documents where "status" == "Pending" whenever an invoiceId document is updated. However, I would like to calculate the sum of "amounts" only for the invoice collection that was updated (not all). For example: suppose there's tenants A and B, each with many invoices. An invoice under tenant A is updated. I would like to calculate the new sum of "amounts" for tenant A (and not B). Let me know if this is even possible. exports.invoiceUpdated = functions.firestore .document('/users/{userId}/tenants/{tenantId}/invoices/{invoiceId}') .onUpdate(async (snap, context) => { const task = await (db.collectionGroup('invoices').where('status', '==', "Pending").get()); if (task.empty) { console.log('No pending invoices...') return; } var total= 0; task.forEach(element => { console.log(element.data().amount) total += element.data().amount }) });``` |
Match Data in Excel using python Posted: 11 Nov 2021 07:54 AM PST I am making a betting software that scrapes the fixtures from a website, puts them into an Excel file and then compares it with another Excel file that I have already manually created to find the winner (the source) The source file would look like this and The scraped output would look like this What I want to do is for the software to find matching fixtures between the two files, then figure out the result using the "Result" column in the source file. Problem is I don't know how to do it, and I have no idea how to look for it, I'm such a beginner and I picked this project for school, can someone at least give me a name to what I'm trying to do (if it has a name), an idea, a path to follow, etc... Thanks a lot to everyone ! Here is my code for now (Only scraping and making an Excel file) import requests from bs4 import BeautifulSoup as bs import pandas as pd #Formation de l'url à scraper url= "https://www.bbc.com/sport/football/scores-fixtures/" date = input(str("Input the date, hit Enter for today")) src = url + date #Scraping de la page web, balise abbr avec attribut title html = requests.get(src).text soup = bs(html, 'lxml') select = soup.find_all('abbr') fixtures = [] for abbr in select: if abbr.has_attr('title'): output = str(abbr['title']) fixtures.append(output) #Création tableau excel, liste[position :: itération] table = pd.DataFrame() table['Home'] = pd.Series(fixtures[::2]) table['Away'] = pd.Series(fixtures[1::2]) name = 'fixtures' + '-' + date + '.xlsx' table.to_excel(name, index=False) =====EDIT====== I think it's gonna be easier if I explain the purpose of my Excel manual Source. It is a file that contains some very renowned fixtures and their outcome (the result), it's what we call in French "bête noire", basically a team that never wins against another. And now what I'm trying to do is for the program to look up the games of the day (or any certain date), match it against that Excel file to see if there's any "bête noire", if so, it should return the fixture with the winner (result/outcome). EXAMPLE : The scraped data : Home | Away | Liverpool | Manchester U | Burnley | West Ham | Arsenal | Chelsea | Tottenham | Brentford | The Manual Excel source file that I have : Home | Away | Result | Liverpool | Manchester U | Liverpool | TestTeam | TestTeam | TestTeam | TestTeam | TestTeam | TestTeam | TestTeam | TestTeam | TestTeam | Arsenal | Chelsea | Chelsea | TestTeam | TestTeam | TestTeam | TestTeam | TestTeam | TestTeam | TestTeam | TestTeam | TestTeam | Now the program should be able to match the data that it scraped against my Excel file, find the matching fixtures (Liverpool//Manchester U ; Arsenal//Chelsea), then return the result of the fixture. I hope this has cleared any confusion, and thanks to everyone for their help I really appreciate it ! |
C# looking for subarrays in large byte array representing strings Posted: 11 Nov 2021 07:53 AM PST In my application I need to open a file, look for a tag and then do some operation based on that tag. BUT! the file content alternates every char with a /0 , so that the text "CODE" becomes 0x43 0x00 0x4F 0x00 0x44 0x00 0x45 0x00 (expressed in hex byte). The issue is that the terminator is also a /0 , so the "CODE123" with the terminator would look something like this: 0x43 0x00 0x4F 0x00 0x44 0x00 0x45 0x00 0x31 0x00 0x32 0x00 0x33 0x00 0x00 0x00 Since /0 is the null string terminator, if I use File.ReadAllText() i get only garbage, so I tried using File.ReadAllBytes() and then purging each byte equal to 0 . This gets me readable text, but then I lose information on when the data ends, i.e. if in the file there was CODE123[terminator]PROP456[terminator]blablabla I end up with CODE123PROP456blablabla. So I decided to gets the file content as a byte[] , and then look for another byte[] initialized with the CODE-with-/0-inside data. This theoretically should work, but since the data array is fairly large (about 1.5 million elements) this takes way too long. The final cherry on the cake is that I am looking for multiple occurences of the CODE tag, so I can't just go and stop as soon as I find it. I tried modifying the LINQ posted as answer here: Find the first occurrence/starting index of the sub-array in C# as follows: var indices = (from i in Enumerable.Range(0, 1 + x.Length - y.Length) where x.Skip(i).Take(y.Length).SequenceEqual(y) select (int?)i).ToList(); but as soon as I tried to enumerate the result it just hogs down. So, my question is: how could I EFFICIENTLY find multiple subarrays in a large array? thanks |
You are loading the CommonJS build of React Router on a page that is already running the ES modules build, so things won't work right Posted: 11 Nov 2021 07:54 AM PST Error: You are loading the CommonJS build of React Router on a page that is already running the ES modules build, so things won't work right. //App.js import React from "react"; import styled from "styled-components"; import LandingPage from "../src/pages/LandingPage"; import MainPage from "../src/pages/MainPage"; import Question from "../src/components/QuestionIcon"; import RichRoadLogo from "../src/img/richroad.png"; import { BrowserRouter as Router, Route, Switch } from "react-router-dom"; function App() { return ( <Router> <Container> <Head> <Logo src={RichRoadLogo} /> <Profile /> </Head> <Switch> <Route exact path="/"> <Body> <LandingPage /> </Body> </Route> <Route exact path="/main"> <Body> <MainPage /> </Body> </Route> </Switch> <Question /> </Container> </Router> ); } //LandingPage.js import React from "react"; import styled from "styled-components"; import google from "../img/google.png"; import { Link } from "react-router-dom"; //This is the problem. function LandingPage() { return ( <Container> <Text> 나의 투자 수익률을 <br /> 기록해보세요 </Text> <LoginButton src={google} /> <Link to="main"> <GuestButton>구경하기</GuestButton> </Link> </Container> ); } If you write import { Link } from "react-router-dom" from LandingPage.js, you get an error. Please, I need your help. "react-router-dom" version is ^5.2.1 |
How to upload data to Tableau Server in Python Posted: 11 Nov 2021 07:54 AM PST I need to run a python script and it should upload/update a data file on a tableau server, so the dashboard linked to the datafile on the server will be automatically updated every time I run my python script. I am not exactly sure how to do that, the file I need to send to the tableau server is in a csv format - but I think the server only works with tableau files? Also I am not sure what API to be using for this purpose |
Rails - Back button duplicating elements Posted: 11 Nov 2021 07:54 AM PST I've come across an issue where a user can go to a certain page, go to a new page, press the chrome back button (happens with all major browsers) and some elements will be duplicated. The elements in question come from JavaScript within a partial view I am rendering as part of that page. I have seen some people having this issue while using turbolinks, however I don't have that installed so I am not sure what is causing this issue. I have tried putting bindings in Chrome dev console on the JavaScript that is run to create these elements, however on Chrome back button press, it doesn't trigger, so I'm not sure why they are being duplicated. Below is what I'm doing to create the elements that are being duplicated: theFieldset = document.getElementsByTagName("fieldset")[0]; editForm = document.getElementById("edit_pattern"); theFieldset.innerHTML += "<div class='form-group control-group belongs_to_association_type pattern_field ' id='pattern_html_block_id_field'><label class='col-sm-2 control-label' for='pattern_pattern_html_block'>Attach template</label><div class='controls col-sm-10' data-children-count='2'><select data-filteringselect='true' placeholder='Search' name='email[pattern_id]' id='pattern_pattern_html_block' style='display: none;'><option value=''></option></select><span class='help-block'>Optional. </span></div></div><div class='form-group control-group belongs_to_association_type pattern_field ' id='pattern_pattern_field' style='display:none'><label class='col-sm-2 control-label' for='currentTemplate'>Current template</label><div class='controls col-sm-10' data-children-count='2'></div><br><label class='col-sm-2 control-label' for='pattern_pattern_html_block'>Attach template</label><div class='controls col-sm-10' data-children-count='2'></div></div>"; Edit: Neither turbolinks nor hotwire is installed. Have been unsuccessful in trying to individually create elements and adding them to the fieldset rather than adding in bulk via innerHTML or insertAdjacentHTML. |
How to debug using npm run scripts from VSCode? Posted: 11 Nov 2021 07:54 AM PST I was previously using gulp and running gulp to start my application and listeners from the Visual Studio Code debugger but have recently needed to switch to running scripts through npm instead. Unfortunately in VSCode I've not been able to run npm scripts through the debugger so I've had to resort to running node to start my server directly which gets rid of my listener tasks which reloaded code automatically. This seems like something that should be simple but so far I haven't had much luck. Below is a snippet from my launch.json file that I attempted to use but npm could not be located. { ... "program": "npm", "args": [ "run", "debug" ], ... } This gives me the following error. Error request 'launch': program 'c:\myproject\npm' does not exist Related resources: |
No comments:
Post a Comment