AlanH

0

votes
0

answer
5

views

Visual Studio- How to view call heirarchy/graph/stack without running code?

In these recent docs, it seems that VS is able to show the call graph/hierarchy of calls to a function. However, in the most recent version of VS, I can't seem to be able to find this. Is this now somewhere else or is there an extension that does something like this?
AlanH
1

votes
2

answer
30

views

How does a link that requires authentication work?

Suppose I sign in to Facebook and I'm looking at a private event. I want to send that link to my friend so that he can join the event. However, doing so requires my friend to log in to Facebook (to be authenticated), so that he can view the event and join it. In other words: I'm logged in, and am on...
AlanH
1

votes
2

answer
52

views

Python: Why does heap give incorrect first pop?

I'm trying to create a max heap by negating all the values of a list, but it doesn't seem to be working: import heapq x = range(1,10) neg = [-n for n in x] heapq.heappop(neg) # -1 heapq.heappop(neg) # -9 heapq.heappop(neg) # -8 Yet if I do heapq.heappop(x) # 1 heapq.heappop(x) # 2 heapq.heappop(x) #...
AlanH
1

votes
1

answer
1k

views

Docker cannot build because can't find matching distribution of a requirement

I'm having difficulty getting my app on Docker. Currently I'm trying to build build it, but am running in to an error I can't figure out how to solve. When I ran docker-compose build, it was pulling and downloading, but when it tried to collect json, it gave the error: Could not find a version that...
AlanH
1

votes
4

answer
5.7k

views

How to check if a function has been called? jQuery

I've been given a script, which I cannot edit (as a part of an exercise). In the script, there is a function which generates random messages for a set of given [fake] users. (It's supposed to emulate a chat room). I need to detect when a message has been generated. As of now, the only thing I can th...
AlanH
1

votes
1

answer
64

views

Python: Unable to kill process with keyboard interrupt?

