How to toggle multiple master windows orientation - xmonad

I'm using the following XMonad.Layout.ThreeColumns layout
-----------------------------------
| | | |
| | | |
| | | |
|--------| Master |--------|
| | | |
| | | |
| | | |
-----------------------------------
when I use sendMessage (IncMaster 1) via hotkey it splits Master window horizontally
-----------------------------------
| | | |
| | Master 1 | |
| | | |
|--------|---------------|--------|
| | | |
| | Master 2 | |
| | | |
-----------------------------------
How to split it vertically or toggle it to vertical orientation?
To make it like this:
-------------------------------------
| | | | |
| | | | |
| | | | |
|--------|Master 1|Master 2|--------|
| | | | |
| | | | |
| | | | |
-------------------------------------

Solved by forking Layout and hard coding it to split vertically:
mkdir -p ~/.xmonad/lib/XMonad/Layout
wget "https://raw.githubusercontent.com/xmonad/xmonad-contrib/master/XMonad/Layout/ThreeColumns.hs" -o ~/.xmonad/lib/XMonad/Layout/My.hs
Change module name:
module XMonad.Layout.My
Fix importing XMonad.Prelude module problems:
-- import XMonad.Prelude
import Control.Monad (ap, msum)
Change behavior from this:
tile3 middle f r nmaster n
| n <= nmaster || nmaster == 0 = splitVertically n r
| n <= nmaster+1 = splitVertically nmaster s1 ++ splitVertically (n-nmaster) s2
| otherwise = splitVertically nmaster r1 ++ splitVertically nslave1 r2 ++ splitVertically nslave2 r3
to this:
tile3 middle f r nmaster n
| n <= nmaster || nmaster == 0 = splitHorizontally n r
| n <= nmaster+1 = splitVertically nmaster s1 ++ splitVertically (n-nmaster) s2
| otherwise = splitHorizontally nmaster r1 ++ splitVertically nslave1 r2 ++ splitVertically nslave2 r3
~/.xmonad/xmonad.hs:
--import XMonad.Layout.ThreeColumns
import XMonad.Layout.My

Related

Python list print - order and space for missing values in either list

Let's suppose I have the following two lists:
foo = [A,B,C,D,Z,G]
bar = [A,C,D,E,F,G,X,H]
I want to print them out as following:
| A | A |
| B | |
| C | C |
| D | D |
| z | |
| | E |
| | F |
| G | G |
| | x |
| | H |
I'm doing a very complicated if else, just want to know if you guys have a simpler way of doing this. TIA
Try this solution
foo = ["A","B","C","D","Z","G"]
bar = ["A","C","D","E","F","G","X","H"]
all_list = sorted(list(set(foo+bar)))
res = ""
for i in all_list:
left = i if i in foo else " "
right = i if i in bar else " "
res += "|"+left+"|"+right +"|" + "\n"
print(res)
output
|A|A|
|B| |
|C|C|
|D|D|
| |E|
| |F|
|G|G|
| |H|
| |X|
|Z| |

Expand single row into multiple rows if next column has content in a spreadsheet

I have a tree structure defined in a Google spreadsheet. I need to modify the following structure:
+---+------------+-----------------+--------------------+-----+--------------+
| | A | B | C | D | E |
+---+------------+-----------------+--------------------+-----+--------------+
| 1 | Techniques | Adduction d'eau | Conduites en fonte | Eau | Tuyaux |
| 2 | | | | | Robinetterie |
| 3 | | | | | Outils |
| 4 | | | | | Accessoires |
| 5 | | | | Gaz | Tuyaux |
| 6 | | | | | Robinetterie |
| 7 | | | | | Outils |
| 8 | | | | | Accessoires |
+---+------------+-----------------+--------------------+-----+--------------+
into this:
+----+------------+-----------------+---------------------+-----+--------------+
| | A | B | C | D | E |
+----+------------+-----------------+---------------------+-----+--------------+
| 1 | Techniques | | | | |
| 2 | | Adduction d'eau | | | |
| 3 | | | Conduites en fonte | | |
| 4 | | | | Eau | |
| 5 | | | | | Tuyaux |
| 6 | | | | | Robinetterie |
| 7 | | | | | Outils |
| 8 | | | | | Accessoires |
| 9 | | | | Gaz | |
| 10 | | | | | Tuyaux |
| 11 | | | | | Robinetterie |
| 12 | | | | | Outils |
| 13 | | | | | Accessoires |
+----+------------+-----------------+---------------------+-----+--------------+
Any idea how to proceed? Thanks in advance
Here's my solution. Probably not perfect but it does the job.
var ss = SpreadsheetApp.getActiveSpreadsheet();
function onOpen() {
var menu = [{name:"Split in rows", functionName:"splitInRows"}];
ss.addMenu("Extras", menu);
}
function splitInRows() {
// Get the current sheet, row, and column.
var sheet = ss.getActiveSheet();
var lastRow = sheet.getLastRow();
var lastColumn = sheet.getLastColumn();
var range = sheet.getRange(1, 1, lastRow, lastColumn);
var numRows = range.getNumRows();
var numCols = range.getNumColumns();
for (var i = numRows; i > 0; i--) {
for (var j = numCols; j > 0; j--) {
var cell = range.getCell(i,j);
var cellValue = cell.getDisplayValue();
if ( j > 1 && cellValue ) {
// check if previous cell has content
var previousCellValue = range.getCell(i,j-1).getDisplayValue();
if (previousCellValue){
// create empty row
sheet.insertRowsAfter(i, 1);
// move cell value into cell just below
var currentCell = sheet.getRange(i, j);
var belowCell = sheet.getRange(i+1, j);
currentCell.copyTo(belowCell, {contentsOnly:true});
currentCell.clearContent();
}
}
}
}
}

