Skip to content

Instantly share code, notes, and snippets.

@laocoi
laocoi / svg-viewer.php
Created May 27, 2019 10:57 — forked from AlekVolsk/svg-viewer.php
SVG viewer
<?php
$list = [];
$err = '';
$path = filter_input( INPUT_GET, 'path');
if ( !$path )
{
$err = 'Path is empty';
@laocoi
laocoi / PHP enable CORS
Created April 22, 2019 09:51
The following snippet should give you a quick overview about the required HTTP headers to set for CORS to work.
$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 December 14, 2018 08:47 — forked from keithmorris/remove-words.php
PHP remove common words from a string
<?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 September 2, 2018 17:09 — forked from jrom/nginx.conf
nginx hack for multiple conditions
if ($request_uri = /) {
set $test A;
}
if ($host ~* teambox.com) {
set $test "${test}B";
}
if ($http_cookie !~* "auth_token") {
set $test "${test}C";

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 June 28, 2018 14:29
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.

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
@laocoi
laocoi / haproxy.config
Created June 22, 2018 11:47 — forked from hzbd/haproxy.config
Sample HAProxy config with logging.
global
pidfile /var/run/haproxy.pid
log 127.0.0.1 local0 info
ulimit-n 65536
defaults
mode http
clitimeout 600000 # maximum inactivity time on the client side
srvtimeout 600000 # maximum inactivity time on the server side

Connect


use MongoDB\Client;
$con = new Client("mongodb://127.0.0.1:27017", array("username" => "xxxx", "password" => "yyyy"));

Find


$filter = ['field' => 'value'];
import requests
def download_file_from_google_drive(id, destination):
def get_confirm_token(response):
for key, value in response.cookies.items():
if key.startswith('download_warning'):
return value
return None
@laocoi
laocoi / Nginx-reverse-proxy.md
Created June 18, 2018 17:54
Sometime 502 bad gateway

Example config nginx reverse proxy

server {
	listen 80;
    server_name example.com www.example.com;
    return 301 https://www.example.com$request_uri;	
}
proxy_cache_path /home/cache levels=1:2 keys_zone=my_cache:10m max_size=10g inactive=60m use_temp_path=off;
upstream backend {