Skip to content

Instantly share code, notes, and snippets.

Nam Le namcoder

Block or report user

Report or block namcoder

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@namcoder
namcoder / postgresql_id.sql
Created Aug 6, 2019 — forked from yohang88/postgresql_id.sql
PostgreSQL Better ID & UUID Generator
View postgresql_id.sql
create schema shard_1;
create sequence shard_1.global_id_sequence;
CREATE OR REPLACE FUNCTION shard_1.id_generator(OUT result bigint) AS $$
DECLARE
our_epoch bigint := 1314220021721;
seq_id bigint;
now_millis bigint;
-- the id of this DB shard, must be set for each
-- schema shard you have - you could pass this as a parameter too
View test-php-basic-auth.php
<?php
function require_auth() {
$AUTH_USER = 'admin';
$AUTH_PASS = 'admin';
header('Cache-Control: no-cache, must-revalidate, max-age=0');
$has_supplied_credentials = !(empty($_SERVER['PHP_AUTH_USER']) && empty($_SERVER['PHP_AUTH_PW']));
$is_not_authenticated = (
!$has_supplied_credentials ||
$_SERVER['PHP_AUTH_USER'] != $AUTH_USER ||
$_SERVER['PHP_AUTH_PW'] != $AUTH_PASS
@namcoder
namcoder / median.js
Created Aug 30, 2018 — forked from caseyjustus/median.js
calculate the median of an array with javascript
View median.js
function median(values) {
values.sort( function(a,b) {return a - b;} );
var half = Math.floor(values.length/2);
if(values.length % 2)
return values[half];
else
return (values[half-1] + values[half]) / 2.0;
@namcoder
namcoder / number-pad-zero.js
Created Jun 24, 2018 — forked from endel/number-pad-zero.js
Simplest way for leading zero padding in JavaScript
View number-pad-zero.js
Number.prototype.pad = function(size) {
var s = String(this);
while (s.length < (size || 2)) {s = "0" + s;}
return s;
}
(1).pad(3) // => "001"
(10).pad(3) // => "010"
(100).pad(3) // => "100"
You can’t perform that action at this time.