Skip to content

Instantly share code, notes, and snippets.

View dejurin's full-sized avatar
💭
;-)

YURII D. dejurin

💭
;-)
  • Si-ɑR
  • București, România 🇷🇴
  • 08:25 (UTC +03:00)
View GitHub Profile
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 / {
@dejurin
dejurin / currency-symbol-map-array.php
Last active February 5, 2019 23:49
PHP Currency Symbol Map
<?php
$arr = [
'AED' => 'د.إ',
'AFN' => '؋',
'ALL' => 'L',
'AMD' => '֏',
'ANG' => 'ƒ',
'AOA' => 'Kz',
'ARS' => '$',
@dejurin
dejurin / currency-by-country-array.php
Created February 6, 2019 00:00
PHP Currency by country
<?php
$arr = [
'BD' => 'BDT',
'BE' => 'EUR',
'BF' => 'XOF',
'BG' => 'BGN',
'BA' => 'BAM',
'BB' => 'BBD',
'WF' => 'XPF',
@dejurin
dejurin / http-benchmark.md
Created December 15, 2019 23:12 — forked from denji/http-benchmark.md
HTTP(S) Benchmark Tools / Toolkit for testing/debugging HTTP(S) and restAPI (RESTful)
@dejurin
dejurin / nginx.conf
Created December 18, 2019 13:04 — 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/
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@dejurin
dejurin / hikOverlay.php
Created September 17, 2020 12:22
Insert Weather into Hikvision IP CAM via Text Overlay
<?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 / round-number.js
Last active November 2, 2020 10:35
Round to at most 2 decimal places (only if necessary)
// 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 / etag.php
Created December 22, 2020 23:05
How to use HTTP cache headers with 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 / mongoimport
Last active May 16, 2021 13:38
Import JSON file to MongoDB
mongoimport --db dbName --collection collectionName --file fileName.json --jsonArray
@dejurin
dejurin / gist:06d979d9a04e3a283ae6b3c22d4bd650
Created May 16, 2021 22:04 — forked from supairish/gist:2951524
Nginx - how to limit requests by User Agent
http {
map $http_user_agent $limit_bots {
default '';
~*(google|bing|yandex|msnbot) $binary_remote_addr;
}
limit_req_zone $limit_bots zone=bots:10m rate=1r/m;
server {