Is there a way to replace the same string across multiple anki cards? - sqlite

I'm a fan of the dark theme but I'm a little bothered by the lack of contrast with the dark blue color in several of my cards.
I have many cards created years ago where I used the blue color to highlight some of the content and it worked well.
But now, with the dark theme, the contrast of the background with the blue is horrible and uncomfortable on the eye.
as I have many cards, I would like to know if there is a way to perform the same replacement on multiple cards?
I managed to change the blue color on the hidden word type cards but I still have a lot of blue words scattered around the deck.
Looking at the source code for the cards, I realized that I needed to replace all occurrences of
color: rgb(0, 0, 255);
for something like
color: rgb(255, 85, 0);

The simplest way I found to replace text on multiple cards was by operating directly on the sqlite database.
The step by step was more or less this:
Download and install sqlite database reader. Like this one.
Locate the folder on is anki's sqlite file. On windows, just go to %APPDATA%\Anki2 and locate the collection.anki2 file inside some subfolder. Instructions for other platforms are here.
Close anki and make a backup copy of collection.anki2 in case something goes wrong.
Open collections.anki2 in the sqlite database reader application and then run the sql commands to perform the text replacements. For example, for color changes described in the question I run the following SQL codes:
UPDATE notes SET flds = replace( flds 'color: rgb(0, 0, 255);', 'color: rgb(255, 85, 0);');
UPDATE notes SET sfld = replace( sfld 'color: rgb(0, 0, 255);', 'color: rgb(255, 85, 0);');
explaining the command references:
notes is the table that holds the texts of all the cards
flds is the column that holds the text on the front of each card is the
sfld column that contains the text on the back of each card

Related

How to automatically resize all tables to optimal column width in a docx with LibreOffice Writer?

Problem
I have 100+ *.docx files created with Microsoft Word on a Windows machine that I would like to use with LibreOffice Writer.
Unfortunately, somehow all the tables have been squished in Writer as shown:
I've tried to fix this by:
Selecting the entire table (ctrl-a, ctrl-a)
Right-click the table
Go to size
Click optimal column width
This indeed gives me the desired result:
What I've tried so far
failed approach 1
I've created the following macro that does the formatting for a single table:
REM ***** BASIC *****
sub setTableColumns
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:SelectAll", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:SelectAll", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:SetOptimalColumnWidth", "", 0, Array())
end sub
I've assigned a keyboard shortcut to this macro such that I can reformat a single table by:
Clicking on the table of interest.
Running the shortcut.
This is an improvement, but it still requires a lot of manual work.
failed approach 2
I've also tinkered with the examples given in this different SO question.
I've managed to set the relative width of all tables to 100% by changing this property of all my tables:
https://www.openoffice.org/api/docs/common/ref/com/sun/star/text/TextTable.html#RelativeWidth
I did this by using the following macro (snippet):
tables = ThisComponent.TextTables
for tid = 0 to tables.count - 1
table = tables(tid)
table.RelativeWidth = 100
next
This does widen all the tables, however the format is not desirable.
Question
Is there a way to apply the optimal column width setting to all tables in a file?
It would be awesome if I could apply it to all tables in multiple docx files at once.
However, it would already make me very happy if I could automatically format all tables in a single docx file.
The code needs to loop through all tables in the document, select each one and then optimize the selected table.
The following Basic code from Andrew Pitonyak's macro document section 7.2.1 shows how to select a table.
ThisComponent.getCurrentController().select(oTable)
Here is some python code from a project of mine.
cellsRange = table.getCellRangeByPosition(
0, 0, endCol, numRows - 1)
controller.select(cellsRange)
dispatcher.executeDispatch(
frame, ".uno:SetOptimalColumnWidth", "", 0, ())
There are also ways to loop through a set of documents, so the code can open, optimize, save and close each document. The most difficult part is closing properly without a crash, as closing events can sometimes interrupt each other.
If this is a problem, you may find it easier to open, save and close each by hand, running the macro to optimize all tables in the currently open document. It's also not too hard to loop through all open documents, if you find it more convenient to open multiple files at the same time.

