Posts

Showing posts from September 17, 2018

Python: Generate random values from empirical distribution

Image
Clash Royale CLAN TAG #URR8PPP Python: Generate random values from empirical distribution In Java, I usually rely on the org.apache.commons.math3.random.EmpiricalDistribution class to do the following: Is there any Python library that provides the same functionality? It seems like scipy.stats.gaussian_kde.resample does something similar, but I'm not sure if it implements the same procedure as the Java type I'm familiar with. I think the accepted answer here has what you're looking for. – Kevin Feb 16 '16 at 14:42 @Kevin: the linked answer doesn't work for this case, because it assumes you already know the analytical form of your distribution, whereas this question is looking for something non-parametric. – abeboparebop Aug 7 at 13:46 1 Answer 1 import numpy as np import scipy import matplotlib.pyplot as plt # This represents the original "empirical" sample -- I fake it by # sampling from a normal distribution orig_sample_data = np.rand

Show that if $(z+1)^100 = (z-1)^100$, then $z$ is purely imaginary

Image
Clash Royale CLAN TAG #URR8PPP Show that if $(z+1)^100 = (z-1)^100$, then $z$ is purely imaginary Let $z$ be a complex number satisfying $$(z+1)^100 = (z-1)^100$$ Show that $z$ is purely imaginary, i.e. that $Re(z) = 0$. Rearrange to $$left(fracz+1z-1right)^100 = 1$$ I tried using $z = x+iy$ and trying to multiply numerator and denominator by the conjugate, but I hit a roadblock. I also tried substituting $1 = -e^ipi$, but that also doesn't seem to get me anywhere. How can I prove this? Any help is appreciated, thank you! 3 Answers 3 Hint $$|z+1|^2=|z-1|^2 \ left(z+1right) overlineleft(z+1right)=left(z-1right) overlineleft(z-1right) \ z barz+z+barz+1=zbarz-z-barz+1 \ barz=-z $$ Umm does $overline z$ stand for the complex conjungate of $z$? – Mohammad Zuhair Khan 7 hours ago @MohammadZuhairKhan Yes. – N. S. 7 hours ago Take absolute values, $|z+1|^100=|z-1|^100|$. Absolute values are always no negative real numbers, for which root extractions are always de

Wordpress - Commit / Push on gitlab after edit File

Image
Clash Royale CLAN TAG #URR8PPP Wordpress - Commit / Push on gitlab after edit File I search for a Solution. I have many wordpress Projects and now i search for a Plugin: After edit a File with the WP - Editor, now i commit/push the file on my gitlab project. thanks for help 1 Answer 1 Hello try this https://it.wordpress.org/plugins/wp-gitlab/ at official sites of Wordpress, I use it for a long time and I feel great thanks for help, but Last updated: 3 years ago ! After Install, in the Backend many Error – Sebastian Schmal Aug 8 at 11:48 By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

download an html page using wget with only partial link

Image
Clash Royale CLAN TAG #URR8PPP download an html page using wget with only partial link I am writing a bash script to download current natgeo photo of the day html web page using wget, it changes everyday. When I go to link https://www.nationalgeographic.com/photography/photo-of-the-day/ it redirects me to current page that is https://www.nationalgeographic.com/photography/photo-of-the-day/2018/08/mandalay-golden-sunrise/ that part after photo of the day changes everyday in website. I want wget to download the 2nd html link (which changes everyday) using only the 1st link( which when typed in browser redirects me to the 2nd link). How can I do it? till now I have tried: wget https://www.nationalgeographic.com/photography/photo-of-the-day/ but it does not give me the desired 2nd link html page. I review the first url, and i think you can get the code and parse the first page, then get the "twitter:image:src" meta value, and you have in this way the url of the desired ima

Diff in PhpStorm

Image
Clash Royale CLAN TAG #URR8PPP Diff in PhpStorm How can I compare a document in current project with one that is not a part of project? How can I compare two arbitrary files in my computer with phpStorm? You could copy the content from the external file into clipboard and right click on/in your project file and then click Compare with clipboard . – Dan Lee Sep 11 '12 at 10:41 Compare with clipboard @Dan Lee Yes, as you mentioned currently easiest way that I found for comparing a project file with a non-project file is copy external file to clipboard and select "View->Compare with clipboard". – PHPst Sep 11 '12 at 10:55 4 Answers 4 Currently, the easiest way that I found for comparing a project file with a non-project file is coping the external file to clipboard and clicking on "View->Compare with clipboard". For me this feature is broken in version phpstorm 10. Someone experiencing the same? – velop Nov 9 '15 at 14:47

Builing DLL and getting error PRJ0019 and warnings LNK4222

