Altering unique fields of inherited Django model

Uncategorized
Question: In Django, I'm trying to create a base model that can be used to track the different version of some other model's data in a transparent way. Something like:class Warehouse(models.Model): version_number = models.IntegerField() objects = CustomModelManagerFilteringOnVersionNumber() class Meta_abstract=True def save(self, *args, **kwargs):# handling here version number incrementation # never overwrite data but create separate records, # don't delete but mark as deleted, etc. pass class SomeData(Warehouse):name = models.CharField(unique=True) The problem I have is that SomeData.name is actually not unique, the tuple ('version_number', 'name' ) is. I know I can use the Meta class in SomeData with unique_together but I was wondering whether this could be done in a more transparent way. That is, dynamically modifying/creating this unique_together field. Final note: maybe handling this with model inheritance is not the…
Read More

How to write a T-Sql query that would output 1 if the value in a column in Table A matches the value in a column in Table B, 0 otherwise?

Uncategorized
Question: I am using SQL Server 2012 and I need to write a query that would do give me the following output:Code Value FRBAR 0 ENSPA 1 DEWINE 1 ... To achieve the above, I am working with 2 specific tables in my database, namely Table A and Table B. Table A has a column called CodeA and Table B has a column called CodeB. I want to write a T-sql query that would match all the values in column CodeA with those in column CodeB and ouput the result I mentioned above. I know I need to do a JOIN on these 2 columns but I am confused about how to implement the logic of returning a 1 if there is a match and a 0 otherwise. Answer: You…
Read More

I have a amazon EC2 instance and have made a shiny application in the instance. I need to link a domain to the instance ip

Uncategorized
Question: I have a small query and it would be helpful if you can help me in solving it. I have a amazon EC2 instance and have made a shiny application in the instance. I need to link a domain to the instance ip. I did it using DNS. But the problem is that in the ip the port of the server needs to be entered as 3838 for shiny app to be used. Generally in the Route s3 , we have option to add the instance IVP4 but we do not have option to add the port. Now how do we add the port address in the DNS??? This is my shiny app hosted in server http://35.154.127.239:3838/ I need to link this to www.renderui.com (My own domain). Thank you.…
Read More

How can I get user input on Windows without echo in a Python script?

python
Question: I'm using python 2.7.9 on Windows 7. I need to obtain a password from a user in order to connect to a resource. It seems that userpass = getpass.getpass("Password :") is the de facto standard for this in Python, however in Windows 7, the inputted text is just happily echoed to the output screen. How can I mask the user input in the console or whatever when running my Python script? Thank you Answer: Read more
Read More

CSS move and translate property not working simultaneously using keyframes

