Skip to content

Instantly share code, notes, and snippets.

@laocoi
laocoi / config.js
Created Dec 27, 2019 — forked from codediodeio/config.js
Snippets from the Firestore Data Modeling Course
View config.js
import * as firebase from 'firebase/app';
import 'firebase/firestore';
var firebaseConfig = {
// your firebase credentials
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
@laocoi
laocoi / vietnamese-slug.js
Last active Jun 11, 2022
Create Vietnamese slug from string - Javascript
View vietnamese-slug.js
function slugify(string){
const a = 'àáäâãåăæąçćčđďèéěėëêęğǵḧìíïîįłḿǹńňñòóöôœøṕŕřßşśšșťțùúüûǘůűūųẃẍÿýźžż·/_,:;'
const b = 'aaaaaaaaacccddeeeeeeegghiiiiilmnnnnooooooprrsssssttuuuuuuuuuwxyyzzz------'
const p = new RegExp(a.split('').join('|'), 'g')
return string.toString().toLowerCase()
.replace(/á|à|||ã|ă||||||â|||||/gi, 'a')
.replace(/é|è||||ê|ế||||/gi, 'e')
.replace(/i|í|ì||ĩ|/gi, 'i')
.replace(/ó|ò||õ||ô||||||ơ|||||/gi, 'o')
.replace(/ú|ù||ũ||ư|||||/gi, 'u')
View svg-viewer.php
<?php
$list = [];
$err = '';
$path = filter_input( INPUT_GET, 'path');
if ( !$path )
{
$err = 'Path is empty';
@laocoi
laocoi / PHP enable CORS
Created Apr 22, 2019
The following snippet should give you a quick overview about the required HTTP headers to set for CORS to work.
View PHP enable CORS
$allowedOrigins = array(
'(http(s)://)?(www\.)?my\-domain\.com'
);
if (isset($_SERVER['HTTP_ORIGIN']) && $_SERVER['HTTP_ORIGIN'] != '') {
foreach ($allowedOrigins as $allowedOrigin) {
if (preg_match('#' . $allowedOrigin . '#', $_SERVER['HTTP_ORIGIN'])) {
header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
header('Access-Control-Max-Age: 1000');
@laocoi
laocoi / remove-words.php
Created Dec 14, 2018 — forked from keithmorris/remove-words.php
PHP remove common words from a string
View remove-words.php
<?php
function removeCommonWords($input){
// EEEEEEK Stop words
$commonWords = array('a','able','about','above','abroad','according','accordingly','across','actually','adj','after','afterwards','again','against','ago','ahead','ain\'t','all','allow','allows','almost','alone','along','alongside','already','also','although','always','am','amid','amidst','among','amongst','an','and','another','any','anybody','anyhow','anyone','anything','anyway','anyways','anywhere','apart','appear','appreciate','appropriate','are','aren\'t','around','as','a\'s','aside','ask','asking','associated','at','available','away','awfully','b','back','backward','backwards','be','became','because','become','becomes','becoming','been','before','beforehand','begin','behind','being','believe','below','beside','besides','best','better','between','beyond','both','brief','but','by','c','came','can','cannot','cant','can\'t','caption','cause','causes','certain','certainly','changes','clearly','c\'mon','co','co.','com','come','comes','concerni
@laocoi
laocoi / nginx.conf
Created Sep 2, 2018 — forked from jrom/nginx.conf
nginx hack for multiple conditions
View nginx.conf
if ($request_uri = /) {
set $test A;
}
if ($host ~* teambox.com) {
set $test "${test}B";
}
if ($http_cookie !~* "auth_token") {
set $test "${test}C";
View Tăng size volume Digitalocean.md

Kiểm tra dung lượng hiện tại

df -h -x tmpfs -x devtmpfs

Tăng trong dashboard

Cập nhật

@laocoi
laocoi / Compile FFmpeg on CentOS - RHEL 5-6-7.md
Created Jun 28, 2018
This guide is in view of an insignificant establishment of the most recent CentOS discharge, and will provide a local, non-framework establishment of FFmpeg with support for a few outside encoding libraries.
View Compile FFmpeg on CentOS - RHEL 5-6-7.md

In your home directory make a new directory to put all of the source code into:

yum install autoconf automake cmake freetype-devel gcc gcc-c++ git libtool make mercurial nasm pkgconfig zlib-devel
mkdir ~/ffmpeg_sources
cd ~/ffmpeg_sources
git clone --depth 1 git://github.com/yasm/yasm.git
cd yasm
autoreconf -fiv
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin"
make
View Auto add nofollow to link - php.md
View gist:a346a13b6d2e1ec33cb0b32652e8d1a6
/*
Copyright 2011 Martin Hawksey
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software