Sunday, January 21, 2024
Tcl 'oo::define self' explained
oo::class create c {
method a {} { puts "c a" }
self method b {} { puts "c b" }}
c create o
# this raises unknown method "a", because 'a' is a member of 'c' as a class, not as an object
# c a
# this works, because 'b' is a member of 'c' as an object, due to self, see man oo_define (^ *self)
c b
# this works, because 'a' is a member of the class 'c' that created o
o a
# this raises unknown method "b", because b is a member of c as an object, not as a class
# o b
Saturday, December 16, 2023
firefox places.sqlite tags select
copy it into a fixed width character terminal for better view
firefox places.sqlite contains all bookmarks
sqlite3 places.sqlite "select sql from sqlite_master
where tbl_name = 'moz_bookmarks' and type = 'table';"
each bookmark has a base entry in moz_bookmarks
where it has the title and the fk that links to moz_places.id
and it has an entry with the same fk for each tag
moz_places has an entry with id = moz_bookmarks.fk that holds the URL
and it has a title that usually is the same with that in moz_bookmarks
moz_bookmarks.title is more about the page, moz_places.title is more about the site
there is no id = 0 record in moz_bookmarks or moz_places
the id = 0 record is referred to signal the root of the reference chain
in moz_bookmarks:
a bookmark has:
one entry that contains its title and it's followed by
entries with the same fk
that link through their parent to one tag of that bookmark each
all those entries with the same fk have a null title, since this query returns no results:
select id, title from moz_bookmarks m where
(select parent from moz_bookmarks where id = m.parent) = 4 and
-- this selects entries that refer tags
-- because entries referred by their parent have parent = 4
title not null;
type is 1 for bookmarks and their links to tags
position does not appear to be important, maybe it refers to the position in the displayed list
keyword_id is null
folder_type is null
fields after title are not relevant for the bookmarks -- tags relationship
tags have:
title is the name of the tag
parent = 4, which is the id of the Tags folder
type = 2
fk = null
a folder has:
title is the name of the folder
parent is the id of the parent folder
the root folder is the Bookmarks Menu with id = 2
type = 2
fk = null
to select all tags of a bookmark:
parent = 4 eliminates the folder referred in the bookmark entry that contains the title
if there is more than one bookmark with that exact title then
fk = (select ...) only fits the first result
but if you replace that '=' with 'in', then all tags of all those bookmarks are listed in one column
tags used more than once by different bookmarks will appear only once in the list
sqlite> select title from moz_bookmarks where id in (select parent from moz_bookmarks where fk = (select fk from moz_bookmarks where title = 'David Icke – The Answer – full length interview. Direct no-email version – starts at 6.46 and please share with everyone you can to bypass censorship – David Icke')) and parent = 4;
or:
parent = 4 eliminates the folder referred in the bookmark entry that contains the title
verified
if there is more than one bookmark with that exact title then
all tags of all those bookmarks are listed in one column and
tags used more than once by different bookmarks will appear more than once in the list
sqlite> select m1.title from moz_bookmarks as m1, moz_bookmarks as m2, moz_bookmarks as m3 where m3.title = 'David Icke – The Answer – full length interview. Direct no-email version – starts at 6.46 and please share with everyone you can to bypass censorship – David Icke' and m2.fk = m3.fk and m1.id = m2.parent and m1.parent = 4;
the first version is ten times faster than the second version
time sqlite3 places.sqlite "select title from moz_bookmarks where id in (select parent from moz_bookmarks where fk = (select fk from moz_bookmarks where title = 'David Icke – The Answer – full length interview. Direct no-email version – starts at 6.46 and please share with everyone you can to bypass censorship – David Icke')) and parent = 4;"
NWO
David Icke
politics
news
video
continue
1:00:00 continue
real 0m0.012s
user 0m0.011s
sys 0m0.001s
time sqlite3 places.sqlite "select m1.title from moz_bookmarks as m1, moz_bookmarks as m2, moz_bookmarks as m3 where m3.title = 'David Icke – The Answer – full length interview. Direct no-email version – starts at 6.46 and please share with everyone you can to bypass censorship – David Icke' and m2.fk = m3.fk and m1.id = m2.parent and m1.parent = 4;"
NWO
David Icke
politics
news
video
continue
1:00:00 continue
real 0m0.183s
user 0m0.077s
sys 0m0.105s
to select all bookmarks that have a specific tag:
title is not null only for the bookmark entry that contains the title.
we know this because this returns no lines:
the subquery selects the id's of all tags
the outer query selects all references to all tags that have not null titles
sqlite> select title from moz_bookmarks where
parent in (select id from moz_bookmarks where parent = 4) and title is not null;
sqlite> select id, title from moz_bookmarks where fk in (select fk from moz_bookmarks where parent = (select id from moz_bookmarks where parent = 4 and title = '1984')) and title is not null;
sqlite> select m1.id, m1.title from moz_bookmarks m1, moz_bookmarks m2, moz_bookmarks m3 where m3.parent = 4 and m3.title = 'David Icke' and m3.id = m2.parent and m2.fk = m1.fk and m1.title not null;
select m1.id, m1.title, count(*) from moz_bookmarks m1, moz_bookmarks m2, moz_bookmarks m3 where m3.parent = 4 and m3.title = 'David Icke' and m3.id = m2.parent and m2.fk = m1.fk and m1.title not null;
1776|What David Icke Said in 1991, Dr Michio Kaku Confirms in 2008 - YouTube|443
time sqlite3 places.sqlite "select id, title from moz_bookmarks where fk in (select fk from moz_bookmarks where parent = (select id from moz_bookmarks where parent = 4 and title = 'David Icke')) and title is not null;"
real 0m0.011s
user 0m0.004s
sys 0m0.008s
time sqlite3 places.sqlite "select m1.id, m1.title from moz_bookmarks m1, moz_bookmarks m2, moz_bookmarks m3 where m3.parent = 4 and m3.title = 'David Icke' and m3.id = m2.parent and m2.fk = m1.fk and m1.title not null;"
real 0m0.012s
user 0m0.008s
sys 0m0.004s
to update a tag in all bookmarks
verified
you can use Firefox > Library window
find oldtag in Search Bookmarks
select all found bookmarks
edit oldtag into newtag in Tags
press Enter
or
verified
sqlite:
you need to update the parent of all entries that refer that bookmark:
the new tag must be already defined
there should be no entries that have both the old tag and the new tag at the same time
both these conditions can be easily configured in Firefox > Library window
sqlite3> update moz_bookmarks set parent = (select id from moz_bookmarks where title = 'new tag' and parent = 4) where id in (select id from moz_bookmarks where parent = (select id from moz_bookmarks where title = 'old tag' and parent = 4));
Monday, November 7, 2022
Python Metaclasses
Copy it to a fixed width font terminal for a good reading.
This is what I gathered and guessed about Python metaclasses from the following pages:
https://mail.python.org/pipermail/python-3000/2006-December/005030.html
https://www.geeksforgeeks.org/python-metaclasses/
https://realpython.com/python-metaclasses/
https://www.geeksforgeeks.org/metaprogramming-metaclasses-python/
Python is a work in progress and so is my understanding of this programming language.
dynamically create a new class:
'name' = type('name', 'bases', 'dict')
differs from class 'name''bases'
by the fact that the name, bases and attributes of the newly created class are decided at runtime
'name' - the name of the new class, memorized in 'name'. __name__
'bases' - a tuple of the base classes from which the class inherits, memorized in 'name'.__bases__
'dict' - a namespace dictionary containing definitions for the class body, memorized in 'name'.__dict__
metaclasses configure classes when they are created
this is different from inheritance
all classes inherit the class 'object' or its subclasses
all classes are configured by the metaclass 'type' or a subclass of it
(maybe it has to be a direct subclass)
'myclass'.__bases__, 'myclass'.__base__ - show directly inherited classes
'myclass'.__class__, type('myclass') - show the metaclass that configured 'myclass'
>>> type.__bases__
(<class 'object'>,)
>>> type(type)
<class 'type'>
>>> int.__bases__
(<class 'object'>,)
>>> type(int)
<class 'type'>
>>> type(7)
<class 'int'>
objects have a __call__() method
which calls the __new__() and __init__() methods
__new__() creates the new object and returns it
'cls' in __new__() is the new object
__init__() initializes the newly created object passed as a parameter
'self' in __init__() is the new object
these methods can be overridden to configure the newly created object
help(type.__call__), help(object.__call__)
help(type) has a __call__ method, but help(object) does not
metaclasses are a “solution in search of a problem”
examples of metaclass usage
$ cat meta.py
# MyMeta is an instance of type and a subclass of type
# MyClass is an instance of MyMeta and a subclass of object
def prints():
print(' type(MyMeta) =', type(MyMeta), '\n type(MyClass) =', type(MyClass), '\n')
class MyClass:
pass
# dynamic creation (definition) of MyClass, parameters can be decided at runtime
MyClass = type('MyClass', (object,), {})
class MyMeta(type):
def __new__(cls, cls_name, bases, attrib):
print('>> MyMeta.__new__()')
return super(MyMeta, cls).__new__(cls, cls_name, bases, attrib)
# super() arguments are not required
print('\nMyMeta.__bases__ =', MyMeta.__bases__, '\nMyMeta.__class__ =', MyMeta.__class__, '\n')
class MyClass(metaclass = MyMeta):
pass
prints()
MyClass = MyMeta('MyClass', (object, ), {})
prints()
# MyClass = type('MyClass', (object, metaclass = MyMeta,), {})
# invalid syntax ^
# so type() cannot create a class of a MyMeta type
# prints()
# MyClass = MyMeta()
# new() missing 3 required positional arguments: 'cls_name', 'bases', and 'attrib'
# prints()
def new(cls, cls_name, bases, attrib):
print('>> new()')
return super(MyMeta, cls).__new__(cls, cls_name, bases, attrib)
# super() arguments are required
MyMeta = type('MyMeta', (type,), {'__new__' : new})
class MyClass(metaclass = MyMeta):
pass
prints()
$ python meta.py
MyMeta.__bases__ = (<class 'type'>,)
MyMeta.__class__ = <class 'type'>
>> MyMeta.__new__()
type(MyMeta) = <class 'type'>
type(MyClass) = <class '__main__.MyMeta'>
>> MyMeta.__new__()
type(MyMeta) = <class 'type'>
type(MyClass) = <class '__main__.MyMeta'>
>> new()
type(MyMeta) = <class 'type'>
type(MyClass) = <class '__main__.MyMeta'>
$ cat meta.py
class Meta(type):
def __new__(cls, name, bases, dict):
x = super().__new__(cls, name, bases, dict)
x.attr = 100
return x
class Foo(metaclass=Meta):
pass
print('Foo.attr =', Foo.attr)
$ python meta.py
Foo.attr = 100
$ cat meta.py
class Meta(type):
def __init__(cls, name, bases, dict):
cls.attr = 100
class X(metaclass=Meta):
pass
print('X.attr =', X.attr)
$ python meta.py
X.attr = 100
Friday, December 8, 2017
zoom pdf for printing
Start pdfedit.
If the pdf file is uneditable then Tools > Delinearize it.
Use Page > Set page transformation matrix to find the transformation you want. You need to check Page transformation matrix description > Select which transformations to use. This only changes one page.
The programming language used is the qt script language, ECMAScript, almost identical to JavaScript. The API functions are listed in Help > Help.
Save this https://sourceforge.net/p/pdfedit/mailman/pdfedit-support/thread/20080707173451.GG4157%40dhcp35.suse.cz/ inspired script in ./zoom.qs:
f = loadPdf("myfile.pdf");
pg = f.getFirstPage();
pg.setTransformMatrix([1.4,0,0,1.4,-130,-180]);
while (f.hasNextPage(pg)) {
pg = f.getNextPage(pg);
pg.setTransformMatrix([1.4,0,0,1.4,-130,-180]); }
f.save();
f.unloadPdf();
Modify the arguments of setTransformMatrix into your desired ones found using Page > Set page transformation matrix. Parameters 1 and 4 should not be 0, that would make the text invisible.
Copy your pdf file to be processed in ./myfile.pdf.
Issue:
$ pdfedit -s zoom.qs
You can print with:
$ lp -o media-size=a4,fit-to-page -P 1 myfile.pdf
It would be nice to calculate the transformation matrix using the printer acceptable minimal margins, but I don't know how to get the current margins of the document.
Tuesday, October 20, 2015
archlinux pacman - an introduction
pacman saves to disk a list of packages available in the repository. This list is not automatically updated (refreshed). (The list is a.k.a. repository databases and the update of the list is a.k.a. synchronizing those databases.) The list can be refreshed using pacman -Sy. pacman -Syy refreshes the list even if it appears to be up to date. I don't know the effect of pacman -Syy when the pacman list is newer than that of the mirror, for example as a result of falling back to a different not yet updated mirror.
When the list is outdated it is possible that packages to be installed with pacman -S package are not available.
When pacman installs one package with pacman -S package it takes care that all its correct version dependencies are installed but it does not verify that dependencies of other packages are not broken by such updates. If the list has been updated but packages not, then this command could make the system unusable. That is why the list should only be updated together with all packages in the system with pacman -Syu and you should never run pacman -Sy or pacman -Sy package.