This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// you can write to stdout for debugging purposes, e.g. | |
// print "this is a debug message\n"; | |
// difference |(A[0] + A[1] + ... + A[P − 1]) − (A[P] + A[P + 1] + ... + A[N − 1])| | |
function solution($A) { | |
// write your code in PHP5.5 | |
$n = count($A); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function solution($A) { | |
// write your code in PHP5.5 | |
$count = count($A); | |
if ($count < 1) return 1; | |
$end = $count + 1; | |
$ordered = range(1, $end); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// you can write to stdout for debugging purposes, e.g. | |
// print "this is a debug message\n"; | |
function solution($A) { | |
$a_count_values = array_count_values($A); | |
$values = array_keys($a_count_values, 1); | |
if (is_array($values)) | |
return $values[0]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// you can write to stdout for debugging purposes, e.g. | |
// print "this is a debug message\n"; | |
function solution($X, $Y, $D) { | |
// write your code in PHP5.5 | |
if ($X == $Y) return 0; | |
$jumps = intval(ceil(($Y - $X) / $D)); | |
return $jumps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function solution($N) { | |
//print "N: $N\n"; | |
// write your code in PHP5.5 | |
$bin = base_convert($N, 10, 2); | |
$sbin = trim((string) $bin); | |
//print "sbin: $sbin\n"; | |
$any_zero = strpos($sbin, '0'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// you can write to stdout for debugging purposes, e.g. | |
// print "this is a debug message\n"; | |
function solution($A, $K) { | |
// write your code in PHP5.5 | |
$count = count($A); | |
$length_offset = $count - $K; | |
if ($length_offset < 0) { | |
$quo = intval($K / $count); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Function: desacentua(character varying) | |
-- DROP FUNCTION desacentua(character varying); | |
CREATE OR REPLACE FUNCTION desacentua(texto character varying) | |
RETURNS character varying AS | |
$BODY$ | |
SELECT translate( $1,'ÁÉÍÓÚÀÈÌÒÙÃÕÂÊÎÔÛÄËÏÖÜÇÑáéíóúàèìòùãõâêîôûäëïöüçñ','AEIOUAEIOUAOAEIOUAEIOUCNaeiouaeiouaoaeiouaeioucn') | |
$BODY$ | |
LANGUAGE sql IMMUTABLE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select locktype, database, relation,page,tuple,virtualxid,transactionid,classid,objid,objsubid,virtualtransaction,pid | |
, mode,granted,datname,datdba,datctype,datistemplate,datallowconn,datconnlimit,datlastsysoid,datfrozenxid,dattablespace,datacl | |
, c.relname as table_name | |
from pg_locks l | |
join pg_database d | |
on d.oid = l.database | |
join pg_class c | |
on c.oid = l.relation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT d.datname, c.relname | |
, pg_size_pretty(count(*) * 8192) as buffered | |
, round(100.0 * count(*) / ( SELECT setting FROM pg_settings WHERE name='shared_buffers')::integer,1) AS buffers_percent | |
, round(100.0 * count(*) * 8192 / pg_relation_size(c.oid),1) AS percent_of_relation | |
FROM pg_class c | |
INNER JOIN pg_buffercache b ON b.relfilenode = c.relfilenode | |
INNER JOIN pg_database d ON (b.reldatabase = d.oid) | |
WHERE pg_relation_size(c.oid) > 0 | |
GROUP BY c.oid, d.datname, c.relname | |
ORDER BY 4 DESC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
user=$1 | |
if [ "$user" != "" ]; then | |
echo "Starting recovering privileges" | |
echo "1. Recovering /home/${user} ${user}:${user}" | |
chown -R ${user}:${user} /home/${user} | |
echo "2. Recovering /home/${user}/etc ${user}:mail" | |
chown -R ${user}:mail /home/${user}/etc | |
echo "3. Recovering /home/${user}/.htpasswds ${user}:nobody" |