Uncategorized
Question: .animation{ animation: rotate 5s ease-in 0s; } @keyframes rotate{ 0%{transform:rotate(0deg) translate(0px,0px); } 100%{ transform:rotate(2520deg) translate(100px,100px); } How to animate move and rotate simultaneously using css property and keyframes while the transform origin also changes along with movement? If it is possible please someone do any reply. Answer: See below. I let the end position in place using forwards div { width: 100px; height: 100px; background: blue; animation: move 3s ease forwards, rotate 3s ease; position: absolute; } @keyframes rotate { from { transform: rotate(0deg); } to { transform: rotate(2520deg); } } @keyframes move { from { top: 0; left: 0; } to { top: 100px; left: 100px; } } Read more
Read More

How to create json format java

Uncategorized
Question: I would like to create JSON format and I have some problem about this I have no idea to create Jsonarray and JsonObject in JsonObject { "users": [7, 16, 35], "group_id": "sdkfjsdkljflds" } I try JSONObject jsonParams = new JSONObject(); try { jsonParams.put("group_id", "dlfsdds"); jsonParams.put("users", list); } catch (JSONException e) { e.printStackTrace(); } and my log is show { "users":"[7, 16, 35]", "group_id":"dlfsdds" } ps. list is from for (int k=0;k
Read More

Can systemd take over a daemon service which run by manual? [on hold]

linux
Question: I have a question like this and I don't know how to answer it. OS:linux A daemon service which start by manual can be monitor by Upstart or systemd ? For example, I start nginx use the command ‘nginx -c xxx.conf’ in terminal, when nginx service down, I want Upstart or systemd can restart it, how can i do this? You may be want to say, nginx can be start by Upstart or systemd ,why do you start it by manual?Because I want hot update a service like nginx. Can someone give me a hint? Thanks advance! Answer: Read more
Read More

How to change index.html in every folder to / when we access it on browser

Uncategorized
Question: I've some unique problem, but I think this is not problem, I just want to optimize the url that my website have. so I want to change all index.html on every folder as example culture folder, so normally if we want access index.html in culture folder we can just type culture/index.html right? but i want to access by just type culture/ Is it possible to do that? If so, how we produce? I'm using jsf 2 as programming language. Answer: Maybe I misunderstand your problem, but this can be done by configuring welcome files in the web.xml file: Web Application developers can define an ordered list of partial URIs called welcome files in the Web application deployment descriptor. The purpose of this mechanism is to allow the deployer to…
Read More

SEO: Reupload images with translated filenames?

Uncategorized
Question: From a SEO/ranking point of view would it make sense to reupload images on a multilanguage website with a translated filename to get traffic from google-search? E.g (house.jpg for english and casa.jpg for spanish) There seem to be different opionions about duplicate content of having the same picture with same filesize etc. under multiple names vs. the possibility of google indexing it. Also most our pictures are from stock-photos like from gettyimages and I've also been reading those ones are harder to "rank" with as they already exist many times in google search. Please share your experiences/practice on the matter. Answer: Read more
Read More

php parse xml use exactly attribute

Uncategorized
Question: Input XML:$url = ' john_1.jpg john_2.jpg john_3.jpg jo_1.jpg jo_2.jpg david_1.jpg '; $xml = simplexml_load_string($url) or die("Error: Cannot create object"); $imgstring =''; foreach ($xml->emp_detail->emp as $node ) { if (strpos((string) $node->attributes()->emp_name, "jo") !== false) { $imgstring .= (string) $node->img . ""; } } echo ($imgstring); Current result:john_1.jpg john_2.jpg john_3.jpg jo_1.jpg jo_2.jpg But i want get only img with attribute is "jo" like, Expected:jo_1.jpg jo_2.jpg How to do it? Answer: You are doing one thing wrong here strpos is to check position of substring and jo is also a substring of john that's why you are getting all the values Instead you can simple use == for comparison. Try this code snippet here Change this to:if (strpos((string) $node->attributes()->emp_name, "jo") !== false) { This:if ($node->attributes()->emp_name== "jo") { Read more
Read More

Letting a single Java annotation implicitly set multiple annotations

Uncategorized
Question: I have written a Java library that defines and uses a custom annotation to find methods that are then called via reflection. See this example @YauaaField("DeviceClass") public void setDeviceClass(TestRecord record, String value) { record.deviceClass = value; } So IDEs like IntelliJ and probably other code analysis tools will report most of the functions annotated this way as "Unused". What I would like is an automated way to say that anything that has been annotated with @YauaaField is automatically also annotated with @SuppressWarnings("unused"). I've done quite a bit of googling, read through several online manuals, tutorials and java documentation. Yet I have not yet been able to find how to do that. The annotations do not seem to support 'inheritance' of any kind. So is what I want even possible?…
Read More

Scrapy: Stop crawling a domain and hop to the next if a condition is met

Uncategorized
Question: I'd like to write a BFO Broad Crawler which does the following:- Begin with first URL - Try to find Links to Impressum RegEx: '.*mpressum.*' (Translation: Imprint) - Check if some condition is met. In my case if the postal Code is in a certain range - If the condition is met continue crawling the page - If the condition is not met stop crawling the domain an blacklist it from future crawls. - Continue with next Domain Basically I want the Answer to the following Question: What domains in Germany are in a certain postal code range? My Code is a mess, as I am learning Scrapy at the moment. Thanks! Answer: You can use the allowed_domains variables in your scraper. When a condition is met you just…
Read More

How to split strings inside a numpy array?

Uncategorized
Question: I have the following table: As the column 'location' has the state repeating inside it, I am trying to remove the state from location so that it only has the city name. year location state success 2009 New York, NY NY 1 2009 New York, NY NY 1 2009 Chicago, IL IL 1 2009 New York, NY NY 1 2009 Boston, MA MA 1 2009 Long Beach, CA CA 1 2009 Atlanta, GA GA 1 I have tried the following code:x = KS_clean.column(1) np.chararray.split(x, ',') How can I split the string so the result only contains the city name like the following:array('New York', 'New York', 'Chicago', ...,) so that I can put it back inside the table? Sorry it is basic question but I am new to python and…
Read More