Pay with Stripe Posted: 11 May 2021 09:06 AM PDT I am trying to make a payment gateway with Stripe and I have more questions than solutions. I explain the business model to see if someone can help me. Company "X" has a parking APP. A user "A" can find a place to park his car and a user "B" can save the place for him. If all goes well, payment needs to be made. The "problem" with the payment is that user "A" does not pay directly to user "B" (to his Stripe account, because he does not need one?), But rather that the money goes through the company's Stripe account , the company keeps a commission and then pays user "B". What I have done so far is: - Create a Connected account (trial mode)
- Create a PaymentIntent in which I put the "Amount", the "ApplicationFeeAmount" and the TransferData [Destination] of the recipient's connected account. I send the "Amount" to the company's Stripe account, subtract the "ApplicationFeeAmount" and send the money to the connected account of user "B" (which is then automatically or manually sent to his bank / card account) The "problem" I see with this is that when using connected accounts, the money is sent directly to the bank or debit card and I cannot use it, for example, to pay with Stripe balance.
Can anyone help me? Thanks! |
Time-based series categorisation Posted: 11 May 2021 09:06 AM PDT I have a data collection that contains various measurements taken during the week. I would like to identify the start and end of the weekly measurements and group them as follow. If there is no gap between the start and end day then: a.) 1 day (start=end); b.) 2 days; c.) 3 days; d.) 4 days; e.) 5 days; f.) 6 days and g.) 7 days. If there is a gap between the measurement I would like to keep the id and weekly measurement structure. Example: Input Output Sample data: df<-structure(list(Id = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38), A = c(0, 0, 0, 0, 41, 0, 51, 0, 0, 41, 0, 0, 0, 0, 0, 43, 49, 0, 0, 29, 0, 48, 0, 0, 0, 0, 0, 0, 52, 62, 47, 21, 0, 42, 0, 3, 0, 0), B = c(0, 0, 0, 0, 0, 0, 51, 0, 0, 7, 45, 0, 46, 0, 44, 21, 51, 48, 0, 0, 47, 42, 0, 0, 0, 0, 43, 0, 59, 56, 0, 57, 0, 46, 0, 44, 0, 0), C = c(0, 0, 0, 0, 25, 0, 50, 0, 0, 0, 55, 0, 49, 0, 46, 17, 51, 41, 0, 49, 51, 23, 0, 0, 0, 0, 38, 0, 57, 70, 46, 53, 0, 4, 0, 2, 0, 0), D = c(0, 0, 0, 0, 42, 0, 63, 0, 0, 8, 0, 0, 0, 0, 47, 24, 29, 0, 0, 0, 53, 35, 0, 0, 48, 0, 0, 0, 0, 14, 0, 60, 0, 53, 0, 49, 0, 0), E = c(0, 0, 0, 0, 0, 0, 46, 0, 0, 48, 0, 0, 46, 0, 43, 0, 0, 0, 0, 0, 46, 0, 0, 0, 48, 0, 26, 0, 0, 58, 46, 51, 0, 40, 0, 48, 0, 0), F = c(0, 0, 0, 0, 0, 0, 0, 0, 55, 0, 0, 0, 0, 0, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), G = c(0, 0, 0, 0, 0, 0, 0, 0, 60, 0, 0, 0, 0, 0, 52, 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), Total = c(0, 0, 0, 1080, 0, 2610, 0, 1150, 1040, 1000, 0, 1410, 0, 2720, 1050, 1800, 890, 0, 780, 1970, 1480, 140, 0, 960, 0, 1290, 0, 1680, 2600, 1390, 2420, 0, 1850, 0, 1460, 0, 0, 1670)), class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame"), row.names = c(NA, -38L), spec = structure(list( cols = list(Id = structure(list(), class = c("collector_double", "collector")), A = structure(list(), class = c("collector_double", "collector")), B = structure(list(), class = c("collector_double", "collector")), C = structure(list(), class = c("collector_double", "collector")), D = structure(list(), class = c("collector_double", "collector")), E = structure(list(), class = c("collector_double", "collector")), F = structure(list(), class = c("collector_double", "collector")), G = structure(list(), class = c("collector_double", "collector")), Total = structure(list(), class = c("collector_double", "collector"))), default = structure(list(), class = c("collector_guess", "collector")), skip = 1L), class = "col_spec")) |
Python pandas print each group from a groupby object as a single row Posted: 11 May 2021 09:06 AM PDT I am having a groupby object ref query_x query_y ANN00118-RA Charonia_GIQZ01011680.1.p1 Typhlosyrinx_Contig7942.p1 ANN00127-RA Charonia_GIQZ01023156.1.p1 Typhlosyrinx_Contig11188.p1 ANN00130-RA Charonia_GIQZ01000168.1.p1 Typhlosyrinx_Contig15281.p1 The data are grouped by the column "ref". It happens that many lines have the same ref, for example test.get_group('ANN12010-RA') query_x ref query_y 0 Charonia_GIQZ01000001.1.p1 ANN12010-RA Typhlosyrinx_Contig13935.p1 1 Charonia_GIQZ01000001.1.p1 ANN12010-RA Typhlosyrinx_Contig13936.p1 2 Charonia_GIQZ01000001.1.p1 ANN12010-RA Typhlosyrinx_TRINITY_DN17744_c0_g2_i1.p1 3 Charonia_GIQZ01000001.1.p1 ANN12010-RA Typhlosyrinx_TRINITY_DN18267_c0_g1_i1.p2 As you see, the second column has identical values ANN12010-RA, I would like to print each "ref" block in its own file, on a single row. Expected output from the example ANN12010-RA Charonia_GIQZ01000001.1.p1 Typhlosyrinx_Contig13935.p1 Charonia_GIQZ01000001.1.p1 Typhlosyrinx_Contig13936.p1 Charonia_GIQZ01000001.1.p1 Typhlosyrinx_TRINITY_DN17744_c0_g2_i1.p1 Charonia_GIQZ01000001.1.p1 Typhlosyrinx_TRINITY_DN18267_c0_g1_i1.p2 The order of elements is not important. The number of columns per row can vary, I don't know how many elements each group has. What's the best way to achieve this? Knowing the groupby object can be thousands of lines long. Thanks a lot |
Ask about TableView in JavaFX Posted: 11 May 2021 09:06 AM PDT I have a TableView. With a class include 3 attributes: name, age and School sc (class School have attributes: name) I do: col1.setCellValueFactory(new PropertyValueFactory<>("name")); col2.setCellValueFactory(new PropertyValueFactory<>("age")); tbv.setItems(data); and I want TableView show "name" of class School. How can I do? I tried col3.setCellValueFactory(new PropertyValueFactory<>("School.name")); but TableView show nothing. |
Question about `input_fn` in Tensorflow's multi worker estimator tutorial Posted: 11 May 2021 09:06 AM PDT In this tutorial, function input_fn has a param named mode . I can't figure out how this param get passed to input_fn when training. BUFFER_SIZE = 10000 BATCH_SIZE = 64 def input_fn(mode, input_context=None): datasets, info = tfds.load(name='mnist', with_info=True, as_supervised=True) mnist_dataset = (datasets['train'] if mode == tf.estimator.ModeKeys.TRAIN else datasets['test']) def scale(image, label): image = tf.cast(image, tf.float32) image /= 255 return image, label if input_context: mnist_dataset = mnist_dataset.shard(input_context.num_input_pipelines, input_context.input_pipeline_id) return mnist_dataset.map(scale).cache().shuffle(BUFFER_SIZE).batch(BATCH_SIZE) |
Repeat each element of vector N times according to other vector R Posted: 11 May 2021 09:06 AM PDT I have a vector of values, in which I would like to recursively repeat each element a variable amount of N times according to another vector, using R. I know how to repeat each element exactly the same N times with repeat(x, each=N), but I cannot figure it out how to generate a variable number of repetitions. An example: Vector of values 0.5, 0.3, 0.2, 0.3, 0.1, 0.5, 0.1, 0.7 .... Vector of repetition 2, 2, 3, 4, 3, 1, 5, 4 .... Expected result 0.5, 0.5, 0.3, 0.3, 0.2, 0.2, 0.2, 0.3, 0.3, 0.3, 0.3, 0.1, 0.1, 0.1, 0.5, 0.1, 0.1, 0.1, 0.1, 0.1, 0.7, 0.7, 0.7, 0.7 .... I guess some kind of apply function family could work but cannot get the proper code to do it... Could anyone help? Many thanks |
Youtube Video with Youtube API inside an image responsive like a TV Posted: 11 May 2021 09:06 AM PDT I´m trying to put a video inside an image that appears like a tv. I wanted to be responsive and in the center of the screen. My attempt puts the video below the image and I can´t play it. ALready tried to mess with the z-index attribute but no luck. Note: using Bootstrap 4 <style> .video-container { position: relative; overflow: hidden; } .tv img { position: absolute; z-index: -10; } </style> <script> var player; function onYouTubePlayerAPIReady() { player = new YT.Player('yt', { height: '100%', width: '100%', videoId: 'WMn1_DAIpIs', playerVars: { 'autoplay': 1, 'controls': 0, 'showinfo': 0 }, events: { 'onReady': onPlayerReady, // function when the player is ready 'onStateChange': onPlayerStateChange // function called when the player changes state (playing, stoped, paused, etc.) } }); } </script> <div class="row align-items-center"> <div class="col"> <div class="video-container "> <img src="src/images/tv31.png" class="img-fluid"> <div class="tv" id=yt></div> </div> </div> </div> </div> |
C++ constructor has no object [duplicate] Posted: 11 May 2021 09:06 AM PDT I just learned about the constructor, and there is a question I am not sure, whether Person(10) is actually Person px(10), and then p2 = px. But the printed result is "paramererized constructor!" and "Destructor!" ", there is no "Copy Constructor!". Is the system automatically optimized or I made a mistake? class Person { public: Person() { cout << "default constructor!" << endl; } Person(int a) { age = a; cout << "paramererized constructor!" << endl; } Person(const Person& p) { age = p.age; cout << "Copy Constructor!" << endl; } ~Person() { cout << "Destructor!" << endl; } public: int age; }; int main() { Person p2 = Person(10); return 0; } |
Java spring boot profiles in multiple properties files Posted: 11 May 2021 09:05 AM PDT Is it possible to use profiles with multiple properties files in spring boot? I have some modules, call it "moduleA" and "api" All modules have own properties files api (just a library) - api.properties
- api-dev.properties
- api-prod.properties
moduleA (contains main method) - application.properties. <- here is profiles.active set, for example to "prod"
- application-test.properties
- application-prod.properties
- moduleA.properties
Loading the api.properties file in moduleA works fine. Also loading the profile prod in moduleA works fine. But it loads just the content of application-prod.properties. From the api module always the "normal" api.properties is loaded. api-prod is ignored. |
Accessing version number for deployed Cloud Function in Python Posted: 11 May 2021 09:05 AM PDT Similar to this Stack Overflow question asked for node.js, I am wondering if there is some way for the deployed Cloud Function in python to access its own version number. I cant find the answer to this anywhere. Thanks! |
TypeError: Cannot read property 'open' of undefined with react native datepicker Posted: 11 May 2021 09:05 AM PDT After searching the internet for similar issues, I couldn't find any solutions to my problem. hope someone can tell me why and how to fix it. My datepicker modal doesn't open but I don't understand where this error is coming from ... Any idea ? My form : import React, { useState } from 'react'; import { DeliveryDatePicker } from './datePicker'; import moment from 'moment'; import { connect } from 'react-redux'; import { createDelivery } from '../store/actions/delivery'; import { Formik } from 'formik'; import * as yup from 'yup'; const reviewSchema = yup.object({ deliveryDate: yup.date() .required() }); function AddDeliveryForm(props) { return ( <Formik initialValues={{ deliveryDate: moment().format('YYYY-MM-DD') }} onSubmit={values => console.log(values)}> {({ handleSubmit, values, setFieldValue }) => ( <DeliveryDatePicker values={values} setFieldValue={setFieldValue} handleSubmit={handleSubmit} /> )} </Formik> ); } const mapStateToProps = (state) => ({ auth: { user: state.auth.user, company: state.auth.company, runer: state.auth.runer }, users: state.users, products: state.products }) const mapDispatchToProps = { createDelivery } export default connect(mapStateToProps, mapDispatchToProps)(AddDeliveryForm) My datepicker : import React, { useState } from 'react'; import DateTimePickerModal from 'react-native-modal-datetime-picker'; import { StyleSheet, Button, ScrollView, View, Text } from 'react-native'; import moment from 'moment'; export const DeliveryDatePicker = props => { const { handleSubmit, values, setFieldValue } = props; const [isDatePickerVisible, setDatePickerVisibility] = useState(false); const showDatePicker = () => { console.log("enter in showModaleDate"); setDatePickerVisibility(true); }; const hideDatePicker = () => { setDatePickerVisibility(false); }; const handleConfirm = date => { setFieldValue('deliveryDate', moment(date).format('YYYY-MM-DD')) hideDatePicker(); }; return ( <View> <Text onPress={showDatePicker}>{moment(values.deliveryDate).format('YYYY-MM-DD')}</Text> <DateTimePickerModal isVisible={isDatePickerVisible} mode="date" onConfirm={handleConfirm} onCancel={hideDatePicker} date={moment(values.deliveryDate).toDate()} /> <Button title="Submit" onPress={handleSubmit} /> </View> ); } image of error on console in debugger image of error in expo |
Duplicade yAxisID Posted: 11 May 2021 09:05 AM PDT When I add yAxisID to the dataset options it adds an extra column to the right that I can't remove. I leave an example of the result var ctx = document.getElementById("myChart"); var myChart = new Chart(ctx, { type: 'line', data: { datasets: [{ type: 'line', label: "Ventas", data: [{x:new Date(), y:100},{x:new Date(), y:300}], yAxisID: 'y-axis-1' }] }, options: { scales: { x: { }, y: { suggestedMin:0, suggestedMax:300, ticks: { stepSize: 10, callback: function(value, index, values) { return value+'€'; } } } } } }); https://codepen.io/soporte-indole/pen/gOmaBNj |
Is there a way to quickly turn text to an array in python in vscode? Posted: 11 May 2021 09:05 AM PDT i have a long list (~5000) of hash digest, the list looks like this: F5CA38F748A1D6EAF726B8A42FB575C3C71F1864A8143301782DE13DA2D9202B 6F4B6612125FB3A0DAECD2799DFD6C9C299424FD920F9B308110A2C1FBD8F443 785F3EC7EB32F30B90CD0FCF3657D388B5FF4297F2F9716FF66E9B69C05DDD09 535FA30D7E25DD8A49F1536779734EC8286108D115DA5045D77F3B4185D8F790 C2356069E9D1E79CA924378153CFBBFB4D4416B1F99D41A2940BFDB66C5319DB B7A56873CD771F2C446D369B649430B65A756BA278FF97EC81BB6F55B2E73569 5F9C4AB08CAC7457E9111A30E4664920607EA2C115A1433D7BE98E97E64244CA ... Is there a fast way to turn this into an array, kind of like this: Array = [F5CA38F748A1D6EAF726B8A42FB575C3C71F1864A8143301782DE13DA2D9202B, 6F4B6612125FB3A0DAECD2799DFD6C9C299424FD920F9B308110A2C1FBD8F443, 785F3EC7EB32F30B90CD0FCF3657D388B5FF4297F2F9716FF66E9B69C05DDD09, 535FA30D7E25DD8A49F1536779734EC8286108D115DA5045D77F3B4185D8F790, C2356069E9D1E79CA924378153CFBBFB4D4416B1F99D41A2940BFDB66C5319DB, B7A56873CD771F2C446D369B649430B65A756BA278FF97EC81BB6F55B2E73569, 5F9C4AB08CAC7457E9111A30E4664920607EA2C115A1433D7BE98E97E64244CA, ...] I am using vscode. |
Why there is a problem if there is an empty stack (java) Posted: 11 May 2021 09:06 AM PDT (leetCode #20) Coding Question : Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: - Open brackets must be closed by the same type of brackets.
- Open brackets must be closed in the correct order.
Now here is the answer to this coding question. class Solution { public boolean isValid(String s) { Stack <Character> stack = new Stack <Character>(); for (char c: s.toCharArray()) { if (c == '(' || c == '{' || c == '[') { stack.push(c); } else if (c == ')' && !stack.isEmpty() && stack.peek() == '(') { stack.pop(); } else if (c == '}' && !stack.isEmpty() && stack.peek() == '{') { stack.pop(); } else if (c == ']' && !stack.isEmpty() && stack.peek() == '[') { stack.pop(); } else return false; } return stack.isEmpty(); } } I am a bit confused that what is the purpose of the "!stack.isEmpty()"? If I erase them, and put "]" for it put, it throws an runtime error which said "java.util.EmptyStackException". Can anyone clarify this? I learned the stack today, so I am bit confused. |
how do i specify wich one to open Posted: 11 May 2021 09:05 AM PDT ok so here is my code: from tkinter import * import os def playWAD(filename): wadlistthing =(GZwadPath, filename) playwad = '\\'.join(wadlistthing) os.startfile(playwad) paths = open('config.txt', 'r') root = Tk() root.title("GZlauncher") root.configure(background="black") GZwadPath = paths.readline(30) paths.close wads = os.listdir(GZwadPath) rownum=2 for file in wads: Button(root, text="PLAY", width=4, command=lambda: playWAD(file)) .grid(row=rownum, column=1, sticky=N) Label(root, text=file, bg="black", fg="white") .grid(row=rownum, column=2, sticky=N) rownum +=1 root.mainloop() the problem is that i get a list of wads like i should. but when i press the play button it opens the last one loaded. how do i fix this? |
Amazon Pay Sandbox Error when trying to login on localhost - "Scheme not HTTPS" Posted: 11 May 2021 09:06 AM PDT I am trying to integrate Amazon Pay for a web shop. The login button is displayed correctly but as soon as I login with my sandbox account credentials to show the address widget I get the following error in my Chrome dev tools console: [Amazon.error] attempted redirect to http://myownvirtualhost.local/shop.html?... but scheme is not HTTPS. So the error is obvious but how do I fix this? After login the redirect is supposed to happen on a HTTPS url but as already mentioned I am developing on my localhost with a configured virtual host. I also use the correct (EU) sandbox Widget.js file and set sandbox mode to true in my PHP configuration. My code: OffAmazonPayments.Button('amazonPayButton', 'MERCHANT-ID', { type: 'PwA', language: 'de-DE', authorization: function() { loginOptions = {scope: 'profile postal_code payments:widget payments:shipping_address', popup: true }; authRequest = amazon.Login.authorize(loginOptions, 'http://myownvirtualhost.local/shop.html?action=cart'); }, onError: function (error) { console.log('auth request: ' + error.getErrorCode() + ': ' + error.getErrorMessage()); } }); I didn't provide my merchant id as this is an example. So my redirect url has HTTP as scheme and this is the cause of the error. I am confused because after reading the registration chapter of the Amazon Pay Integration guide I thought SSL is not relevant on localhost. From the integration guide: Obtain an SSL certificate. Your server is required to have a valid SSL certificate issued by a trusted Certificate Authority. Note: When working in a "localhost" environment, an SSL certificate is not required. For more information, see SSL certification. Any help is appreciated. Thanks in advance! |
How to read data from file in c++ Posted: 11 May 2021 09:05 AM PDT I am writing this code because of my project. I want to do person will select his/her decisions for example He want to read History books with 10-50 dollars and 100-200 pages and my program shows History books with in 10-50 dollars ranges and 100-200 pages in ranges. I write data about books in text file but how can i read and compare please help me. #include <iostream> #include <fstream> using namespace std; class BookShop{ protected: int usertema; int userfiyat; int usersayfaaraligi; public: int tur; void Karsilama(){ cout<<"Hosgeldiniz secmek istediginiz türü seciniz"<<endl; cout<<"1:modern klasik \n 2:Turkedebiyati \n 3:Dunyaklasigi"; cin>>tur; } }; class ModernKlasik:public BookShop{ public: ModernKlasik() { cout<<"Aradiginiz kitap temasi nedir?"; cout<<"\n1:Korku\n2:Aşk\n3:Sevgi\n4:Dram\n5:Kahramanlık\n"; cin>>usertema; cout<<"Sayfa sayisi?:"; cout<<"\n1:[0-50]\n2:[50-100]\n3:[100-200]\n4:[200-300]\n5:[400-500]\n6:[500+]"; cin>>usersayfaaraligi; cout<<"Bir fiyat araligi giriniz:"; cin>>userfiyat; if(userfiyat>=0 && userfiyat<=50){ cout<<userfiyat<<endl; } } void fonksiyon1(){ ofstream myFile1("Modernklasik.txt"); myFile1<<"Kitap1:Tema= ,Sayfa sayisi=50,Fiyat=6 TL,Adý=Mecburiyet(Stefan Zweig)"<<endl; myFile1<<"Kitap2:Tema= ,Sayfa sayisi=70,Fiyat=8 TL,Adý=Feniçka(Lou Andreas-Salome)"<<endl; myFile1<<"Kitap3:Tema= ,Sayfa sayisi=74,Fiyat=8 Tl,Adý=Ayýþýðý Sokaðý(Stefan Zweig)"<<endl; myFile1<<"Kitap4:Tema= ,Sayfa sayisi=108,Fiyat=11 TL,Adý=Vahþetin Çaðrýsý(Jack London)"<<endl; myFile1<<"Kitap5:Tema= ,Sayfa sayisi=150,Fiyat=20 TL,Adý=Hayvan Çiftliði(George Orwell)"<<endl; myFile1<<"Kitap6:Tema= ,Sayfa sayisi=256,Fiyat=15 Tl,Adý=Karmaþýk Duygular(Stefan Zweig)"<<endl; } }; class Turkedebiyati:public BookShop{ public: Turkedebiyati() { cout<<"Aradiginiz kitap temasi nedir?"; cout<<"\n1:Korku\n2:Aşk\n3:Sevgi\n4:Dram\n5:Kahramanlık\n"; cin>>usertema; cout<<"Sayfa sayisi?:"; cout<<"\n1:[0-50]\n2:[50-100]\n3:[100-200]\n4:[200-300]\n5:[400-500]\n6:[500+]"; cin>>usersayfaaraligi; cout<<"Fiyat araligi?:"; cout<<"\n1:[0-10]TL\n2:[10-20]TL\n3:[20-50]TL\n4:[50-75]TL\n5:[75-100]TL\n6:[100+]TL"; cin>>userfiyat; } void fonksiyon2(){ ofstream myFile2 ("Turkedebiyati.txt"); myFile2<<"Kitap1:Tema= ,Sayfa sayisi=409,Fiyat=20 TL,Adý=Çalýkuþu(Reþatnuri Gültekin)"<<endl; myFile2<<"Kitap2:Tema= ,Sayfa sayisi=164,Fiyat=5 TL,Adý=Kürk Mantolu Madonna(Sabahattin Ali)"<<endl; myFile2<<"Kitap3:Tema= ,Sayfa sayisi=112,Fiyat=8 Tl,Adý=Dokuzuncu Hariciye Koðusu(Peyami Safa)"<<endl; myFile2<<"Kitap4:Tema= ,Sayfa sayisi=112,Fiyat=5 TL,Adý=Vatan Yahut Silistre(Namik Kemal)"<<endl; myFile2<<"Kitap5:Tema= ,Sayfa sayisi=300,Fiyat=10 TL,Adý=Eylül(Mehmet Rauf)"<<endl; myFile2<<"Kitap6:Tema= ,Sayfa sayisi=195,Fiyat=12 Tl,Adý=Kýrmýzý Sacli Kadin(Orhan Pamuk)"<<endl; } }; class Dunyaklasikleri:public BookShop{ public: Dunyaklasikleri() { cout<<"Aradiginiz kitap temasi nedir?"; cout<<"\n1:Korku\n2:Aşk\n3:Sevgi\n4:Dram\n5:Kahramanlık\n"; cin>>usertema; cout<<"Sayfa sayisi?:"; cout<<"\n1:[0-50]\n2:[50-100]\n3:[100-200]\n4:[200-300]\n5:[400-500]\n6:[500+]"; cin>>usersayfaaraligi; cout<<"Fiyat araligi?:"; cout<<"\n1:[0-10]TL\n2:[10-20]TL\n3:[20-50]TL\n4:[50-75]TL\n5:[75-100]TL\n6:[100+]TL"; cin>>userfiyat; } void fonksiyon3(){ ofstream myFile3 ("Dunyaklasikleri.txt"); myFile3<<"Kitap1:Tema= ,Sayfa sayisi=592,Fiyat= TL,Adý=Suç ve Ceza(Dostoyevski)"<<endl; myFile3<<"Kitap2:Tema= ,Sayfa sayisi=393,Fiyat= TL,Adý=Savaþ ve Barýþ(Tolstoy)"<<endl; myFile3<<"Kitap3:Tema= ,Sayfa sayisi=464,Fiyat= Tl,Adý=Ýki þehrin hikayesi(Charles Dickens)"<<endl; myFile3<<"Kitap4:Tema= ,Sayfa sayisi=184,Fiyat= TL,Adý=Ýnsancýklar(Dostoyevski)"<<endl; myFile3<<"Kitap5:Tema= ,Sayfa sayisi=128,Fiyat= TL,Adý=Fareler ve Ýnsanlar(John Steinbeck)"<<endl; myFile3<<"Kitap6:Tema= ,Sayfa sayisi=240,Fiyat= Tl,Adý=Romeo ve Juliet(William Shakespeare)"<<endl; } }; int main() { BookShop b1; b1.Karsilama(); if(b1.tur==1) { ModernKlasik m1; m1.fonksiyon1(); } if(b1.tur==2) { Turkedebiyati t1; t1.fonksiyon2(); } if(b1.tur==3) { Dunyaklasikleri d1; d1.fonksiyon3(); } return 0; } |
How check if previous element having active class on click event Posted: 11 May 2021 09:06 AM PDT Considering the below case - I try to check on click event of <button> if there was any active class present on its parent <li> item. e.g If the user clicks on button 5, will search and check if the previous <li> has an active class or not, in that case, it will return TRUE. Same if the user clicks on button 2, will search on the all previous <li> and if not having 'active' class then it will return FALSE. <ul class="list-item"> <li><button>1</button></li> <li><button>2</button></li> <li class="active"><button>3</button></li> <li><button>4</button></li> <li><button>5</button></li> <li><button>6</button></li> <li><button>7</button></li> </ul> const listItem = document.querySelector('.list-item'); if(listItem){ const alldots = document.querySelectorAll('button'); alldots.forEach((button) => { button.addEventListener('click', (event) => { // How to check here // If there was 'active' class on previous 'li' items on 'click'? // }, false); }); } |
How to combine multiple vectors such that elements of each vector are distributed as equally as possible? Posted: 11 May 2021 09:06 AM PDT Let's say I have two or more vectors with to or more elements (single factor) each, e.g. v1 = c("a", "a", "a") v2 = c("b", "b") What I want to do is to merge all vectors and distribute the elements for each group as equally as possible. For the simple example above there would be a single solution: c("a", "b", "a", "b", "a") If v1 = c("a", "a", "a", "a") any of these c("a", "b", "a", "b", "a", "a") c("a", "b", "a", "a", "b", "a") c("a", "a", "b", "a", "b", "a") would be the best solution. Is there a built-in function that can do this? Any ideas how to implement it? |
Understanding a table bloat query Posted: 11 May 2021 09:05 AM PDT When researching table bloat there is this query that crops up in quite a few places. From what i can see its basically been copy pasted since 2008 I'm struggling to decipher this query so as not to blindly rely on it. What is so special about the 27 or 23 here and the difference between a windows and non-windows install to offer the values 4 or 8 ? CASE WHEN SUBSTRING(v,12,3) IN ('8.0','8.1','8.2') THEN 27 ELSE 23 END AS hdr, CASE WHEN v ~ 'mingw32' THEN 8 ELSE 4 END AS ma Can anyone offer any insights into this query ? Would using pgstattuple be a more sensible approach to calculating table bloat ? Thanks. SELECT tablename AS relname, schemaname, (ROUND((CASE WHEN otta=0 THEN 0.0 ELSE sml.relpages::FLOAT/otta END)::NUMERIC,1))::BIGINT AS tbloat, (CASE WHEN relpages < otta THEN 0 ELSE bs*(sml.relpages-otta)::BIGINT END)::BIGINT AS wastedbytes FROM ( SELECT schemaname, tablename, cc.reltuples, cc.relpages, bs, CEIL((cc.reltuples*((datahdr+ma- (CASE WHEN datahdr%ma=0 THEN ma ELSE datahdr%ma END))+nullhdr2+4))/(bs-20::FLOAT)) AS otta FROM ( SELECT ma,bs,schemaname,tablename, (datawidth+(hdr+ma-(CASE WHEN hdr%ma=0 THEN ma ELSE hdr%ma END)))::NUMERIC AS datahdr, (maxfracsum*(nullhdr+ma-(CASE WHEN nullhdr%ma=0 THEN ma ELSE nullhdr%ma END))) AS nullhdr2 FROM ( SELECT schemaname, tablename, hdr, ma, bs, SUM((1-null_frac)*avg_width) AS datawidth, MAX(null_frac) AS maxfracsum, hdr+( SELECT 1+COUNT(*)/8 FROM pg_stats s2 WHERE null_frac<>0 AND s2.schemaname = s.schemaname AND s2.tablename = s.tablename ) AS nullhdr FROM pg_stats s, ( SELECT (SELECT current_setting('block_size')::NUMERIC) AS bs, CASE WHEN SUBSTRING(v,12,3) IN ('8.0','8.1','8.2') THEN 27 ELSE 23 END AS hdr, CASE WHEN v ~ 'mingw32' THEN 8 ELSE 4 END AS ma FROM (SELECT version() AS v) AS foo ) AS constants GROUP BY 1,2,3,4,5 ) AS foo ) AS rs JOIN pg_class cc ON cc.relname = rs.tablename JOIN pg_namespace nn ON cc.relnamespace = nn.oid AND nn.nspname = rs.schemaname AND nn.nspname <> 'information_schema' ) AS sml WHERE schemaname != 'pg_catalog' order by 4 desc |
Display date/time remaining current time Posted: 11 May 2021 09:05 AM PDT I am trying to create a function to send me back a String which represent a restaurant opening status like: "Open", "Closed", "22min" I have the closing time displayed as: 2021-05-11T06:45:00Z I would like to make a comparison based on current time, but it's not working. I have done the code below: fun getCloseTime(ctx: Context): String? { val timeFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern("hh:mm a", Locale.ENGLISH) val diff: Duration = Duration.between( LocalTime.parse(next_close_time, timeFormatter), LocalTime.parse(getISO8601StringForDate(), timeFormatter)) return when { (diff.toDays().toInt() > 0 ) || (diff.toHours() > 0) -> "Open" (diff.toMinutes().toInt() <= 60) -> diff.toMinutes().toString() else -> ctx.getString(R.string.closed) } } private fun getISO8601StringForDate(): String? { val now = Date() val dateFormat: DateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US) dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")) return dateFormat.format(now) } My goal is to: - return "Closed" when current is after the
next_close_time - when the diff between
next_close_time and current is more than an hour, we display "Open" -
- when the diff between
next_close_time and current is less than an hour, we display the remain time in minute before closure Any idea? |
12 Months rolling for order amount, customer count and order count Posted: 11 May 2021 09:05 AM PDT I have 3 fields customer id, order id and order total from transactions table. Now I want to calculate 12 monthing for order amount, distinct customer count and distinct orderid count. I tried with below query : with Month AS ( select Order_date, count(distinct customerid) as distinctCustomerCount, sum(orderamount) as orderamount, count(distinct orderid) as distinctOrderCount from trans where Date(date) between Date_ADD('Day', -2, Date_ADD('Year', -2, current_date) ) and Date_ADD('Day', -2, Current_Date) group by 1 ) select a.* from ( select distinct Order_date, sum(orderamount) OVER( ORDER BY Order_date RANGE BETWEEN INTERVAL '12' MONTH PRECEDING AND CURRENT ROW) as Rolling12monthamount, sum(distinctCustomerCount) OVER( ORDER BY Order_date RANGE BETWEEN INTERVAL '12' MONTH PRECEDING AND CURRENT ROW) as Rolling12monthCustomerCount, sum(distinctOrderCount) OVER( ORDER BY Order_date RANGE BETWEEN INTERVAL '12' MONTH PRECEDING AND CURRENT ROW) as Rolling12monthOrderCount from CTEMonth )a where Date(Order_date) >= Date_ADD('Day', -2, Date_ADD('Year', -1, current_date) ) order by Order_date I got the results but when I compare order and customer count that is not matching with the expected count. Here I'm calculating day wise customer counts. But I need customercount and order count for whole year. For example: if I'm calculating orderamount, customercount, ordercount for april10 12 month rolling then the order date period should be 04-09-2019 to 04-09-2020 and similarly for other days aswell. Can any one please help me with the query? I was able to implement it in T-SQL. but not able to do in PostgreSql or Presto SQL. |
Motion Editor Preview not Loading Posted: 11 May 2021 09:06 AM PDT I am working on app using MotionLayout feature but the MotionLayout Editor is acting up and is not showing the preview when I click the Design tab. I am getting is a blank preview with a Rendering error which I have been trying to solve to no avail. This is what I have. This is the error I am getting java.lang.reflect.InvocationTargetException at jdk.internal.reflect.GeneratedMethodAccessor586.invoke(Unknown Source) atjava.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at android.view.BridgeInflater.lambda$createViewFromCustomInflater$0(BridgeInflater.java:259) at android.view.BridgeInflater.createViewFromCustomInflater(BridgeInflater.java:285) at android.view.BridgeInflater.onCreateView(BridgeInflater.java:122) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:928) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:948) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1002) at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:309) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1121) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72) at android.view.LayoutInflater.rInflate(LayoutInflater.java:1095) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082) at android.view.LayoutInflater.inflate(LayoutInflater.java:680) at android.view.LayoutInflater.inflate(LayoutInflater.java:499) at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:325) at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:369) at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:141) at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:710) at com.android.tools.idea.rendering.RenderTask.lambda$inflate$6(RenderTask.java:865) at com.android.tools.idea.rendering.RenderExecutor$runAsyncActionWithTimeout$2.run(RenderExecutor.kt:174) 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) Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1 at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:47) at java.base/java.lang.String.charAt(String.java:693) at android.content.res.BridgeTypedArray.getType(BridgeTypedArray.java:1024) at android.content.res.BridgeTypedArray.getType(BridgeTypedArray.java:809) at android.content.res.BridgeTypedArray.getValue(BridgeTypedArray.java:778) at android.content.res.BridgeTypedArray.peekValue(BridgeTypedArray.java:847) at android.view.View.<init>(View.java:5951) at android.view.ViewGroup.<init>(ViewGroup.java:697) at android.widget.AdapterView.<init>(AdapterView.java:260) at android.widget.AbsSpinner.<init>(AbsSpinner.java:74) at android.widget.Spinner.<init>(Spinner.java:246) at android.widget.Spinner.<init>(Spinner.java:213) at android.widget.Spinner.<init>(Spinner.java:163) at androidx.appcompat.widget.AppCompatSpinner.<init>(AppCompatSpinner.java:209) at androidx.appcompat.widget.AppCompatSpinner.<init>(AppCompatSpinner.java:180) at androidx.appcompat.widget.AppCompatSpinner.<init>(AppCompatSpinner.java:160) at androidx.appcompat.widget.AppCompatSpinner.<init>(AppCompatSpinner.java:144) at androidx.appcompat.app.AppCompatViewInflater.createSpinner(AppCompatViewInflater.java:214) at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:131) ... 26 more I am on Android 4.2 and I am using this dependency for the Constraint Layou. implementation "androidx.constraintlayout:constraintlayout:2.1.0-beta02" The classpath is classpath "com.android.tools.build:gradle:4.2.0 This is my gradle version distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip I have tried restarting, invalidating cache, cleaning, rebuilding, delete lib fold in .idea and also deleting app/build file but still cannot get the preview and the Rendering Error Persists. This is my link to the project and will appreciate any help to resolve this. |
get transform component via string to track player Posted: 11 May 2021 09:05 AM PDT im trying to grab the transform component via t.find and then via the transform component, grab the game object component, and then t.LookAt can work, and look at the player. this is the code: using System.Collections; using System.Collections.Generic; using UnityEngine; public class gunner : MonoBehaviour { //legacy statements: isShot //these statements initialize all the main variables used in the project. most of these are for the "ai". #region variables [Header("gun stats")] [Space(10)] public float damage = 10f; public float range = 100f; [Space(10)] [Header("Camera")] [Space(10)] public Camera cam; [Space(10)] [Header("AI Variables")] [Space(10)] public float shootlength; public bool aiactive; public float Speed; public target self; public Transform t; public Rigidbody rb; public string playername = "Player"; public GameObject PlayerObject; public Transform PlayerTrans; [Header("Decor")] public ParticleSystem ps; AudioSource audioData;
|
No comments:
Post a Comment