This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* | |
* usage: node server.js folder port | |
* - folder is "." by default which is the current directory where node has been executed. | |
* - port is "8080" by default and you can specify any available port in your OS. | |
* | |
*/ | |
const http = require('http') | |
const fs = require('fs') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function configureTimeAgo(element) { | |
const elementID = element.getAttribute('id') | |
let updater = setInterval(function() { | |
const elementStillExistInDOM = document.getElementById(elementID) | |
if (!elementStillExistInDOM) { | |
clearInterval(updater) | |
return; | |
} | |
const seconds = (Date.now() - parseFloat(element.dataset.timestamp)) / 1000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function file_changed { | |
# compares md5 hashes of the files and returns boolean | |
# usage: if file_changed file1.ext file2.ext; then ... | |
local return_=1 | |
# get md5 hash of the first file | |
local m=($(openssl md5 $1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# set env vars from .env file | |
set -a | |
. $1 | |
set +a | |
# set backup filename | |
datetime=$(date +%Y-%m-%d-%H-%M-%S) | |
filename="${datetime}.gz" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
last 3 versions | |
> 0.1% | |
not ie <= 9 | |
# enter "npx browserslist" in the terminal to see which browsers supported. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mongodb://$user:$password@localhost:27027/?authMechanism=DEFAULT&authSource=$dbname | |
mongodb://$user:$password@$host1:27017,$host2:27017/?replicaSet=rs0&authMechanism=DEFAULT&authSource=$dbname |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# check if user doesn't exist | |
function user_doesnt_exist { | |
if id -u "$1" >/dev/null 2>&1; then | |
return 1 | |
else | |
return 0 | |
fi | |
} | |
# usage. do something if the user abc doesn't exist. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const os = require('os') | |
const crypto = require('crypto') | |
const path = require('path') | |
const fs = require('fs') | |
const util = require('util') | |
const puppeteer = require('puppeteer') | |
const libxml = require('libxmljs') | |
const dayjs = require('dayjs') | |
// generates static html files for server side rendering |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import floor, fabs | |
from PIL import Image, ImageSequence | |
def transform_image(original_img, crop_w, crop_h): | |
""" | |
Resizes and crops the image to the specified crop_w and crop_h if necessary. | |
Works with multi frame gif and webp images also. | |
args: | |
original_img is the image instance created by pillow ( Image.open(filepath) ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
apt update | |
apt install python3-pip -y | |
apt install libjpeg8-dev zlib1g-dev libtiff-dev libfreetype6 libfreetype6-dev libwebp-dev libopenjp2-7-dev libopenjp2-7-dev -y | |
pip3 install pillow --global-option="build_ext" --global-option="--enable-zlib" --global-option="--enable-jpeg" --global-option="--enable-tiff" --global-option="--enable-freetype" --global-option="--enable-webp" --global-option="--enable-webpmux" --global-option="--enable-jpeg2000" |