Select every other element from a vector

remove[c(TRUE, FALSE)] will do the trick. How it works? If logical vectors are used for indexing in R, their values are recycled if the index vector is shorter than the vector containing the values. Here, the vector remove contains ten values. If the index vector c(TRUE, FALSE) is used, the actual command is: remove[c(TRUE, FALSE, … Read more

List of all unique characters in a string?

The simplest solution is probably: In [10]: ”.join(set(‘aaabcabccd’)) Out[10]: ‘acbd’ Note that this doesn’t guarantee the order in which the letters appear in the output, even though the example might suggest otherwise. You refer to the output as a “list”. If a list is what you really want, replace ”.join with list: In [1]: list(set(‘aaabcabccd’)) … Read more

JavaScript createElementNS and SVG

I hope, the following example will help you: function CreateSVG() { var xmlns = “http://www.w3.org/2000/svg”; var boxWidth = 300; var boxHeight = 300; var svgElem = document.createElementNS(xmlns, “svg”); svgElem.setAttributeNS(null, “viewBox”, “0 0 ” + boxWidth + ” ” + boxHeight); svgElem.setAttributeNS(null, “width”, boxWidth); svgElem.setAttributeNS(null, “height”, boxHeight); svgElem.style.display = “block”; var g = document.createElementNS(xmlns, “g”); svgElem.appendChild(g); … Read more

Division in script and floating-point

You could use the bc calculator. It will do arbitrary precision math using decimals (not binary floating point) if you set increease scale from its default of 0: $ m=34 $ bc <<< “scale = 10; 1 – (($m – 20) / 34)” .5882352942 The -l option will load the standard math library and default … Read more

Convert hex to float

In Python 3: >>> import struct >>> struct.unpack(‘!f’, bytes.fromhex(‘41973333’))[0] 18.899999618530273 >>> struct.unpack(‘!f’, bytes.fromhex(‘41995C29’))[0] 19.170000076293945 >>> struct.unpack(‘!f’, bytes.fromhex(‘470FC614’))[0] 36806.078125 In Python 2: >>> import struct >>> struct.unpack(‘!f’, ‘41973333’.decode(‘hex’))[0] 18.899999618530273 >>> struct.unpack(‘!f’, ‘41995C29’.decode(‘hex’))[0] 19.170000076293945 >>> struct.unpack(‘!f’, ‘470FC614’.decode(‘hex’))[0] 36806.078125

Programmatically adding TableRow to TableLayout not working

Got it, every LayoutParams should be of android.widget.TableRow.LayoutParams except one that supplied to tl.addView(…) /* Find Tablelayout defined in main.xml */ TableLayout tl = (TableLayout) findViewById(R.id.SaleOrderLines); /* Create a new row to be added. */ TableRow tr = new TableRow(this); tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT)); /* Create a Button to be the row-content. */ Button b = … Read more