Skip to content

Instantly share code, notes, and snippets.

View georgebent's full-sized avatar

Yuriy Kr georgebent

View GitHub Profile
@georgebent
georgebent / appache_settings.txt
Last active March 6, 2018 07:39
Apache 2 Server Settings
<VirtualHost localhost:80>
ServerName test.dev
ServerAlias www.test.dev
DocumentRoot /home/yura/projects/test.dev
<directory /home/yura/projects/test.dev>
AllowOverride All
Require all granted
</directory>
ErrorLog /home/yura/projects/test.dev/logs/error.log
LogLevel warn
@georgebent
georgebent / changeFileNames.php
Last active June 17, 2023 15:16
PHP examples
<?php
$i = 1;
$path = 'files/'; // path to files
$separator = '-logo-'; // separator to divide the string and take the first part
$errors = [];
foreach (glob($path . '*.*') as $name) {
$filename = basename($name);
$arrayOfString = explode($separator, $filename);
@georgebent
georgebent / getIp.php
Last active March 3, 2018 08:38
PHP examples
function getIp()
{
//check ip from share internet
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
return $_SERVER['HTTP_CLIENT_IP'];
}
//to check ip is pass from proxy
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
return $_SERVER['HTTP_X_FORWARDED_FOR'];
@georgebent
georgebent / loadStyles.js
Last active October 19, 2017 15:38
optimizeCSSLoading
var loadDeferredStyles = function() {
var addStylesNode = document.getElementById("deferred-styles");
var replacement = document.createElement("div");
replacement.innerHTML = addStylesNode.textContent;
document.body.appendChild(replacement)
addStylesNode.parentElement.removeChild(addStylesNode);
};
var raf = requestAnimationFrame || mozRequestAnimationFrame ||
webkitRequestAnimationFrame || msRequestAnimationFrame;
if (raf) raf(function() { window.setTimeout(loadDeferredStyles, 0); });
@georgebent
georgebent / updating node
Last active May 11, 2018 08:27
node update commands
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
# if not working
sudo ln -sf /usr/local/n/versions/node/<VERSION>/bin/node /usr/bin/nodejs
@georgebent
georgebent / htpassword.txt
Last active November 20, 2017 18:11
Auth for pages by htaceess
// for passwords add to ht.access
AuthType Basic
AuthName "Private zone. Only for administrator!"
AuthUserFile /home/path/to/site.dev/.htpasswd
require valid-user
// and run command
htpasswd -c /home/path/to/site.dev/.htpasswd admin
cd /etc/nginx/sites-available/
sudo touch new.site.conf
sudo nano new.site.conf
cd ../sites-enabled
sudo ln -s ../sites-available/new.site.conf .
sudo mcedit /etc/hosts
sudo nginx -t
@georgebent
georgebent / sql_commands.txt
Last active June 25, 2018 08:23
Commands for SQL dumps
To export
If it's an entire DB, then:
$ mysqldump -u [uname] -p[pass] db_name > db_backup.sql
If it's all DBs, then:
$ mysqldump -u [uname] -p[pass] --all-databases > all_db_backup.sql
If it's specific tables within a DB, then:
$ mysqldump -u [uname] -p[pass] db_name table1 table2 > table_backup.sql
@georgebent
georgebent / informer.ino
Last active March 15, 2019 22:27
Arduino temperature humidity sensor
#include "DHT.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define DHTPIN 4
LiquidCrystal_I2C lcd(0x3F, 16, 2);
DHT dht(DHTPIN, DHT11);
void setup() {
Serial.begin(9600);
@georgebent
georgebent / paginator.blade.php
Created March 21, 2019 08:03
Custom Laravel Paginator
@if (isset($paginator) && $paginator->lastPage() > 1)
<ul class="pagination">
<?php
$interval = isset($interval) ? abs(intval($interval)) : 3 ;
$from = $paginator->currentPage() - $interval;
if($from < 1){
$from = 1;
}