dinsdag 25 mei 2021

Waarom kost vermenigvuldigen minder clockcycles dan delen?

De oorspronkelijk Pentium CPU kon in 10 clockcycles een multiply doen, maar had voor een division 41 clockcycles nodig. Waarom is dat?

Als je kijkt naar onze schoolmethoden voor het vermenigvuldigen en delen, dan kun je het antwoord raden.

Vermenigvuldigen doen we namelijk door per cijfer een vermenigvuldiging te doen en de berekende getallen uiteindelijk op te tellen. De vermenigvuldigingsstappen zijn parallel uit te voeren. De CPU doet die stappen dus ook parallel.

Het delen doet de CPU op een soortgelijke methode als onze staartdeling. Die stappen kun je echter niet parallel uitvoeren, want de volgende stap is afhankelijk van de vorige. De CPU kan het probleem dus niet makkelijk parallel oplossen. Daarom duurt het langer.

Je ziet het terug in de logische diagrammen voor multiply en division. Op CPU's die geen float division kunnen doen kun je je wenden tot benaderingen.

woensdag 14 april 2021

Postgresql paste

create or replace function create_partitions()
returns void
language plpgsql
as $$
declare
  c_date_format constant varchar(8) := 'yyyymmdd';
  meuk varchar(255);
begin
  for r in (select tablename from pg_tables where tablename like 'history_%' and substring (tablename from '........$' < to_char(now() + '-7 day', c_date_format))
  loop
     meuk := r.tablename;
     raise notice '%', meuk;
     execute format ('drop table %1$s', r.tablename);
  end loop;
end;
$$;


do $$
declare
distance float;
begin
distance := (select ST_Distance(ST_Transform(old."location"::geometry, 3857), ST_Transform(new."location"::geometry, 3857)));
if (distance > 4.0) then
   perform create_partitions();
end if;
end;
$$


select create_partitions()

select cron.schedule('10 2 * * *', $$select create_partitions()$$);
-- iedere 5 minuten is: '*/5 * * * *'
select * from cron.job
select cron.unschedule(jobid) from cron.job where jobid = {jobid getal}
select * from history where date > TIMESTAMP 'yesterday'

maandag 22 maart 2021

ssl binding on port on windows

 On Windows, it is possible to bind a SSL certificate to a port.

netsh http show sslcert

netsh http add sslcert ipport=0.0.0.0:4000 certhash=casda... appid={123123..123123}

netsh http delete sslcert ipport=0.0.0.0:4000

The appid can be randomly choosen, because it is only a id to identify the entry.
The certhash is the thumbprint found in the certificate.

maandag 22 februari 2021

pg_dump remote server tables

Je moet eerst even in pgpass.conf in %APPDATA% aanmaken.

Dus:
cd %APPDATA%
notepad pgpass.conf

Inhoud pgpass.conf

dnsentryname.local:5432:*:user:password
localhost:5432:*:postgres:password

Vervolgens:

pg_dump -h ipadres --column-inserts --data-only -t tablename -t othertablename --username=username --file=output.dmp --dbname=db -w

maandag 1 februari 2021

SQL: Update using a select

begin transaction;

update targettable
set "location" = CAST(ST_SetSRID( ST_Point(subquery.longitude_::float, subquery.latitude_::float), 4326) AS geography)
from (
select id, ajsonb -> 'location' as location_, ajsonb->'location'->'latitude' as latitude_, ajsonb->'location'->'longitude' as longitude_
from targettable) as subquery
where targettable.id = subquery.id
and subquery.location_ is not null

commit;
--rollback;

woensdag 20 januari 2021

Door welk process is poort 80 in gebruik

 netstat -aon | findstr :80

 If you would like to free the port, go to Task Manager, sort by pid and close those processes.

-a displays all connections and listening ports.
-o displays the owning process ID associated with each connection.
-n displays addresses and port numbers in numerical form.

Nginx restart

nginx staat meestal in /etc/nginx

Herstarten:
sudo su
systemctl reload nginx

of

systemctl restart nginx