2018-10-22         Jerry

Python urllib2 Response header

I'm trying to extract the response header of a URL request. When I use firebug to analyze the response output of a URL request, it returns:Content-Type text/htmlHowever when I use the python code:urllib2.urlopen(URL).info()the resulting output returns:Content-Type: video/x-flvI am new to python, and to web programming in general; any helpful insight is much appreciated. Also, if more info is needed please let me know.Thanks in advance for reading this post Try to request as Firefox does. You can see the request headers in Firebug, so add them to your request object:impor...

 python                     6 answers                     3 view
 2018-10-22         Jerry

HTML5shiv vs Dean Edwards IE7-js vs Modernizr - which to choose?

I'm looking to build my first HTML5 site and have been looking at working with IE.There is html5shiv, Dean Edwards ie7-js and then Modernizr. Are these all largely the same? I'm confused about which route to go. No, they're not the same at all; they do completely different things.html5shiv allows you to use the new HTML5 tags in versions of IE that don't understand them. Without it, IE will choke on these tags, so you need this if you intend to use the tags. Don't expect it to make the tags actually do anything in IE though! It just stop the browser complaining about th...

 html5                     3 answers                     70 view
 2018-10-22         Jerry

How do I collect all the topics that are owned by the members of the groups I am a member of?

This may be tough for me to explain, so if it's not clear just let me know so I can edit as needed!I have the following example:class User < ActiveRecord::Base has_many :topics has_many :membershipsendclass Topic < ActiveRecord::Base belongs_to :userend#join model between User and Groupclass Membership < ActiveRecord::Base belongs_to :user belongs_to :groupendclass Group < ActiveRecord::Base has_many :memberships has_many :members, :through => :memberships, :source => :user has_many :topics, :through => :membersendThe problem I'm having is that ...

 ruby-on-rails                     2 answers                     45 view
 2018-10-22         Jerry

dplyr:: append to postgresql remote source if uid not present

