Stack Overflow

Subscribe to Stack Overflow feed
most recent 30 from stackoverflow.com 2018-02-21T10:21:19Z
Updated: 4 hours 17 min ago

how to number of rows affected by delete in sybase

4 hours 17 min ago

There is requirement that I want rows affected by delete operation in sybase any one if know please do let me know.

There is not sufficient documentation for sybase as I see.

Django: How to load file not in MEDIA_ROOT correctly | FileField?

4 hours 17 min ago

In my Django project I have application in which I want to load files NOT in MEDIA_ROOT. I used storage attribute to change the place but it raise error.

I used next code but it raise error when I try to load the file. How can I fix this problem?

settings.py:

MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media_root')

models.py:

from django.core.files.storage import FileSystemStorage from os import environ PRODUCT_STORAGE = FileSystemStorage(location=environ.get('PRODUCT_STORAGE_PATH')) def product_file_upload_path(instance, filename): if instance.category=="1": path = '/category_1/' + '/%s' % filename return path elif instance.category=="2": path = '/category_2/' + '%s' % filename return path else: path = '%s' % filename return path class Product(models.Model): file = models.FileField( max_length=255, blank=True, null=True, validators=[validate_file_extension], storage=PRODUCT_STORAGE, upload_to=product_file_upload_path, )

ERROR:

The joined path (/category_1/test.pdf) is located outside of the base path component (/other_folder)

TortoiseGit: Merge from remote

4 hours 17 min ago

When doing a merge from remote TortoiseGit doesn't check if version is up-to-date, so, every time I try to merge I have to fetch first and only then I can merge a remote in, otherwise it will (erroneously) say that remote is up-to-date.

Is there an easy way, that every time I attempt a merge from remote, TortoiseGit does a fetch first?

Access MongoDB Array of Embedded Documents with PHP 7

4 hours 17 min ago

Hi I'm trying to reach ebedded inside this array with PHP