Pandas sort not sorting data properly

I am trying to sort the results of sklearn.ensemble.RandomForestRegressor's feature_importances_
I have the following function:
def get_feature_importances(cols, importances):
feats = {}
for feature, importance in zip(cols, importances):
feats[feature] = importance
importances = pd.DataFrame.from_dict(feats, orient='index').rename(columns={0: 'Gini-importance'})
importances.sort_values(by='Gini-importance')
return importances
I use it like so:
importances = get_feature_importances(X_test.columns, rf.feature_importances_)
print()
print(importances)
And I get the following results:
| PART | 0.035034 |
| MONTH1 | 0.02507 |
| YEAR1 | 0.020075 |
| MONTH2 | 0.02321 |
| YEAR2 | 0.017861 |
| MONTH3 | 0.042606 |
| YEAR3 | 0.028508 |
| DAYS | 0.047603 |
| MEDIANDIFF | 0.037696 |
| F2 | 0.008783 |
| F1 | 0.015764 |
| F6 | 0.017933 |
| F4 | 0.017511 |
| F5 | 0.017799 |
| SS22 | 0.010521 |
| SS21 | 0.003896 |
| SS19 | 0.003894 |
| SS23 | 0.005249 |
| SS20 | 0.005127 |
| RR | 0.021626 |
| HI_HOURS | 0.067584 |
| OI_HOURS | 0.054369 |
| MI_HOURS | 0.062121 |
| PERFORMANCE_FACTOR | 0.033572 |
| PERFORMANCE_INDEX | 0.073884 |
| NUMPA | 0.022445 |
| BUMPA | 0.024192 |
| ELOH | 0.04386 |
| FFX1 | 0.128367 |
| FFX2 | 0.083839 |
I thought the line importances.sort_values(by='Gini-importance') would sort them. But it is not. Why is this not performing correctly?
importances.sort_values(by='Gini-importance') returns the sorted dataframe, which is overlooked by your function.
You want return importances.sort_values(by='Gini-importance').
Or you could make sort_values inplace:
importances.sort_values(by='Gini-importance', inplace=True)
return importances

Spark: join multiple times on the same dataset

In order to enrich my stream data, I join it with a static dataset.
Actually, I join my input dataset twice with the same dataset to add informations about seller and buyer.
input:
+-----------+------+-----+------+
|transaction|seller|buyer|amount|
+-----------+------+-----+------+
| 1 | A | D | 100 |
| 2 | B | A | 10 |
| 3 | C | A | 20 |
+-----------+------+-----+------+
static dataset:
+------+-------+
|person|address|
+------+-------+
| A | #A |
| B | #B |
| C | #C |
| D | #D |
+------+-------+
Code:
iputDF.join(staticDS, iputDF("seller") <=> staticDS("person"))
.join(staticDS, iputDF("buyer") <=> staticDS("person"))
output:
+-----------+------+-------+-----+------+------+
|transaction|seller|#seller|buyer|#buyer|amount|
+-----------+------+-------+-----+------+------+
| 1 | A | #A | D | #D | 100 |
| 2 | B | #B | A | #A | 10 |
| 3 | C | #C | A | #A | 20 |
+-----------+------+-------+-----+------+------+
Is there an optimal solution to do this?

What does this nltk-boxer DRT output mean?

After much headache, I have finally managed to get Boxer and nltk boxer working. However, the output that I get from nltk boxer is somewhat different from what I was expecting. An example sentence like "Bob knows that John likes cows" should look like:
__________________ ____________________
|x1 x2 | |x3 x4 |
|..................| |....................|
(|named(x2,bob,per) |+|know(x3) |)
|named(x1,john,geo)| | Actor(x3,x2) |
|__________________| | Topic(x3,x4) |
| ______________ |
| |x5 x6 ||
| x4:|..............||
| |like(x5) ||
| | Actor(x5,x1)||
| | Theme(x5,x6)||
| |cow(x6) ||
| |______________||
|____________________|
But instead, it looks like:
_____________________
| e1 p1 x1 x2 |
|---------------------|
| ne_geo_john(x2) |
| ne_per_bob(x1) |
| Topic(e1,p1) |
| Actor(e1,x1) |
| v_know(e1) |
| ______________ |
| p1:| e2 x3 | |
| |--------------| |
| | Theme(e2,x3) | |
| | Actor(e2,x2) | |
| | v_like(e2) | |
| | n_cow(x3) | |
| |______________| |
|_____________________|
Why is that?

Resources