Unless I'm missing something there is no reference in documentation to how to use functions such as db_write_table in practice. The only reference in package documentation is.db_write_table(con, table, types, values, temporary = FALSE, ...)types is not explained. None of dplyr's remote connectivity functionality seems to be documented in much detail anywhere, e.g. dplyr.tidyverse.org.I have a database mydb with table mydata I can connect require(RPostgreSQL)require(dplyr)drv <- dbDriver("PostgreSQL")sapply(dbListConnections(drv), dbDisconnect)con <- dbConnect(drv, db...

 r                     2 answers                     12 view
 2018-10-22         Jerry

How do I limit auto completion results in JFXAutoCompletionPopup JavaFX

ArrayList<String> aniNames = new ArrayList<>();I made connection with Database and stored 7K anime names in above ArrayList. JFXAutoCompletePopup<String> autoCompPop = new JFXAutoCompletePopup<>(); for (int i=0; i<aniNames.size(); i++){ autoCompPop.getSuggestions().addAll(aniNames.get(i)); } autoCompPop.setSelectionHandler(event ->{ autoTF.setText(event.getObject()); }); autoTF.textProperty().addListener(observable -> { autoCompPop.filter(string -> string.toLowerCase().contains(autoTF.getText().toLowerCa...

 java                     1 answers                     51 view
 2018-10-22         Jerry

Using Subquery to annotate a Count

Please help me I've been stuck on this for way too long :( What I want to do:I have these two models:class Specialization(models.Model): name = models.CharField("name", max_length=64)class Doctor(models.Model): name = models.CharField("name", max_length=128) # ... specialization = models.ForeignKey(Specialization)I would like to annotate all specializations in a queryset with the number of doctors that have this specialization.My Solution so Far:I went through a loop and I made a simple: Doctor.objects.filter(specialization=spec).count() however this proved to ...

 python                     1 answers                     28 view
 2018-10-22         Jerry

Setting a ceiling on Django widthratio tag

The Django widthratio tag takes three arguments - the top and bottom of a ratio, and a constant value. If the ratio is greater than one, then the rendered result will be greater than the constant. For example, if your first two numbers are 6 and 3 and your constant is 100, then the rendered number would be 200, not 100.I'm wondering if there is a way to set a ceiling for a widthratio tag so that the rendered result would not be above the constant, preferably without a new tag or filter. What do you mean by first two numbers? Widthratio first two numbers are "this_value"...

 django                     1 answers                     100 view
 2018-10-22         Jerry

Sort Dict by Values in Python 3.6+

I was looking for a method to sort a dictionary in Python with its values, after a few attempts, is what it comes:a = {<populated dict...>}a = {v: k for k, v in a.items()}a = {v: k for k, v in sorted(a.items())}This code seems to work, but I think it's poor for performance, is there a better way? You do not need to do the double key/value swap, you can do this:a = {k: v for k, v in sorted(a.items(), key=lambda x: x[1])}(sorted DOCS)Test Code:data = dict(a=1, b=3, c=2)print(data)data_sorted = {k: v for k, v in sorted(data.items(), key=lambda x: x[1])}print(data_sort...

 python                     2 answers                     40 view
 2018-10-22         Jerry

how to run a RESTful webservice over service stack on an https (ssl) channel

I looked at the documentation and examples in the service stack library and googled around but couldn't find a way to create an ssl (https) web service.In particular in the example i run the console example (really cool) that extends the AppHostHttpListenerBase class. I would like to make it run with https. You must set up a Server Certificate for the Http Listener, here's a walk through example of how to do that:http://blogs.msdn.com/b/jpsanders/archive/2009/09/29/walkthrough-using-httplistener-as-an-ssl-simple-server.aspxWhilst here is an article for setting up SSL wit...

 c#                     1 answers                     73 view
 2018-10-22         Jerry

jQuery - select item just clicked

I would like to know which item in select list was last clickedI have select drop down like this<select id="selectId" multiple="multiple" onchange=""><option value=1>Value 1</option><option value=2>Value 2</option><option value=3>Value 3</option><option value=4>Value 4</option></select>I would like to know, which item from select was last clicked and if it is now selected or not. Which jQuery selector (http://docs.jquery.com/Selectors) should be used in this case? Try using the click event on the <option> ...

 javascript                     3 answers                     20 view
 2018-10-22         Jerry

Command Execution Exception: The INSERT statement conflicted with the FOREIGN KEY constraint

I have a table named student I want to assign a fee or update (if present), I am looping over them which worked fine until I deleted a student. So now whenever I run the stored procedure it shows error.Here is my code.ALTER PROC [dbo].[sp_AutoAssignFeeUpdate]( @FeeID int, @FeeAmount int, @Fine int, @DueDate date, @AppliedON date, @FeeMonth varchar(30))AS --- Variables Using in LoopsDECLARE @LoopCounter INT , @MaxStudentID INT, @StdID INT, @FID INT-- Setting Counter From the count of students in student table if they are 'Active'SELECT @LoopCounter = min(Ad...

 sql                     2 answers                     63 view
 2018-10-22         Jerry

Mass import txt files in a single SQL Server table, using filename as key column

I have a folder of txt files. The filenames are of the form [integer].txt (like 1.txt, 2.txt and so on).I have a table, let's say TableA (id int not null, contents varchar(max))I want a way to mass import the contents of those files into TableA, populating the id column from the filename. Each file will be a single record in the table. It's not a delimited file.I've looked into SSIS and flat-file source, but I could not find a way to select a folder instead of a single file (this answer claims it can be done, but I could not find out how).Bulk Insert is my next bet, but I'm...

 sql-server                     1 answers                     73 view
 2018-10-22         Jerry

What is the difference between hazelcast.operation.thread.count and hazelcast.operation.generic.thread.count in hazelcast?

We are trying to optimize the performance of hazelcast and we are running a 16 node(8 core VM) cluster such that we have total 4001 partitions in the cluster and we have configured 50 operation threads per node. We need improvement in performance i.e more throughput and smaller response time so we are thinking of configuring hazelcast.operation.generic.thread.count as well.1) What is the difference between hazelcast.operation.generic.thread.count and hazelcast.operation.thread.count? What kind of of operations does hazelcast.operation.generic.thread handle?2) The ratio betw...

 hazelcast                     1 answers                     78 view
 2018-10-22         Jerry

using RewriteCond, can i change how fast content is served to users in different parts of the world?

using RewriteCond or similar mechanism on apache, can i change how fast content is served to users in different parts of the world?because it seems like this: I am hosting a site on netfirms.com, which is based in Toronto, and hosting another site on dreamhost.com, which is based in California. Both sites are almost empty. So I just uploaded identical files to them, to test the speed of download.the site on netfirms, it took 3 minutes for a 38MB file to download. the site on dreamhost.com, it took 45 seconds. (I am also in California).I then asked some friends to test ...

 apache                     1 answers                     74 view
 2018-10-22         Jerry

How do I use clipboard in GTK?

How can I, using GtkClipboard, read and write to a clipboard? As an example, please show me how to get the current clipboard content and print it to console.I tried this to get and print what is currently in the clipboard, but it doesn't work:GtkClipboard *clip = gtk_clipboard_get(GDK_SELECTION_PRIMARY);gtk_clipboard_request_text(clip, (GtkClipboardTextReceivedFunc)print_clip, NULL);Everything compiles without any warnings, but print_clip() function is never reached. Maybe I should use another function, like gtk_clipboard_wait_for_text()? Please help me, what am I supposed ...

 c                     2 answers                     71 view
 2018-10-22         Jerry

Remove the outer list from dictionary values

I want to remove the outer list from dictionary values but I can only find the unpacking method not sure how to use this on dictionary values.My data look like thisDIC{'A': array([[ 1.90769404e-01, 1.26112014e-01, -2.17013955e-02]],'B': array([[ 2.80194253e-01, 1.19333006e-01, 3.63824964e-02]],'C': array([[ 1.40285566e-01, 4.76801395e-02, 5.49828596e-02]]}I want to remove the outer list to make them like this{'A': array([ 1.90769404e-01, 1.26112014e-01, -2.17013955e-02],'B': array([ 2.80194253e-01, 1.19333006e-01, 3.63824964e-02],'C': array([ 1.40285566e-01, 4.7680...

 python                     2 answers                     12 view

Page 1 of 144  |  Show More Pages:  Top Prev Next Last