Posts

r - Making a list of zeros and ones from a large list -

i have large list looks this: 1 2 3 3 and need create list looks this: |------|------|------|------| | 1 | 1 | 0 | 0 | |------|------|------|------| | 2 | 0 | 1 | 0 | |------|------|------|------| | 3 | 0 | 0 | 1 | |------|------|------|------| | 3 | 0 | 0 | 1 | |------|------|------|------| i have tried using loops, , method detailed here: create mutually exclusive dummy variables categorical variable in r but because dataset large, run memory constraints. am thinking of using split, apply, combine technique, not able desired result. help appreciated! here ways: 1) outer gives matrix result: x <- c(1, 2, 3, 3) outer(x, unique(x), "==") + 0 giving: [,1] [,2] [,3] [1,] 1 0 0 [2,] 0 1 0 [3,] 0 0 1 [4,] 0 0 1 2) model.matrix gives matrix result. fx <- factor(x) model.matrix(~ fx + 0) giving: fx1 fx2 fx3 1 1 0 0 2 ...

html - Pure CSS accordion not working within CSS tabs -

i have pure css accordion using checkbox input+label trick. source code can found here: accordion: https://codepen.io/raubaca/pen/pzzpve tabs: https://css-tricks.com/css3-tabs/ accordion works outside of tabs. challenge making accordion work within tabs, not expanding , contracting. adjusted position, z-index, height, etc.. have had no success. how can make accordion work inside tabs? https://jsfiddle.net/lance_bitner/z5odxw88/ .tab > input:checked ~ .tab-content { max-height: 100%; } .tab > label::after { position: absolute; left: -20px; top: -9px; display: block; width: 3em; height: 3em; line-height: 3em; text-align: center; -webkit-transition: .35s; -o-transition: .35s; transition: .35s; } .tab > input[type=checkbox] + label::after { content: " + "; font-size: 18px; font-weight: 900; } .tab > input[type=radio] + label::after { content: " \25bc "; } .tab > input[type=checkbox]:checked + label::after { transform...

Why is C++ behaving weirdly when I add leading 0's to an int? -

why cout << 0110 << endl; printing out 72? i didnt' think adding leading 0's int make difference, shouldn't '0110' same '110'? note 0110 octal-literal : octal-literal digit 0 (0) followed 0 or more octal digits (0, 1, 2, 3, 4, 5, 6, 7) that's why you're getting 72 when printing out it, it's not same 110 .

shell - how to check ssh exit command executed? -

i want check exit command executed success in ssh session. my first attempt using command exit && echo $? || echo $? .the echo $? || echo $? ,it should print 0 if exit successful. problem echo never execute if exit execute success because connection disconnected , later command lost. my second attempt splitting command 2 command, this: $ exit $ echo $? echo $? should 0 if exit execute successful. problem echo $? maybe swallowed because send arrived remote ssh host before exit executed. so, how ensure exit executed @ remote host before send next command? update using stage execute shell command @ program language , send message ssh pipe stream.so, don't know exit command executed time.if exit command not completed, follow commands swallowed because send exiting host. why i'm care exit command executed. if main concern knowing local machine, define variable earlier in script known on local machine before ssh. after exiting test e...

unit testing - Mock patch decorators python -

hi mock decorator since don't want calling/executing function. can't seem find solution below code # decorator located in project # located in custom.mydecorators.decorator_file.custom_decorator base = declarative_base() def custom_decorator(func): @wraps(func) def wrapper(*args, **kwargs): print("this message still printed when try patch function") try: #code here my_var = coolclass() retval = func(*args, **kwargs) except exception e: #rollback code here raise e return retval return wrapper now i'm trying patch using code patch('custom.mydecorators.decorator_file.custom_decorator', lambda x: x).start() class testmockdecoratorscallingclass(unittest.testcase): def test_should_return_success_if_decorators_are_mocked(self): # code here my decorators work in non unittest file. if mock decorator fails saying local variable 'my_var' referenced before assignment note: my_...

Running Custom Android ROM on Emulator -

i built custom rom based out of aosp (7.0 nexus 6) , use rom sdk emulator. lunch combo build 'aosp_x86_64-eng' believe should work on sdk emulator. however, don't see option in avd manager specify custom system image. allows me use listed roms google. i tried copying custom rom's system.img on stock nexus 6 avd emulator doesn't launch after that. note emulator gets generated during build works fine. build happens on server, , want use generated rom on development machine sdk's avd manager. found out can done using following steps. create compatible avd using stock avd system images. in case, used system image nexus 6 running nougat on x86_64 abi. go ~/.android/avd folder , locate folder avd created above (ex. ~/.android/avd/test.avd). copy custom system.img file folder. run emulator! when tried first time didn't work me because have chosen wrong base image (nougat x86 instead of x86_64). catch make sure stock system image compatibl...

coding style - Why 'window.onload' but simply 'document' instead of 'window.document' in conventional JavaScript code? -

in javascript come across, see programmers write window.onload instead of writing onload . but when comes accessing document object, write document instead of window.document . is there specific reason inconsistency in coding convention? the document available in scope, unless it's overwritten, doesn't happen. that means 1 can do var obj = { key : function() { return document.getelementbyid('test'); // still document } } console.log( obj.key() ); <div id="test"></div> this beacuse document in global special variable available, window on other hand, elements have onload function, of time 1 isn't dealing window.onload if writing onload . not that, being property of object, depends on this being window, in global scope. create other scope, , onload other window.onload var obj = { key : function() { onload = function() { // not window.onload cons...