Image
Clash Royale CLAN TAG #URR8PPP Builing DLL and getting error PRJ0019 and warnings LNK4222 In my DLL defs file I had: EXPORTS DllCanUnloadNow @1 PRIVATE DllGetClassObject @2 PRIVATE DllRegisterServer @3 PRIVATE DllUnregisterServer @4 PRIVATE If I build it, I get 4 warnings LNK4222, exported symbol 'DllCanUnloadNow' should not be assigned an ordinal, I get this for each entry. So I commented out each link with ; Now when I build I get: error PRJ0019: A tool returned an error code from "Performing registration" What is the correct way to resolve both issues? Just remove @1 , @2 ... as shown here: msdn.microsoft.com/en-us/library/8e705t74.aspx – Alex F Aug 8 at 10:36 @1 @2 Thank you, although the actual fix was just to remove the @# leaving in the PRIVATE as without it another warning is produced. – SPlatten Aug 8 at 10:39 1 Answer 1 Thank you to Alex P, the actual fix was to replace with: EXPORTS DllCanUnloadNow PRIVATE DllGetClassObject P

VCS settings for Clear Case UCM Plugin for Jenkins [on hold]

Image
Clash Royale CLAN TAG #URR8PPP VCS settings for Clear Case UCM Plugin for Jenkins [on hold] I am using Jenkins and its ClearCase UCM plugin, but am unable to make it work (make ClearCase checkout the proper view in the Jenkins job workspace). I have been trying to set up source code to ClearCase, but it is asking too many inputs and I am not aware what to fill. It is asking for the following fields: Viewtag : Jenkins_$USER_NAME_$NODE_NAME_$JOB_NAME$DASH_WORKSPACE_NUMBER View Path: Stream Selector. Can anybody help with this? What should be the correct values for ClearCase to work properly, that is get the code in the Jenkins job workspace? This question appears to be off-topic. The users who voted to close gave this specific reason: Note to moderator: this is not off topic. This is not a request for a tool recommendation. – VonC 18 hours ago Exactly. How can this be off topic. – raj vardhan 16 hours ago The title is "Clear Case UCM Plugin for Jenkins",

Excel VlookUp left cell into VBA from another workbook

Image
Clash Royale CLAN TAG #URR8PPP Excel VlookUp left cell into VBA from another workbook Hi everybody, my VLookUp function is working so far, now I would like to convert it into a VBA function. My VLookUp: =VLOOKUP(A6;'[test.xls]Sheet1'!$A:$B;2;0) 'example for Cell A6, which can vary Now I would like to get this into a VBA function which can be called. So if the function is called "A6" sould be "overwriten" by the left cell of where the function has been called. I have tried following code: Sub lookup() Dim x1 As String x1 = ActiveCell.Offset(0, -1).Select VLOOKUP(x1,'[test.xls]Sheet1'!$A:$B;2;0) End Sub What is necessary that it's working as expected? I'm grateful for any tips. Sorry, mabye it wasn't clear. "test.xls" is another workbook. The code should run inside the file called (e.g.) "missing.xls". The range you want to do VLookUp on, is it in the same workbook or a different workbook? from your

Python conversion from binary string to hexadecimal

Image
Clash Royale CLAN TAG #URR8PPP Python conversion from binary string to hexadecimal How can I perform a conversion of a binary string to the corresponding hex value in Python? I have 0000 0100 1000 1101 and I want to get 048D I'm using Python 2.6. 0000 0100 1000 1101 048D 11 Answers 11 int given base 2 and then hex : int hex >>> int('010110', 2) 22 >>> hex(int('010110', 2)) '0x16' >>> >>> hex(int('0000010010001101', 2)) '0x48d' The doc of int : int int(x[, base]) -> integer Convert a string or number to an integer, if possible. A floating point argument will be truncated towards zero (this does not include a string representation of a floating point number!) When converting a string, use the optional base. It is an error to supply a base when converting a non-string. If base is zero, the proper base is guessed based on the string content. If the argument is outside the integer range a

Metamask injects web3 after page refresh only

Image
Clash Royale CLAN TAG #URR8PPP Metamask injects web3 after page refresh only In my react application I am checking for web3 like below, but i need to refresh the page at least once after installing metamask on chrome. detectAndReadMetaMaskAccount() { return new Promise((resolve, reject) => web3.currentProvider.isMetaMask !== true) reject( code: "error.metamask.missing" ); Below are the steps I am doing: 1. loading my page. 2. Installing metamask on chrome. 3. Clicking on a submit button which invokes above function but web3 is undefined. 4. But after page refresh getting web3. So my query is, when and how exactly metamask injects web3? Is there any way where metamask will inject web3 without page refresh? 1 Answer 1 Unfortunately I couldn't find any way to force web3 to update after installing MetaMask without a page reload. As a hack workaround I'm forcing a page reload on window focus change: window.onfocus = () => window.location.reload(); Th

Browser like object for Swift

