Skip to content

Instantly share code, notes, and snippets.

@delwar2016
delwar2016 / How to stub jQuery remove using sinonJS
Created January 16, 2017 13:35
How to stub jQuery remove using sinonJS
Suppose we have following situation
$('#dom1').remove();
$('#dom2').remove();
$('#dom3').remove();
$('#dom4').remove();
So, we can write unit test as follows:
this.removeStub = sinon.stub($.fn, 'remove');
it('Should remove dom', function(){
@delwar2016
delwar2016 / Explain NumPy array object
Last active February 13, 2017 15:57
Explain NumPy array object
import numpy as np
# Manual construction of arrays
# one dimension array
a = np.array([0,1,2,3])
print(a)
print ('dimension', a.ndim)
@delwar2016
delwar2016 / Explain Python's slice notation
Last active January 10, 2017 01:59
Explain Python's slice notation
array[start:end:step] # start through not past end, by step
start: the beginning index of the slice, it will include the element at this index unless it is the same as end, defaults to 0, i.e. the first index.
If it's negative, it means to start n items from the end.
end: the ending index of the slice, it does not include the element at this index,
defaults to length of the sequence being sliced, that is, up to and including the end.
step: the amount by which the index increases, defaults to 1. If it's negative, you're slicing over the iterable in reverse.
@delwar2016
delwar2016 / mongodbUpdateQuery
Created September 29, 2016 05:34
mongodb update document
Suppose we have the following document in users_exams collection:
{
"answers" : [
{
"auto_score" : 0,
"question_id" : "579733a97e6b58a0616b2c55",
"user_answers" : "na",
"isCorrect" : false,