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 | |
/** | |
* Returns current time in nanoseconds, which is a bigint (int64) and thus can be used as a primary key in SQLite. | |
*/ | |
function get_sqlite_bigint_id_time_based(): int | |
{ | |
// The challenge here is that: | |
// - microtime() returns current time accurate to the nearest microsecond, while we need it to nanosecond | |
// - hrtime() returns a very precise time accurate to the nanosecond and is recommended for performance measurements, |
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
drop function if exists maybe_to_natural_number; | |
create or replace function maybe_to_natural_number(str text) returns integer | |
language plpgsql immutable leakproof returns null on null input parallel safe as $$ | |
begin | |
if regexp_match(str, '^\d+$') is null then | |
return null; | |
end if; | |
return str::int8; | |
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
import {useEffect, useState} from "react"; | |
import trim from 'lodash/trim'; | |
export default function useAutofocus() { | |
const [querySelector, setQuerySelector] = useState(null); | |
// Either a non-empty string OR null | |
let normalizedQuerySelector = querySelector; | |
if (typeof normalizedQuerySelector === 'string') { |
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
import $ from 'jquery'; | |
export const IDLE_EVENT_NAME = 'idleTimeSeconds'; | |
/** | |
* How often an 'idleTimeSeconds' event is fired on the document instance. | |
* | |
* @type {number} | |
*/ | |
const IDLE_EVENT_RATE_SECONDS = 10; |
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 | |
public static function sanitizeRelativeRedirectUrl($url): ?string | |
{ | |
$res = parse_url($url); | |
// On seriously malformed URLs, parse_url() may return FALSE | |
if (!is_array($res)) { | |
return null; | |
} |
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
# - docker/pgbadger/Dockerfile | |
# - Makefile | |
FROM perl:5.32.1 | |
LABEL "com.mycompany.container"="pgbadger" | |
ARG PGBADGER_VERSION=11.5 | |
WORKDIR /pgbadger | |
COPY pgbadger-${PGBADGER_VERSION}.tar.gz /pgbadger/ |
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 | |
/******** TEST 1 ********/ | |
// SELECT * FROM email WHERE id = 100 | |
$fetched = [ | |
'id' => 100, | |
'subject' => 'Welcome!' | |
]; |
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
CREATE OR REPLACE FUNCTION no_gaps_time_ranges( | |
in start_date timestamptz, | |
in interval_len_sec bigint, | |
in num_intervals bigint | |
) | |
RETURNS TABLE (date_from timestamptz, date_to timestamptz) | |
LANGUAGE plpgsql | |
IMMUTABLE | |
AS $function$ | |
DECLARE |
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 | |
/** | |
* Sanity-checks PHP code that was already parsed into AST with using php-parser library. | |
* | |
* The AST must be represented as a multi-level array with scalar values. | |
* | |
* Example usage: | |
* | |
* <code> |
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 | |
namespace Toptal\SpeedCoding\Controller\Api; | |
use Exception; | |
use Respect\Validation\Validator as v; | |
use Toptal\SpeedCoding\Api\ApiResult; | |
use Toptal\SpeedCoding\Auth; | |
use Toptal\SpeedCoding\Challenge\EmailProcessor; | |
use Toptal\SpeedCoding\Challenge\TaskResultComparator; |
NewerOlder