Skip to content

Instantly share code, notes, and snippets.

@unicornist
unicornist / Centos7.md
Last active September 3, 2024 09:38
CentOS 7 Server Setup including NginX, NodeJs, MongoDB, Redis, Docker, etc...

Note: For newer versions of NodeJS, Nginx and MongoDB, checkout their websites and update the related parts.

0.Pre-requisites

run all the commands in terminal as the root user (sudo su)

yum update
yum install -y epel-release
@unicornist
unicornist / log-es6.js
Last active November 29, 2019 07:58
TimeStamped console.log
const log = (...args) => console.log(`[${new Date().toLocaleString()}]`, ...args);
module.exports = log;
// log(1,2,3) --> [2018-3-10 01:42:21] 1 2 3
// log([1,2,3]) --> [2018-3-10 01:43:47] [ 1, 2, 3 ]
// log('this is:', this) --> [2018-3-10 01:43:01] this is: { console: [Getter],............}
@vagarenko
vagarenko / maybe.ts
Last active November 6, 2022 06:50
Maybe type in Typescript.
/**
* The Maybe type encapsulates an optional value.
*/
export class Maybe<T> {
/** Create an empty value. */
static nothing<T>(): Maybe<T> {
return new Maybe<T>(undefined);
}
/** Create a non-empty value. */

Convert Video

Just Convert Format:
ffmpeg -i input.avi -c:v libx265 output.mp4
ffmpeg -i input.avi -c:v libx264 output.mp4
ffmpeg -i input.mp4 -c:v flv output.flv
Convert to H265 with smaller size and medium quality:
ffmpeg -i input.mp4 -c:v libx265 -crf 28 -vf "scale=iw/2:ih/2" -c:a copy output.mp4
ffmpeg -i input.mp4 -c:v libx265 -crf 28 -vf "scale=720:-1" -c:a copy output.mp4
ffmpeg -i input.mp4 -c:v libx265 -crf 28 -vf "scale=720:trunc(ow/a/2)*2" -c:a copy output.mp4

ffmpeg -i input.mp4 -c:v libx265 -crf 28 -vf "scale=trunc(oh*a/2)*2:720" -c:a copy output.mp4

@kaifius
kaifius / auto-pair-back-ticks.sublime-keymap
Last active March 13, 2021 07:18
Auto-pair backticks in sublime text
// add to User keybindings (find this file with cmd+shift+p; start typing `Key Bindings - User`)
// file located @ [$HOME]/Library/Application Support/Sublime\ Text 3/Packages/User/Default (OSX).sublime-keymap
[
// Auto-pair backticks
{ "keys": ["`"], "command": "insert_snippet", "args": {"contents": "`$0`"}, "context":
[
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|\\}|$)", "match_all": true }
]
// jalali date
JalaliDate = {
month_names: ["فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند"],
g_days_in_month: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
j_days_in_month: [31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29]
};
JalaliDate.jalaliToGregorian = function(j_y, j_m, j_d) {
j_y = parseInt(j_y);
j_m = parseInt(j_m);
j_d = parseInt(j_d);
@yzyzsun
yzyzsun / shadowsocks-libev.sh
Last active August 16, 2023 05:38
shadowsocks-libev server setup script on CentOS 7
cd /etc/yum.repos.d
curl -O https://copr.fedorainfracloud.org/coprs/librehat/shadowsocks/repo/epel-7/librehat-shadowsocks-epel-7.repo
yum -y install shadowsocks-libev
setcap CAP_NET_BIND_SERVICE=+eip /usr/bin/ss-server
cat > /etc/shadowsocks-libev/config.json << 'EOF'
{
"server": "0.0.0.0",
"server_port": 443,
"password": "p@$$w0rd",
"method": "aes-128-gcm"
@hotmeteor
hotmeteor / .sublime-keymap
Last active September 7, 2018 12:16
Sublime backtick auto-pair
{ "keys": ["`"], "command": "insert_snippet", "args": {"contents": "`$0`"}, "context":
[
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|\\}|>|$)", "match_all": true },
{ "key": "preceding_text", "operator": "not_regex_contains", "operand": "[`a-zA-Z0-9_]$", "match_all": true },
{ "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.backtick", "match_all": true }
]
},
{ "keys": ["`"], "command": "insert_snippet", "args": {"contents": "`${0:$SELECTION}`"}, "context":
@daytonn
daytonn / .colors
Created January 28, 2014 21:50
Bash Color functions
# Colors
end="\033[0m"
black="\033[0;30m"
blackb="\033[1;30m"
white="\033[0;37m"
whiteb="\033[1;37m"
red="\033[0;31m"
redb="\033[1;31m"
green="\033[0;32m"
greenb="\033[1;32m"
@denji
denji / nginx-tuning.md
Last active October 30, 2025 20:38
NGINX tuning for best performance

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.