Testkitchen / KitchenCI - How to change console output colors?

In the present case Ansible is used with KitchenCI/Testkitchen.
Question: How can I control the color of the kitchen output?
I tried different coloroptions in ansible but for kitchen I didn't find any options, but this bugs me, especially if the color of the kitchenoutput turns darkblue suddenly.
Problem:
The color of the kitchen-output changes, depending on ...I don't know...
(It doesn't change every run, but at some time, something initiates the colorchange and then it will keep the color for a while)
Sometimes it's an ugly pink:
Sometimes it's yellow, green or cyan:
... But most annoyingly, if it's darkblue, suddenly, and I can't read stuff:
Setup: i3, xfce4-terminal, zsh, sometimes in tmux, with echo $TERM # -> screen-256color
I think, if something in the folderstructure change, or something in the current ansible environment (the shell-options are always the same), e.g. if I clone the whole directory (at least thats where I recognized it last time). It can even be a different color if I change the directory in the "roles" directory. But all in all I can't point my finger at it and I would be glad for help.
If more Information is needed, I would gladly provide it.
Update:
Maybe it's something in ~/.rvm/gems/ruby-2.5.1/gems/...
Theres a lot of code regarding "tty"
This does not answer the question (that's still interesting! because I don't want the color to change), but targets the underlying problem, meaning the non-readablitity of the blue color.
The reason was the configuration of "xfce4-terminal".
In xfce4-terminal one can define the representation for colors in the right-click: 'preferences' > 'colors' > 'Palette'
If a background-color is set, that would conflict with the color "blue" (dark blue), the representation for the color "blue" can be change (e.g. to grey, or light blue, or everything else).
See the screenshot:

Reading multiple lines from QTextedit

I'm trying to write my own code-editor, I figure its a good way to learn pyQt.
I am using a qtextedit, in which i can write code(it's not real code, more pseudo code).
Each line represents ending in a semi-colon represents some command
e.g.
PSEUDO->FWD->90;
PSEUDO->STOP;
PSEUDO->RIGHT 90;
PSEUDO->FWD 10;
These are relatively easy to read, as the user presses the [ENTER] the current line is read, parsed and checked for errors so the following
PSEUDO->RIGHT -pi/2
would generate an error because the line doesn't end in a semi-colon and the value following RIGHT needs to be a number.(my editor, my rules).All this I have more or less got working.
I would like to know how to do multiple lines though. I am familiar with editors such as Eclipse,sublime or visual studio which handle muliple lines very well, in my case
PSEUDO->DO:
FWD->90
RIGHT->45
FWD->10
LEFT->55
FWD->50
STOP;
Should all be read in and treated as one statement, starting at the keyword PSEUDO and ending at the semi-colon.
However the following should be read as 3 separate statements.
PSEUDO->DO:
FWD->90
RIGHT->45
FWD->10
LEFT->55
FWD->50
STOP;
PSEUDO->DO:
FWD->90
RIGHT->45
STOP;
PSEUDO->BACK 10;
My question how can I go about reading muliple lines as described above from QTextEditor as discreet statements.
Should I do the parse/check whenever I press the [ENTER] key for a new line?
I'm using python2.7,pyQT, and QTextEdit.
Basically what you are trying to do, can be done with all the text of the document and some regular expressions. I would be careful with this course, because it may slow things down.
So to stay lean and to use the right classes of Qt, I would use anything related to the Rich Text Processing, QTextDocument, and QTextCursor.
I have used QSyntaxHighlighter quite a bit, and QRegExp. There is now QRegularExpression, too. Here are the classes and general documentation I'd look at to get started with Rich Text processing.
http://doc.qt.io/qt-5/qtextblock.html#details
http://doc.qt.io/qt-5/richtext-structure.html
http://doc.qt.io/qt-5/richtext.html
http://doc.qt.io/qt-5/richtext-cursor.html
http://doc.qt.io/qt-5/richtext-common-tasks.html#finding-text
Hope that helps.

SASS Variables converting to Hex Codes

I have been using SASS for a month, love it.
However, when I create a variable such as:
$darkgrey:rgb(82,81,83);
Then decide re-use the variables, say in a specific p tag? In the body:
body{
p.ahh-whatever{
color:$darkgrey;
}
}
However it always seems to come up as a HEX in all browsers. Is there a reason for this? Do I need to use RGBA with 1 Opacity...
Software Being Used:
I also use Foundation 3 inline with Compass-Style. In addition to CodeKit to compile my code, and Sublime Text 2 for my editor. Operating System is OSX 10.8 (New IMac 27").
Any help would be great!
SASS will output hex whenever possible, because almost all browsers will understand it.
(Not all browsers will "get" RGB values or RGBA values.)
if you do specify a an rgba value, SASS will output it as such
for instance :
rgba(blue, 0.2)
will output :
rgba(0, 0, 255, 0.2)
see : Sass RGBA instances documentation

Unicode characters in qt app dont show up

I'm trying to display different language strings in my qt app by inserting each language into a QMap<QString, QString> so it can be re-used in several places and put into different combo Boxes across the application. I do this by
creating the QMap like so in the CTOR:
m_langMap.insert(QString::fromWCharArray(L"English"), "english");
m_langMap.insert(QString::fromWCharArray(L"Dansk"), "dansk");
m_langMap.insert(QString::fromWCharArray(L"Nederlands"), "dutch");
m_langMap.insert(QString::fromWCharArray(L"Čeština"), "czeck");
m_langMap.insert(QString::fromWCharArray(L"Slovenský"), "slovak");
m_langMap.insert(QString::fromWCharArray(L"Magyar"), "hungarian");
m_langMap.insert(QString::fromWCharArray(L"Român"), "romanian");
m_langMap.insert(QString::fromWCharArray(L"Latviešu"), "latvian");
m_langMap.insert(QString::fromWCharArray(L"Lietuvių"), "lithuanian");
m_langMap.insert(QString::fromWCharArray(L"Polski"), "polish");
m_langMap.insert(QString::fromWCharArray(L"Português"), "portuguese");
m_langMap.insert(QString::fromWCharArray(L"Español"), "spanish");
m_langMap.insert(QString::fromWCharArray(L"Français"), "french");
m_langMap.insert(QString::fromWCharArray(L"Italiano"), "italian");
m_langMap.insert(QString::fromWCharArray(L"Svenska"), "swedish");
m_langMap.insert(QString::fromWCharArray(L"Русский"), "russian");
m_langMap.insert(QString::fromWCharArray(L"Українська"), "ukranian");
m_langMap.insert(QString::fromWCharArray(L"Русский"), "russian");
m_langMap.insert(QString::fromWCharArray(L"中文"), "chinese");
m_langMap.insert(QString::fromWCharArray(L"日本語"), "japanese");
I then insert them into the combo box:
QMap<QString, QString>::const_iterator it = m_langMap.begin();
while (it != m_langMap.end())
{
ui->comboBox->addItem(it.key());
++it;
}
When the app runs, I see the following:
However, if I create a separate .ui file and insert the map the same way, I see the following (even if I include this separate Dialog class into the same application), so clearly there is no font issue as far as the App not knowing how to render the different character sets....yet I cant figure out why the first one won't render the character sets?
Can someone tell me why the first doesn't work but the second does? I checked the Designer and its Locale is set to 'C, Default' in both ui files I've shown below. I can't seem to figure out what else is causing the difference for the first not to work, and the second does work within the same application.
Thanks for any help!
The other test Dialog:
Your code is correct, but the problem is that your source file cannot contain Unicode characters - apparently it is using different coding.
Save file as UTF-8 and everything should work!
In the first screenshot the font used by the combobox is much larger than in the second screenshot. My guess is that you have changed the font either in the GUI designer or in the code and the second (working) screenshot is using the default font. It might be that when you have changed the font size, you have also changed the font to something that doesn't contain all the required Unicode characters. Try changing the font used by the combobox to something else.

Resources