Skip to content

Instantly share code, notes, and snippets.

View namcoder's full-sized avatar
🌴
On vacation "><img src=x onerror=alert(99)>

Nam Le namcoder

🌴
On vacation "><img src=x onerror=alert(99)>
View GitHub Profile
@namcoder
namcoder / cloudflare-worker-youtube-dl.js
Created September 7, 2020 08:36 — forked from hizkifw/cloudflare-worker-youtube-dl.js
Download YouTube videos with Cloudflare Worker
/**
* cloudflare-worker-youtube-dl.js
* Get direct links to YouTube videos using Cloudflare Workers.
*
* Usage:
* GET /?v=dQw4w9WgXcQ
* -> Returns a JSON list of supported formats
*
* GET /?v=dQw4w9WgXcQ&f=251
* -> Returns a stream of the specified format ID
@namcoder
namcoder / postgresql_id.sql
Created August 6, 2019 14:15 — forked from yohangdev/postgresql_id.sql
PostgreSQL Better ID & UUID Generator
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
@namcoder
namcoder / test-php-basic-auth.php
Created January 11, 2019 03:52 — forked from rchrd2/test-php-basic-auth.php
PHP basic auth example
<?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 August 30, 2018 04:19 — forked from caseyjustus/median.js
calculate the median of an array with javascript
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 June 24, 2018 14:49 — forked from endel/number-pad-zero.js
Simplest way for leading zero padding in JavaScript
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"
@namcoder
namcoder / Direct Link of YouTube videos.md
Last active September 4, 2020 04:00 — forked from egyjs/Direct Link of YouTube videos.md
PHP API To get Direct Link of YouTube videos
We couldn’t find that file to show.