I have a decorator written as such: import threading from time import sleep from functools import wraps import sys import os def repeat_periodically(f): ''' Repeat wrapped function every second ''' @wraps(f) def wrap(self, *args, **kwargs): def wrap_helper(*args, **kwargs): try: threading.Timer(1.0,...
AlanH
0

votes
0

answer
3

views

Pytest not collecting tests with pytest command

I have in my Project/tests/learn_pytest.py a basic test. This is everything in the file: import pytest import os class Learning(object): def create_file(self): p = tmpdir.mkdir('sub').join('hello.txt') p.write('content') print tmpdir.listdir() assert p.read() == 'content' assert len(tmpdir.listdir()...
AlanH
1

votes
2

answer
195

views

Python: What does the following code do?

Can someone please explain to me piece by piece, what the following does? My code won't run and this part was provided. I've tested all of my code in iPython notebook and everything works, so I don't know if the problem is because of this block below. def main(): args = sys.argv[1:] if not args: pr...
AlanH
1

votes
3

answer
793

views

Pandas: How to create a column based on values of another column?

I need to create a new column at the end of a data frame, where the values in that new column are the result of applying some function who's parameters are based on other columns. Specifically, from another column, but a different row. So for example, if my data frame had two columns, containing val...
AlanH
1

votes
3

answer
72

views

How to loop over properties of objects at the same time in Javascript?

I'm trying to figure out how to loop over two objects at the same time so that I can compare their properties. What I tried was something like for ((prop1, prop2) in (obj1, obj2) { console.log(prop1 == prop2) } which definitely didn't work. How do I do this in js?
AlanH
1

votes
4

answer
99

views

How to understand this example of a logical and ternary operator?

I understand that ternary operators are essentially a shortcut for an if-else statement, and I also understand that && is a logical AND. However, I don't understand how the two are combined in the code below. I tried playing around with the output as well, but it didn't help. How do I interpret the...
AlanH
1

votes
1

answer
228

views

Excel VBA form TextBox passed as an Arguement

I'm trying to pass a TextBox created on a form to a subroutine to inspect the contents of the TextBox and limit the TextBox to numeric data only. Since VBA doesn't have overloading I'm using optional parameters to call the function without any parameters as part of TextBox_Exit event or as a standa...
AlanH
3

votes
4

answer
1.1k

views

How to ignore re-render after store changes?

I have a few components where I outright want to ignore a re-render (or any other change to those components) if certain parts of the store change. How can this be done?
AlanH
2

votes
2

answer
1.8k

views
2

votes
2

answer
39

views

Python Regular expression: is there a symbol to search for more than one occurence of a pattern?

I know that * is 0 or more, and + is 1 or more, but what if I wanted to indicate 2 or more (more than 1)? For example, I have >>> y = 'U0_0, P33, AVG' >>> re.findall(r'[a-zA-Z]+', y) ['U', 'P', 'AVG'] But I only want to obtain ones that have 2 or more letters. In this example, AVG. How do I do thi...
AlanH
5

votes
2

answer
3.1k

views

How to cancel ALL requests in ComponentWillUnmount?

According to the docs, ComponentWillUnmount is able to cancel requests. I have a page that makes requests for an iframe to load, as well as other requests for page. If the user decides to navigate away from the page while the page is still processing the requests, how can I cancel those requests so...
AlanH
6

votes
4

answer
2.3k

views

Avoiding inline functions in React: How to bind functions with arguments?

I'm trying to follow the no-bind rule for React using the pattern that they have recommended with ES6 classes: class Foo extends React.Component { constructor() { super(); this._onClick = this._onClick.bind(this); } render() { return ( Hello! ); } _onClick() { // Do whatever you like, referencing 't...
AlanH
5

votes
4

answer
396

views

Git: How does checking out affect the repository?

I'm not at all experienced with programming, and I'm just starting to learn Git. I don't understand how git checkout works. According to this: Checking out an old commit is a read-only operation. It’s impossible to harm your repository while viewing an old revision. The “current” state of your...
AlanH
8

votes
1

answer
598

views

Python pandas: conditionally select a uniform sample from a dataframe

Say I have a dataframe as such category1 category2 other_col another_col .... a 1 a 2 a 2 a 3 a 3 a 1 b 10 b 10 b 10 b 11 b 11 b 11 I want to obtain a sample from my dataframe so...
AlanH
2

votes
1

answer
32

views

R: How to obtain corresponding column of values?

Let's say I have three columns A, B, and C. I've taken a subset of A (say every other row), how do I obtain the corresponding values of those rows in C? A B C 1 a1 a1 c1 2 a2 b2 c2 3 a3 b3 c3 4 a4 b4 c4 I want: A C 1 a1 c1 2 a3 c3 Note: using every other row for the subse...
AlanH
2

votes
3

answer
311

views

How to split a list by a changing step size?

I have a list that I want to split up in to variable steps sizes. For example, if I have a list from 1 to 100, at the end of each iteration, I would want the output to be: [1, 2, 3] [4, 5, 6, 7, 8] [9, 10, 11, 12, ..., 15] [16, 17, ..., 25] The length of the first list is 3, then 5, then, 7, then 9...
AlanH
6

votes
6

answer
1.8k

views

Python: When do two variables point at the same object in memory?

Here is an example: l = [1, 5, 9, 3] h = l h[0], h[2] = h[2], h[0] print(h) # [9, 5, 1, 3] print(l) # [9, 5, 1, 3] h = h*2 print(h) # [9, 5, 1, 3, 9, 5, 1, 3] print(l) # [9, 5, 1, 3] My understanding was that calling setting h = l would simply point h at the same item in memory that l was pointing a...
AlanH
1

votes
1

answer
88

views

Python: How to obtain directory of current script being run?

In this post, the top answer explains how to (1) obtain the directory of the script being run, and (2) obtain the path of the working directory. However, I'm confused on the usage of __file__. BryanOakley even states to notice the double underscore of __file__, but I do not understand why. Essentia...
AlanH
3

votes
2

answer
100

views

Python: Having difficulty filtering out strings containing certain substrings

I have a list of strings that I'm trying to filter. If it contains the word blahblah, then I want to keep it. I tried it the first way, and I've gone over my code over and over, but I don't know why it retains some strings that don't have the word 'blahblah' in them. However, I tried it a second way...
AlanH
1

votes
1

answer
24

views

Trying to understand closures (JavaScript)

function myFunc(inputFunc){ var called = false; return function() { if (!called) { called = true; var storedResult = inputFunc(); return storedResult; } else return storedResult; }; } In the above code, I don't understand what purpose it serves to have the if-else statement returned in a function. W...
AlanH
12

votes
2

answer
10.6k

views

How to insert multiple elements into a list? [duplicate]

This question already has an answer here: Inserting values into specific locations in a list in Python 7 answers In JavaScript, I can use splice to insert an array of multiple elements in to an array: myArray.splice(insertIndex, removeNElements, ...insertThese) But I can't seem to find a way to do...
AlanH
2

votes
1

answer
268

views

Bookshelfjs: How to fetch all entries based on information of another table

I have a table of users and courses (ex: psychology 101, poli sci 205, etc.). I also have a join table called users_courses. I want to fetch all the courses that belong to a user. I have two questions pertaining to solving this problem: Should I be using fetchAll() on a model or a collection (course...
AlanH
3

votes
3

answer
535

views

Python: How to refer to member variables

I've been learning Python on Codecademy, and I'm quite confused. I can't figure out how to refer to member variables (I hope that's what they're called). Here's a piece of code I wrote to demonstrate my confusion: class Triangle(object): number_of_sides = 3 def __init__(self, angle1, angle2, angle3)...
AlanH
3

votes
3

answer
2.5k

views

Is there an equivalent of Python's list and append feature in Matlab?

This is more of a Matlab programming question than it is a math question. I'd like to run gradient descent multiple on different learning rates. I have a set of learning rates alpha = [0.3, 0.1, 0.03, 0.01, 0.003, 0.001]; and each time I run gradient descent, I get a vector J_vals as output. Howev...
AlanH
1

votes
1

answer
1.6k

views

How to understand underscore's invoke

I'm trying to understand underscore's invoke() function, but I'm having trouble in a few areas. Here's the code from the annotated source: _.invoke = function(obj, method) { var args = slice.call(arguments, 2); var isFunc = _.isFunction(method); return _.map(obj, function(value) { var func = isFunc...
AlanH
3

votes
2

answer
323

views

How to access an element of an array without using indexer (javascript)?

Let's say I have a single element array ['someStringHere'] (I don't know in advance what the string will be) and I want to access the string so that my function returns the string and not the array, how could I do so without using an indexer (ex: array[0])? In other words, it would be as if I could...
AlanH
4

votes
4

answer
1.1k

views

How to curry a function across an unknown number of parameters

Say I have a function called multiplyDivide If I were to call multiplyDivide(2)(3)(4)(6) it would be equivalent to 2 * 3 / 4 * 6. Update: Is it possible to write a function like this if I don't know in advance how many parameters I will be taking? For example, I could have multiplyDivide(1)(2) or mu...
AlanH
4

votes
1

answer
68

views

Summarizing dataframe into a dictionary

I have a pandas data frame like such date hour level 0 2015-10-27 0 2.5 1 2015-10-27 1 2.5 2 2015-10-27 2 2.5 3 2015-10-27 3 2.5 4 2015-10-28 0 0.0 5 2015-10-28 1 0.0 6 2015-10-28 2 0.0 7 2015-10-28 3 0.0 8 2015-10-28 4...
AlanH
3

votes
4

answer
369

views

Python: reference variable in nested function's outer scope (not global) [duplicate]

This question already has an answer here: Is it possible to modify variable in python that is in outer, but not global, scope? 8 answers I'm trying to recurse a tree and track the path of the traversal up to the point where I find an element that I'm looking for. However, I encounter two issues: W...
AlanH
2

votes
1

answer
96

views

Need help understanding recursive function to generate all combinations of a string

I came across this code, but am having a hard time figuring out how the flow of this function is working. function combinations(str) { var fn = function(active, rest, a) { if (!active && !rest) return; if (!rest) { a.push(active); } else { fn(active + rest[0], rest.slice(1), a); fn(active, rest.sli...
AlanH
1

votes
2

answer
269

views

Accessing arguments object using ES6

According to MDN, I should be able to do the following: const test = (a, b, c, d) => { console.log(...arguments); } test(1, 2, 3, 4); However, I'm getting the actual arguments object, not [1,2,3,4]. How do I do this using ES6?
AlanH
2

votes
1

answer
2.5k

views

Manipulating sparse matrices in Matlab

Suppose I have a sparse matrix Sparstica that is a vertical concatenation of several other sparse matrices. When I type Sparstica(:), I get a list of the nonzero elements. In the left column, will be the index of the element, in the right column will be the nonzero element. How can I manipulate the...
AlanH
2

votes
1

answer
3k

views

Getting different colors for different numbers using `spy` in Matlab

When I use spy to check a sparsity pattern, it doesn't distinguish certain elements from others. Is there any way to do this? Say, for example, elements that are equal to 10 are red and all elements equal to 9 are blue. Can I get this in one spy plot? I've only been able to change the size and style...
AlanH
4

votes
2

answer
17.6k

views

pandas: how to store a list in a dataframe? [duplicate]

This question already has an answer here: Python pandas insert list into a cell 3 answers I want to set a cell value as a list. Say for example: df.loc['a']['b'] = ['one', 'two', 'three'] However, I'm unable to do so as I get the following error: ValueError: Must have equal len keys and value when...
AlanH
2

votes
2

answer
1.2k

views

How can I recursively generate an Array of the Fibonacci sequence?

I've seen several posts on generating a given fibonacci sequence, such as this one. However, I can't figure out how to generate the sequence (return an array) of fibonnaci numbers for a given n using recursion. What I have clearly doesn't work, but I really can't figure out how to do it otherwise....
AlanH

View additional