"_id" : 0, "name" : "Sykes", "orders" : [ { "invoiceNumber" : 788, "cart" : [ { "item" : 0, "pkgId" : 3, "qty" : 10 } ] }, { "invoiceNumber" : 801, "cart" : [ { "item" : 1, "pkgId" : 1, "qty" : 8 } ] }

So I'm trying to achieve this in PHP

db.customer.find({_id:1},{'orders.invoiceNumber':1,_id:0}).pretty()

I managed to get through with json_decode and BSON, but I am not sure if that is the right way, there are better ways. Any help please?

Equivalent of console.log in C#

4 hours 17 min ago

I am running an MVC Web application built by using Visual Studio 2017. I want to test some parts of C# code without using debugger breakpoints. Is there any way to know a certain part of code has run by adding some code at that point? Something like console.log in Javascript? As to make things more specific I'd like to add this "watcher code" inside the following method:

public static void Main(string[] args) { BuildWebHost(args).Run(); }

Is the above doable and how?

how can i simplify this array to make MySQL where condition

4 hours 18 min ago

Array ( [0] => Array ( [ram] => 2 GB ) [1] => Array ( [ram] => 4 GB ) [2] => Array ( [ram] => 6 GB ) [3] => Array ( [screen_size] => 5 - 6 Inch ) [4] => Array ( [screen_size] => 6 - 7 Inch ) [5] => Array ( [network_connectivity] => 3G ) [6] => Array ( [network_connectivity] => 4G ) )

how to show username and password alert inTOFilesTableViewController using TOSMBClient Pod

4 hours 18 min ago

TOSMBClient Pod file was installed. Please refer this link for reference.

In this pod if authentication required it shows alert with username and password in TORootTableViewController class. But i need same alert in TOFilesTableViewController if authentication required. In TOFilesTableViewController i put same code as used in root view but its not working.Can anyone help me.

https://github.com/TimOliver/TOSMBClient

Changing HTML elements from Python on a running Bokeh server instance served by Flask

4 hours 18 min ago

I've been trying to run Bokeh application server that is handled by Flask.

I run the Bokeh server and embed the application mostly using code from https://github.com/bokeh/bokeh/blob/0.12.14/examples/howto/server_embed/flask_embed.py , I changed a few things looking on various topics on stackoverflow and mailing groups and experimented with it for a good few days for now.

Then i sucessfully hooked some callbacks based on on_change properties to my elements

for w in [offset, amplitude, phase, freq]: w.on_change('value', update_data) amplitude_value = amplitude.value offset_value = offset.value phase_value = phase.value freq_value = freq.value calculated_thing = calculate_something(amplitude_value,offset_value,phase_value,freq_value) # Here i want to influence the other elemenents on the webpage based on the output of this calculated thing.

The thing is, i want to get the output values from those sliders (dynamically on change, to the server) and based on that output i want to calculate something in a python function that i will pass to the resulting page. The thing is that those elements are not Bokeh widgets but rather just DIV's and other HTML elements.

I am able to get this functionality by e.g. using custom JS Callback:

w.js_on_change('value', CustomJS(args=dict(amplitude=amplitude, offset=offset, phase=phase, freq=freq),code=js_code)) js_code = """ doc = document.getElementById("dynamic_equation"); doc.textContent = amplitude.value + "sometext" + offset.value; """

Unfortunately I am unable to do this thing solely with JS as i want to utilize Sympy to calculate me some equations based on those values and return the output.

I can give any clarification and further code needed (its about 130 lines now).

How to break a line in centered flexbox div container?

4 hours 18 min ago

I need to align a div element vertically and horizontally. I did that using flex display, but now the elements are displayed in a single line even though <br> is present. How can I separate the paragraph and image elements into two lines?

<style> .container{ width: 100%; height: 100%; } .center{ display: flex; justify-content: center; align-items: center; } </style> <div class="container"> <div style="width: 100%; height: 100%; color: #fff; background-color: black;" class="center"> <p>SOME TEXT</p> <br> <img style="max-height: 100%; max-width: 100%;" src="http://www.jacobsladderky.com/uploads/6/9/1/4/69146851/4652558.png"> </div> </div>

Thanks in advance.

Email Confirm in MVC 5

4 hours 24 min ago

I am trying to send a confirmation email from my API. The mail is sent without problems.

When I load the url from MVC5, I have this error:

I tried:

Asp.NET Identity 2 giving "Invalid Token" error

http://www.gunaatita.com/Blog/Invalid-Token-Error-on-Email-Confirmation-in-Aspnet-Identity/1056 --> My api and my MVC are two projects hosted on two servers, for this reason I try using machineKey validationKey.

The code I use is below:

Web API

if (!await db.Users.AnyAsync(c => c.Email == userRequest.Email)) return StatusCode(HttpStatusCode.NotFound); var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(userContext)); userManager.UserTokenProvider = new TotpSecurityStampBasedTokenProvider<ApplicationUser, string>(); var user = await userManager.FindByNameAsync(userRequest.Email); var userId = user.Id; var code = await userManager.GenerateEmailConfirmationTokenAsync(user.Id); var url = "MyUrl" + "/Account/ConfirmEmail?userId=" + userId + "&code=" + code;

MVC5

if (userId == null || code == null) { return View("Error"); } var result = await UserManager.ConfirmEmailAsync(userId, code); return View(result.Succeeded ? "ConfirmEmail" : "Error");

Execute the remaining code after handling exception in java?

4 hours 26 min ago

I may be silly. But I got interviewed and I was asked question regarding how you will run the remaining code after you will get the exception.

I gave number of approaches :