Image
Clash Royale CLAN TAG #URR8PPP Browser like object for Swift I am creating an app for a website. I want to run a browser or a browser like object in the background and fetch data from the website. This website requires login!!! In Python there are libraries like mechanize and selenium which I can fill forms, get html, and find links very easily. However, I did not find any libraries or classes in swift that can do this. I have tried URLSession, but it cannot fill forms to login and get html dynamically. I also tried WKWebView and SafariServices. None of them seems to fulfill my goals. Are there any browser-like classes like mechanize and selenium in Swift? And I am not sure whether URLSession, WKWebView, and SafariServices can fill forms and login a website. Can anyone point me out. Also is using python in this case suitable? Thank you! 1 Answer 1 Use the WebKit , and have your UIViewController conform to WKNavigationDelegate . WebKit UIViewController WKNavigationDelegate Use

Pandas making a new list from groupby object

Image
Clash Royale CLAN TAG #URR8PPP Pandas making a new list from groupby object My data has a country column and 'Clicked on Ad' column which has boolean value for customers preference for ad. I want to groupby my list to see the number of clicks based on countries. Then I want to cut (4,8) clicks which represent highest clicks per country. I want to cut these rows and create a new list while keeping all features of rows ad_country=ad_data.groupby('Country') Country_sum= for i in range(4,8): if ad_country['Clicked on Ad']==i: Country_sum.append(iloc[ad_country]) Please show a sample of your data and the output expected. – coldspeed 19 secs ago By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

MongoDB sorting by date as type String

Image
Clash Royale CLAN TAG #URR8PPP MongoDB sorting by date as type String Can someone help me with the query for sorting an array by date in ascending order? I have tried the below query but the sorting is not happening as expected, db.getCollection(xyz).aggregate([ $match: "_id":$in:["a" : "NA","b" : "HXYZ","c" : "12345","d" : "AA"] , $sort: 'bal.date': 1 , $project: balances: $slice: ["$bal",2] ]) My collection: /* 1 */ "_id" : "a" : "NA", "b" : "HXYZ", "c" : "12345", "d" : "AA" , "bal" : [ "type" : "E", "date" : "2015-08-02" , "type" : "E", "date" : "2015-08-01" , "type" : "E", "date" : "2015-07-07" ] Please help me what is the p

Get week number in month from date in PHP?

Image
Clash Royale CLAN TAG #URR8PPP Get week number in month from date in PHP? I have an array of random dates (not coming from MySQL). I need to group them by the week as Week1, Week2, and so on upto Week5. What I have is this: $dates = array('2015-09-01','2015-09-05','2015-09-06','2015-09-15','2015-09-17'); What I need is a function to get the week number of the month by providing the date. I know that I can get the weeknumber by doing date('W',strtotime('2015-09-01')); but this week number is the number between year (1-52) but I need the week number of the month only, e.g. in Sep 2015 there are 5 weeks: date('W',strtotime('2015-09-01')); I should be able to get the week Week1 by just providing the date e.g. $weekNumber = getWeekNumber('2015-09-01') //output 1; $weekNumber = getWeekNumber('2015-09-17') //output 3; Please clarify your question. – William Smith Sep 16 '15 at 18:19 9

Unruly disk usage, and will not shrink

Image
Clash Royale CLAN TAG #URR8PPP Unruly disk usage, and will not shrink I have about 10 databases in CouchDB, the largest of which is showing about 1MB in Fauxton. Which sounds right, as there are no binaries in it, all just text. And yet, my Couch data files are 20 Gigabytes! I have run _compact on each database, which saved me about 5GB (was 25GB!), but that still doesn't explain why they're taking up so much space still. What can I do to fix this? EDIT: adding more info following the helpful comments so far (thank you!): Replication to a new server seems to fix the problem (everything is just a few meg again), for a few days. Then inexplicably the data chomp starts up again. Earlier, I watched it being used heavily, but not taking up any extra space. And then all of a sudden it's off again! The database sizes in Fauxton remain tiny, it's only the data files / shards that take up the space The documents are mainly things like text messages (received via an API

Spring JDBCTemplate issue

Image
Clash Royale CLAN TAG #URR8PPP Spring JDBCTemplate issue i have a method to update multiple rows in my oracle database using jdbc template. before updating the application has some processings to do, if these processings are successfully completed it goes on for the update. HashMap<String, Object> mapUpdate = new HashMap<String, Object>(); mapUpdate.put("ID_REF_STATUT", IConstants.Status.GEN); mapUpdate.put("DATE_REGLEMENT", new Date()); managerTransactionDao.updateListValeur(listValeurs, mapUpdate); HashMap<String, Object> mapUpdateBord = new HashMap<String, Object>(); mapUpdateBord.put("ID_STATUS", IConstants.Status.GEN); mapUpdateBord.put("DATE_GENERATION_DATA", new Date()); mapUpdateBord.put("NOM_FICHIER_DATA", file.getName()); managerTransactionDao.updateBordereau(vbordereau, mapUpdateBord); below is the update method : public int updateListValeur(List<VValeur> listValeurs, Map<String, Ob