Skip to content

Instantly share code, notes, and snippets.

Nam Le namcoder

View GitHub Profile
View init.vim
call plug#begin('~/.vim/plugged')
Plug 'junegunn/vim-easy-align'
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'w0rp/ale'
Plug 'itchyny/lightline.vim'
Plug 'tpope/vim-surround'
Plug 'morhetz/gruvbox'
Plug 'pangloss/vim-javascript'
Plug 'scrooloose/nerdcommenter'
Plug 'chemzqm/vim-jsx-improve'
@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
@namcoder
namcoder / unaccent.rules
Created Jul 19, 2019
unaccent.rules for Vietnamese
View unaccent.rules
© (C)
« <<
­ -
® (R)
» >>
¼ 1/4
½ 1/2
¾ 3/4
À A
Á A
@namcoder
namcoder / react-waiting-user-end-typing.js
Created Jul 18, 2019
React trick: Waiting for user stop typing then beign search. Does not take search for every key, save performance
View react-waiting-user-end-typing.js
searchPost = value =>{
clearTimeout(this.timeout)
this.timeout = setTimeout(() => {
if(value.length < 1) return
return console.log('begin search: ', value)
}, 500)
}
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 / login-fshare.php
Created Sep 23, 2018
new way to login fshare
View login-fshare.php
<?php
$filename = 'cookie.txt';
if (file_exists($filename)) {
if(time()-filemtime($filename) > 12 * 3600)
{
$ch = curl_init();
@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 / zero-before.js
Created Jun 24, 2018
Add Zero before number less than 10
View zero-before.js
('0' + 11).slice(-2) // '11'
('0' + 4).slice(-2) // '04'
For ease of access, you could of course extract it to a function, or even extend Number with it:
Number.prototype.pad = function(n) {
return new Array(n).join('0').slice((n || 2) * -1) + this;
}
Which will allow you to write:
c += deg.pad() + '° '; // "04° "
@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.