Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
;-)

Yurii De dejurin

💭
;-)
  • Si-ɑR
  • 127.0.0.1
View GitHub Profile
@dejurin
dejurin / mongoimport
Last active May 16, 2021
Import JSON file to MongoDB
View mongoimport
mongoimport --db dbName --collection collectionName --file fileName.json --jsonArray
@dejurin
dejurin / etag.php
Created Dec 22, 2020
How to use HTTP cache headers with PHP
View etag.php
<?php
// https://stackoverflow.com/a/1973016/3360295
$tsstring = gmdate('D, d M Y H:i:s ', $timestamp) . 'GMT';
$etag = $language . $timestamp;
$if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false;
$if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? $_SERVER['HTTP_IF_NONE_MATCH'] : false;
if ((($if_none_match && $if_none_match == $etag) || (!$if_none_match)) &&
@dejurin
dejurin / round-number.js
Last active Nov 2, 2020
Round to at most 2 decimal places (only if necessary)
View round-number.js
// Solution 1 is to use a script with required rounding algorithm, for example:
// https://stackoverflow.com/questions/11832914/round-to-at-most-2-decimal-places-only-if-necessary
function roundNumber(num, scale) {
if (!(`${num}`).includes('e')) {
return +(`${Math.round(`${num}e+${scale}`)}e-${scale}`);
}
const arr = (`${num}`).split('e');
let sig = '';
if (+arr[1] + scale > 0) {
sig = '+';
@dejurin
dejurin / hikOverlay.php
Created Sep 17, 2020
Insert Weather into Hikvision IP CAM via Text Overlay
View hikOverlay.php
<?php
// https://api.openweathermap.org/data/2.5/weather?id=709114&appid=&units=metric&mode=json
// This code you can add to CRON
Class hikOverlay {
function __construct(object $config = null) {
if (isset($config)) {
foreach($config as $key => $value) {
$this->$key = (object) $value;
@dejurin
dejurin / nginx.conf
Created Dec 18, 2019 — forked from plentz/nginx.conf
Best nginx configuration for improved security(and performance). Complete blog post here http://tautt.com/best-nginx-configuration-for-security/
View nginx.conf
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@dejurin
dejurin / http-benchmark.md
Created Dec 15, 2019 — forked from denji/http-benchmark.md
HTTP(S) Benchmark Tools / Toolkit for testing/debugging HTTP(S) and restAPI (RESTful)
View http-benchmark.md
View currency-by-country-array.php
<?php
$arr = [
'BD' => 'BDT',
'BE' => 'EUR',
'BF' => 'XOF',
'BG' => 'BGN',
'BA' => 'BAM',
'BB' => 'BBD',
'WF' => 'XPF',
View currency-symbol-map-array.php
<?php
$arr = [
'AED' => 'د.إ',
'AFN' => '؋',
'ALL' => 'L',
'AMD' => '֏',
'ANG' => 'ƒ',
'AOA' => 'Kz',
'ARS' => '$',
View codeigniter4.tpl
server {
listen %ip%:%web_port%;
server_name %domain_idn% %alias_idn%;
root %docroot%;
index index.php index.html index.htm;
access_log /var/log/nginx/domains/%domain%.log combined;
access_log /var/log/nginx/domains/%domain%.bytes bytes;
error_log /var/log/nginx/domains/%domain%.error.log error;
location / {
View codeigniter4.stpl
server {
listen %ip%:%web_ssl_port% http2;
server_name %domain_idn% %alias_idn%;
root %sdocroot%;
index index.php index.html index.htm;
access_log /var/log/nginx/domains/%domain%.log combined;
access_log /var/log/nginx/domains/%domain%.bytes bytes;
error_log /var/log/nginx/domains/%domain%.error.log error;
ssl on;