Skip to content

Instantly share code, notes, and snippets.

View rafaelbernard's full-sized avatar

Rafael Bernard Araújo rafaelbernard

View GitHub Profile

Keybase proof

I hereby claim:

  • I am rafaelbernard on github.
  • I am rafaelbernard (https://keybase.io/rafaelbernard) on keybase.
  • I have a public key ASAhtOpKuJNu6BEpS5Me9dYSddb-YVyO2NZY9sGpZpwSyQo

To claim this, I am signing this object:

// original clone adapted from https://dev.to/samanthaming/how-to-deep-clone-an-array-in-javascript-3cig
// and the example at http://jsben.ch/q2ez1
//
// Deep clone written by @obscurerichard https://github.com/obscurerichard
const clone = (items) => items.map(item => Array.isArray(item) ? clone(item) : item);
// ✅ Nested array NOT affected
var src = [1, [2], 3];
var dest = clone(src)
// Make some changes
gsettings set org.gnome.desktop.input-sources xkb-options "['caps:escape']"
@rafaelbernard
rafaelbernard / remap caps to escape - during session.sh
Created April 17, 2019 18:35
remap caps to escape - during session
setxkbmap -option caps:escape
@rafaelbernard
rafaelbernard / index_all_columns_in_schema.sql
Last active November 2, 2017 20:20
Indexing all columns from all tables in schema (development purpose)
SELECT 'CREATE INDEX ' || table_name || '_' || column_name || ' ON ' || table_schema || '.' || table_name || ' ("' || column_name || '");'
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name != 'pg_stat_statements'
AND table_name != 'pg_buffercache';
@rafaelbernard
rafaelbernard / pg_schemas_size.sql
Created March 17, 2016 22:05
PostgreSQL schema sizes
WITH schema_size AS (
SELECT
tab.table_catalog AS database_name,
tab.table_schema AS schema_name,
tab.table_name,
pg_total_relation_size(table_schema || '.' || tab.table_name) AS table_size_total,
pg_relation_size(table_schema || '.' || tab.table_name) AS table_size
FROM information_schema.tables tab
WHERE table_schema NOT IN ('pg_catalog', 'information_schema')
), pretty_size AS (
@rafaelbernard
rafaelbernard / wp-db.php
Created March 1, 2016 20:31
Fix at wp-db.php - PG4WP - PG9.5
<?php
public function set_sql_mode( $modes = array() ) {
if ( empty( $modes ) ) {
/*
if ( $this->use_mysqli ) {
$res = mysqli_query( $this->dbh, 'SELECT @@SESSION.sql_mode' );
} else {
$res = mysql_query( 'SELECT @@SESSION.sql_mode', $this->dbh );
}*/
$res = '';
@rafaelbernard
rafaelbernard / driver_pgsql.php
Created March 1, 2016 20:28
Show Full Column - PG4WP
<?php
# at pg4wp_rewrite
# right after `Fix tables listing`
// Rewriting SHOW FULL COLUMN
elseif( 0 === strpos($sql, 'SHOW FULL COLUMN'))
{
$logto = 'SHOWFULL';
$sql = str_replace( 'SHOW FULL COLUMNS FROM ', 'SELECT column_name FROM information_schema.columns WHERE table_name = ', $sql);
$sql = str_replace( '`', "'", $sql );
@rafaelbernard
rafaelbernard / pg-deadlock_info.sql
Last active January 27, 2016 21:12
PostgreSQL - Deadlock Info
SELECT w.locktype AS waiting_locktype,w.relation::regclass AS waiting_table,w.transactionid
, substr(w_stm.query,1,20) AS waiting_query
, w.mode AS waiting_mode,w.pid AS waiting_pid,other.locktype AS other_locktype
,other.relation::regclass AS other_table,other_stm.query AS other_query
,other.mode AS other_mode,other.pid AS other_pid,other.granted AS other_granted
FROM pg_catalog.pg_locks AS w
JOIN pg_catalog.pg_stat_activity AS w_stm ON (w_stm.pid = w.pid)
JOIN pg_catalog.pg_locks AS other
ON ((w.database = other.database AND w.relation = other.relation) OR w.transactionid = other.transactionid)
<?php
// you can write to stdout for debugging purposes, e.g.
// print "this is a debug message\n";
function solution($A) {
// write your code in PHP5.5
$A = array_unique($A);
$count = count($A);
if ($count < 1) return 1;