Thursday, November 24, 2016
Tuesday, November 15, 2016
Monday, November 7, 2016
PostgreSQL: remove all Bucardo triggers from a schema
do
$$
declare
_row record;
_query text;
begin
for _row in SELECT tgname, tgrelid::regclass as table_name FROM pg_trigger where tgname ~ 'bucardo' and tgrelid::regclass::text ~ 'shared_db' loop
_query := format('drop trigger %s on %s', _row.tgname, _row.table_name);
raise notice '%', _query;
execute _query;
end loop;
end
$$;
Labels:
postgresql
Sunday, November 6, 2016
Google Drive web hosting is shutting down
An alternative is to use Google Firebase.
Create new project on Firebase console : Select Storage : Import your files : Edit your template in Blogger : Copy the Firebase URL of the file you want to use in Blogger : Replace your Google Drive URL : Save your template and you will get an error about token : To workaround the token issue, go to the Google URL shortener, and paste the Firebase URL : Copy the short URL : Replace the Firebase URL with the shortened one in Blogger : [2021-09-05 Edit]
syntaxhighlighter has stopped working for some time now. The Web Dev Tools console in FF shows the following error:
So, it seems as if something changed either in the Google shortener behavior, or maybe in FF itself.
Let's try to re-use the original URLs instead of the shortened ones. As the Blogspot UI changed, you now need to go to "Themes", and click the "Customize" button. Then select the "Edit HTML" menu item. But using, e.g. "https://firebasestorage.googleapis.com/v0/b/syntaxhighlighter-2b128.appspot.com/o/scripts%2FshBrushPhp.js?alt=media&token=1533c104-e33b-43fa-b299-c2dd8c8f81ab" instead of "https://goo.gl/kQztrh" brings back the old error: which is actually caused by the use of "&token=" instead of "&token=".
Once all the URLs have been substituted and the "&token=" occurences replaced, we're back in tracks :)
Create new project on Firebase console : Select Storage : Import your files : Edit your template in Blogger : Copy the Firebase URL of the file you want to use in Blogger : Replace your Google Drive URL : Save your template and you will get an error about token : To workaround the token issue, go to the Google URL shortener, and paste the Firebase URL : Copy the short URL : Replace the Firebase URL with the shortened one in Blogger : [2021-09-05 Edit]
syntaxhighlighter has stopped working for some time now. The Web Dev Tools console in FF shows the following error:
The resource from “https://goo.gl/kQztrh” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
So, it seems as if something changed either in the Google shortener behavior, or maybe in FF itself.
Let's try to re-use the original URLs instead of the shortened ones. As the Blogspot UI changed, you now need to go to "Themes", and click the "Customize" button. Then select the "Edit HTML" menu item. But using, e.g. "https://firebasestorage.googleapis.com/v0/b/syntaxhighlighter-2b128.appspot.com/o/scripts%2FshBrushPhp.js?alt=media&token=1533c104-e33b-43fa-b299-c2dd8c8f81ab" instead of "https://goo.gl/kQztrh" brings back the old error: which is actually caused by the use of "&token=" instead of "&token=".
Once all the URLs have been substituted and the "&token=" occurences replaced, we're back in tracks :)
Thursday, November 3, 2016
PostgreSQL: Find a table columns type
From http://dba.stackexchange.com/questions/75015/query-to-return-output-column-names-and-data-types-of-a-query-table-or-view:
SELECT attname, format_type(atttypid, atttypmod) AS type
FROM pg_attribute
WHERE attrelid = 'foo'::regclass
AND attnum > 0
AND NOT attisdropped
ORDER BY attnum;
Labels:
postgresql
Sunday, October 2, 2016
OSX: Installing Sierra over El Capitan
Information found here:
- Direct Update to macOS Sierra using Clover
- NVIDIA GeForce GTX 260 + Sierra
- Sierra Desktop/Realtek AppleHDA Audio
Install Sierra:
- Update Clover from Clover Configurator, then reboot
- Mount EFI partition like in OSX: use Clover Configurator
- Copy kext to inject from 10.11
cp -R /Volumes/EFI/EFI/CLOVER/kexts/10.11/* /Volumes/EFI/EFI/CLOVER/kexts/Other- Copy NVDAStartup.kext from El Capitan, to avoid a kernel panic on Sierra install
cp -R /Volumes/osx/System/Library/Extensions/NVDAStartup.kext /Volumes/EFI/EFI/CLOVER/kexts/Other- Download Sierra from Mac App Store
- Reboot and choose Boot macOS Install option. Before running the install, press spacebar and tick Without cache + Inject kexts. This will install and start Sierra.
- When Sierra up, re-mount EFI partition
- Remove Sierra NVDAStartup.kext
rm -R /Volumes/osx/System/Library/Extensions/NVDAStartup.kext- Copy NVDAStartup.kext from EFI partition to Desktop
- Install NVDAStartup.kext with KextBeast
- Reboot
Then install audio drivers:
- Re-mount EFI partition
- Run audio_cloverALC command to install Toleda AppleHDA
- Reboot, et voila
Thursday, July 28, 2016
Emacs: disable auto-indent of new lines
This is a new feature from Emacs 24.4.
To revert to the old behavior, you need to disable electric-indent-mode.
To revert to the old behavior, you need to disable electric-indent-mode.
(when (fboundp 'electric-indent-mode) (electric-indent-mode -1))See http://emacs.stackexchange.com/questions/5939/how-to-disable-auto-indentation-of-new-lines
Monday, July 11, 2016
CentOS 6 / wkhtmltopdf: extra spaces added in strings when generating PDF from HTML
The tip on this page solved it for me:
sudo wget http://pastebin.com/raw.php?i=AmfYN3er -O /etc/fonts/conf.d/10-wkhtmltopdf.conf
Labels:
centos,
wkhtmltopdf
Wednesday, June 1, 2016
grep extract
Suppose you want 150 lines after the line containing "2016-05-31 11:06:39.265" from file postgresql-31.csv:
grep -A150 '2016-05-31 11:06:39.265' postgresql-31.csv > /tmp/postgresql-31.csv.extract
Tuesday, May 31, 2016
PostgreSQL: pgq
Ticker uses following rules by default:
Show pgq status
- Batch is made when there are more than 500 new events (ticker_max_count)
- Batch is made when there are any number of new events and 3 seconds have passed since last batch (ticker_max_lag)
- Batch is made if there are no new events, but 1 minute has passed since last batch (ticker_idle_period)
Show pgq status
crmmbqt=# select * from pgq.get_consumer_info() where queue_name = 'londiste3_queue';
┌─────────────────┬───────────────────┬─────────────────┬─────────────────┬───────────┬───────────────┬───────────┬────────────────┐
│ queue_name │ consumer_name │ lag │ last_seen │ last_tick │ current_batch │ next_tick │ pending_events │
├─────────────────┼───────────────────┼─────────────────┼─────────────────┼───────────┼───────────────┼───────────┼────────────────┤
│ londiste3_queue │ .global_watermark │ 02:12:20.5365 │ 00:01:16.560372 │ 14376 │ NULL │ NULL │ 13333 │
│ londiste3_queue │ londiste3_slave │ 00:04:48.404077 │ 00:00:00.014105 │ 14630 │ 5070555 │ 14631 │ 252 │
│ londiste3_queue │ .slave.watermark │ 02:09:20.494378 │ 00:00:07.537384 │ 14381 │ NULL │ NULL │ 10910 │
└─────────────────┴───────────────────┴─────────────────┴─────────────────┴───────────┴───────────────┴───────────┴────────────────┘
(3 rows)
Labels:
postgresql
PostgreSQL: deleting duplicates example
delete from resource_db.ht_sim_party where sim_party_id in ( select sim_party_id from ( select sim_party_id, sim_id, party_id, rnum from ( select distinct sim_party_id, sim_id, party_id, row_number() over (partition by party_id) as rnum from resource_db.ht_sim_party where ht_sim_party.from_date <= localtimestamp(0) and localtimestamp(0) < ht_sim_party.to_date and '2016-05-30' < ht_sim_party.from_date ) as foo where rnum > 1 ) as bar )
Labels:
postgresql
Friday, May 27, 2016
PostgreSQL: who is locking my table?
See http://stackoverflow.com/questions/17605511/why-would-alter-table-drop-constraint-on-an-empty-table-take-a-long-time
select c.relname, l.*, psa.* from pg_locks l inner join pg_stat_activity psa ON (psa.pid = l.pid) left outer join pg_class c ON (l.relation = c.oid) where l.relation = 'prov_db.ht_request_status'::regclass;
Labels:
postgresql
Sunday, May 15, 2016
Saturday, May 14, 2016
Thursday, May 12, 2016
PostgreSQL: Passing an array of record to a stored procedure
create type my_type as (val1 int, val2 int);
create function my_function(arr my_type[]) returns text language plpgsql as
$$
begin
return arr::text;
end;
$$;
select my_function(array[row(1,2)::my_type, row(3,4)::my_type]);
my_function
-------------------
{"(1,2)","(3,4)"}
(1 row)
Labels:
postgresql
PostgreSQL: join opposite
select t1.* from table1 t1 left join table2 t2 on t1.id=t2.id where t2.id is null;
Labels:
postgresql
Tuesday, May 3, 2016
PostgreSQL: select ip range with max masklen
with
radius_cdr_pdp(sgsn_address, cdr_src_id) as (
values ('212.183.144.0'::inet, 1), ('212.183.144.0'::inet, 2), (null, 3)
),
dt_ip_range(ip_range) as (
values ('212.183.144.0/16'::inet), ('212.183.144.0/24'::inet), ('212.182.0.0/16'::inet), (null)
),
radius_cdr_pdp_max as (
select max(masklen(dt_ip_range.ip_range)) as max_masklen, cdr_src_id
from radius_cdr_pdp
left join dt_ip_range on radius_cdr_pdp.sgsn_address <<= dt_ip_range.ip_range
group by cdr_src_id
)
select radius_cdr_pdp.sgsn_address, dt_ip_range.ip_range, radius_cdr_pdp.cdr_src_id, radius_cdr_pdp_max.max_masklen
from radius_cdr_pdp
join radius_cdr_pdp_max using (cdr_src_id)
left join dt_ip_range
on radius_cdr_pdp.sgsn_address <<= dt_ip_range.ip_range
and radius_cdr_pdp_max.max_masklen = masklen(dt_ip_range.ip_range);
Labels:
postgresql
PostgreSQL: Create temp table from values
WITH temp (k,v) AS (VALUES (0,-9999), (1, 100)) SELECT * FROM temp;
Labels:
postgresql
Subscribe to:
Posts (Atom)