1. We can write the code in finally. 2. We can write the code in catch block. (They do not want to handle with these 2 approaches. 3. We can use throw keyword. But I tried practically, It's not working.

I tried to explain them with throw statement too.

I have referred so many posts. But My doubt is still present.

As example.

public static void main(String[] args) { a(); // getting exception here... b(); // This method should executed after handling exception }

It will be helpful if I can any approach on this. So I can understand it.

converting difficult string to a list format in python

4 hours 29 min ago

I have strings from a diff file that can occur in multiple ways:

'@@ -1289,4 +1289,4 @@' '@@ -1289,2 +1289 @@' '@@ -1289 +1289,8 @@'

I'd like to find a nice way to cover all possibilities using regex or other tools such that I can output lists as follows for each respective case

[1289,4,1289,4] [1289,2,1289,0] [1289,0,1289,8]

I have tried playing around with regex queries on this website

For example (-\d+,\d+) (\+\d+,\d+). However I'm not sure how to default to zero when it can't match a value. I am quite new to regex but I'm also starting to doubt if this is the tool that I need to be resorting to.

Any elegant ways to do this? Thanks

How can I display pagination in laravel?

4 hours 29 min ago

I use laravel 5.6

I try this documentation : https://laravel.com/docs/5.6/pagination

My controller like this :

public function index() { $products = $this->product->list(); dd($products); return view('admin.product.index',compact('products')); }

My list function like this :

public function scopeList($query) { return $query->orderBy('updated_at', 'desc')->paginate(20); }

If I dd($products);, the result like this :

On the view laravel, I add this :

{{ $products->links() }}

Then I check on the web, the result empty

Why the result empty?

Is there something wrong?

If the image not display, access here : https://postimg.org/image/w39usbfrv/

#2013 - Lost connection to MySQL server during query

4 hours 29 min ago

I have one SQL query , in that query i joined three tables and i run in SQL QUERY it is showing some error, i am not getting why this error coming ,if anyone knows means please update my code

my error is: #2013 - Lost connection to MySQL server during query

My SQL QUERY

SELECT tm.empId,a.companyId,a.tripId,a.startTime,a.endTime,a.tripDate,c.shiftTiming,c.routeId,c.cabId, a.forceEndStatus,a.tripStatus,c.type, ( select count('*') from trip_member as m WHERE m.tripId=a.tripId and m.empPresentStatus = '1' ) as absentcount,( select count('*') from trip_member as m WHERE m.tripId=a.tripId and m.empPresentStatus = '0' ) as presentcount ,( select count('*') from trip_member as m WHERE m.tripId=a.tripId and m.pickupotpStatus = '1' ) as pickupcount FROM trip_details a INNER JOIN cab_allocation as c on c.allocationId = a.allocationId LEFT JOIN trip_member tm ON a.tripId = tm.tripId where c.companyId = '1' order by a.id desc LIMIT 0,30

Suppose i am removing LEFT JOIN trip_member tm ON a.tripId = tm.tripId means it is working fine,

How to comare two columns using VBA EXCEL

4 hours 30 min ago

I need a macro VBA that will takes a code in columns "B" and look for it in column "E" row by row until the end and if it exist => Ok in column "F" else "FALSE" There are so many code in columns B and E.

I tried this code but it doesn't works

Sub ComparerCP() Dim ws1 As Worksheet: Set ws1 = Worksheets("Feuil1") Dim LastRow As Long LastRow = ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row For i = 1 To LastRow If ws1.Cells(i, 2) = ws1.Cells(i, 5) Then ws1.Cells(i, 6) = "OK" Else: ws1.Cells(i, 6) = "FALSE" End If Next i End Sub

Find most recent entries before date criteria

4 hours 33 min ago

I am having trouble on figuring out how to find the most recent entry in a table <= to a specified date.

Example Table:

ENTRY_DATE ID PRICE 01/JAN/2010 1 1.2 01/JAN/2010 2 1.4 01/JAN/2010 3 2.6 02/JAN/2010 1 1.1 02/JAN/2010 2 1.5 02/JAN/2010 3 2.2 03/JAN/2010 1 1.0 03/JAN/2010 2 1.2 03/JAN/2010 3 2.4 04/JAN/2010 2 1.2 04/JAN/2010 3 2.8 05/JAN/2010 1 1.1 05/JAN/2010 3 2.9

I want to be able to say find me the most recent prices for all IDs on or before 05/01/2010. Now there isn't always necessarily a price update for every single ID on the same date, so with the above table I would want the following results:

ENTRY_DATE ID PRICE 04/JAN/2010 2 1.2 05/JAN/2010 1 1.1 05/JAN/2010 3 2.9

So it's returning the prices for IDs 1 and 3 because it found entries for 05/01/2010, and then it's finding the most recent non null value for ID 2 which is from 04/01/2010. I have seen some previous questions/examples for almost similar questions which use Coalesce but I can't get my head around how it works. I also saw some examples which use MAX, and I was running into trouble with it wanting every single column to be in the group by statement. Note: I am using Microsoft SQL Management Server rather than Oracle.

How to store a list of objects in memory at startup of webapi?

4 hours 49 min ago

Hi i'm new in C# development, I want to store a List of objects in memory when I start a simple service in dotnet core with some dummy data and can be able to access them in the Controller.

List<Cat> cats = new List<Cat> { new Cat(){ Name = "Sylvester", Age=8 }, new Cat(){ Name = "Whiskers", Age=2 }, new Cat(){ Name = "Sasha", Age=14 } };

For loop on SELECT2 Jquery plugin

4 hours 56 min ago

while trying to effect all of my 7 selects inputs in my View (.NET CORE 2).

I use this code in my site.js.

for (var i = 0; i<7 ; i++) { var option1 = $('#option1_' + i); var option2 = $('#option2_' + i); var option3 = $('#option3_' + i); var myselect = '#myselect_' + i; option1.click(function() { $(myselect).val($(this).html()).trigger('change'); }); option2.click(function() { $(myselect).val($(this).html()).trigger('change'); }); option3.click(function() { $(myselect).val($(this).html()).trigger('change'); }); }

When clicking on any option only the last one changes, how am I able to affect all of them?

Is a mock MongoRepository saving objects?

6 hours 8 min ago

I am using SpringBoot 1.5.9 and try to do Integration testing. Weirdly a MongoRepository.save() method updates the object when called on mock MongoRepository.

I have a Counter Class

public class Counter { public String id; public int seq; public void increaseSeq() { this.seq += 1; } }

And his repository

public interface CounterRepository extends MongoRepository<Counter, String>{ Counter findById(String id); List<Counter> findAll(); }

And his service

@Service public class CounterService { @Autowired private CounterRepository counterRepository; public Counter findCounter(String id) { return counterRepository.findById(id); } public int getSeqAndIncrease(String id) { Counter counter = findCounter(id); if (counter == null) { return -1; } counter.increaseSeq(); counterRepository.save(counter); return counter.getSeq(); } }

Now, when I do system integration and try to mock the counterRepository, it happens something that I don't expect. The counterRepository.findById() returns a Counter object where the 'seq' field is increased. Why? Does the counterRepository.save() affect the result in any way (the counterRepository is mocked, hence I suppose that save() should not have any effect)?

@RunWith(SpringRunner.class) @SpringBootTest public class FlowServiceTest { @MockBean private CounterRepository counterRepository; @Autowired private CounterService counterService; @Before public void setUp() { Mockito.when(counterRepository.save(any(Counter.class))).then(arg -> arg.getArgumentAt(0, Counter.class)); Mockito.when(counterRepository.findById("flow")).thenReturn(new Counter("flow", 10)); } @Test public void testSavingInDatabase() { System.out.println(counterRepository.findById("flow")); counterService.getSeqAndIncreaseSafe("flow"); System.out.println(counterRepository.findById("flow")); counterService.getSeqAndIncreaseSafe("flow"); System.out.println(counterRepository.findById("flow")); } }

It prints "10 11 12". Why doesn't it print '10 10 10'?

react-router-dom doesn't work

6 hours 12 min ago

It looks like i have some problem with react-router-dom package if i try to install it i have this warning (see the screenshot):

npm WARN react-router-dom@4.0.0 requires a peer of react@^15 but none is installed.
You must install peer dependencies yourself.
npm WARN react-router@4.2.0 requires a peer of react@>=15 but none is installed.
You must install peer dependencies yourself.

I also tried to update all the packages but with bad results.

Any suggestion?

Pages