Skip to content

Instantly share code, notes, and snippets.

View kirilkirkov's full-sized avatar
🎯
Focusing

Kiril Kirkov kirilkirkov

🎯
Focusing
View GitHub Profile
@kirilkirkov
kirilkirkov / array_in_lenght
Created July 17, 2015 13:38
Return a size in bytes,kilobytes,megabytes and gigabytes for given array or string. Can be used if you want to check performance for some script.
<?php
function array_size($arr) {
$byte = 0;
foreach ($arr as $key => $val) {
$byte += is_array($val) ? array_size($val) : mb_strlen($val);
}
$kb = number_format($byte / 1024, 4);
$mb = number_format($byte / 1048576, 4);
$gb = number_format($byte / 1073741824, 4);
$result = array('Bytes: ' => $byte, 'Kilobytes: ' => $kb, 'Megabytes: ' => $mb, 'Gigabytes: ' => $gb);
@kirilkirkov
kirilkirkov / divs_changing(Carousel)
Created July 17, 2015 13:39
Simple div changing like Carousel. JS gets all divs with class game and rotate him. Compatibility Tested in jscc.info .
@kirilkirkov
kirilkirkov / get_highlight
Created July 17, 2015 13:40
Return highlight hex color for string. Can be used in loop. Return same color for same strings and different for others
<?php
function get_highlight($str) {
$colors = array('#ccddee', '#ffdddd', '#ddccee',
'#ddeecc', '#eeccdd', '#cceedd',
'#eeddcc', '#ddddff', '#ddffdd');
shuffle($colors);
static $prev_color = '';
static $arr = array();
if (!in_array($str, $arr)) {
$arr[] = $str;
@kirilkirkov
kirilkirkov / popUp
Created July 17, 2015 13:41
ReSizable popup with cookies for one time opening
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
</head>
<body>
<!-- Popup -->
<div id="overlay" style="display:none; position: fixed; width: 100%; height: 100%; background-color: black; z-index:1101; opacity:0.7; filter: alpha(opacity=70); top:0; left:0;"></div>
<div id="popup" style="display:none; z-index:1101; position: fixed; width:100%; max-width:700px; height:100%; max-height:572px; top: 50%; left: 50%; margin-top: -286px; margin-left: -350px;">
<a href="#" style="color:#fff; float:right; font-weight:bold;" onClick="setCookie()">Close <span class="glyphicon glyphicon-remove"></span></a>
<div style="width:700px; height:572px; background-color:#000;"></div>
@kirilkirkov
kirilkirkov / rgb_den
Created July 17, 2015 13:41
Give rgb color and percent and function will return you same color but brighter according to percent. From 0% to 100%. Example: <?php echo rgb_gen('64,128,0', '50%'); ?>
<?php
function rgb_gen($rgb, $percent) {
$cleaned_percent = preg_replace("/\..*|%/", "", $percent);
$rgb_increment = 100 - $cleaned_percent;
$rgb_arr = explode(',', $rgb);
$rgb_arr[0] + $rgb_increment <= 255 ? $rgb_arr[0]+=$rgb_increment : $rgb_arr[0] = 255;
$rgb_arr[1] + $rgb_increment <= 255 ? $rgb_arr[1]+=$rgb_increment : $rgb_arr[1] = 255;
$rgb_arr[2] + $rgb_increment <= 255 ? $rgb_arr[2]+=$rgb_increment : $rgb_arr[2] = 255;
$new_rgb = implode(',', $rgb_arr);
return $new_rgb;
@kirilkirkov
kirilkirkov / config_reverse_proxy
Last active August 24, 2020 04:07
How To Configure Nginx as a Reverse Proxy for Apache (Linux)
I will consider that you have three servers. First one with apache, second one with nginx server and third with bind.
1: Go to bind server (/etc/bind/zones/) and setup new A records to site that we will run.
- nginx5 IN A 192.168.0.1
- apache5 IN A 192.168.0.2
2: Set vhost with new site for port 8080 (/etc/apache2/sites-available/)
<VirtualHost *:8080>
ServerName apache5.mysite.com
ServerAdmin webmaster@localhost
@kirilkirkov
kirilkirkov / what_are_reverse_and_forward_proxy
Last active March 23, 2016 09:45
Difference Between Forward Proxy And Reverse Proxy
The previous answers were accurate, but perhaps too terse. I will try to add some examples.
First of all, the word "proxy" describes someone or something acting on behalf of someone else.
In the computer realm, we are talking about one server acting on the behalf of another computer.
For the purposes of accessibility, I will limit my discussion to web proxies - however, the idea of a proxy is not limited to web sites.
FORWARD proxy
Most discussion of web proxies refers to the type of proxy known as a "forward proxy."
@kirilkirkov
kirilkirkov / prepare.php
Created July 27, 2015 14:31
Example about prepare statements. No SQL Injections... no bugs, be safe
<?php
$servername = "localhost";
$username = "root";
$password = "toor";
$dbname = "test";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
@kirilkirkov
kirilkirkov / gist:820db876ae69df969a49
Created July 27, 2015 14:59
Installing SNMP Deamon on Ubuntu and connecting to him .
Installation on server:
sudo apt-get update
sudo apt-get install snmpd
sudo vim /etc/snmp/snmpd.conf
------------------
# Listen for connections from the local system only
#agentAddress udp:127.0.0.1:161
# Listen for connections on all interfaces (both IPv4 *and* IPv6)
agentAddress udp:161,udp6:[::1]:161
@kirilkirkov
kirilkirkov / pagination_helper.php
Created July 28, 2015 07:48
Bootstrap pagination helper for CodeIgniter
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
function pagination($url, $rowscount, $per_page) {
$ci = & get_instance();
$ci->load->library('pagination');
$config = array();
$config["base_url"] = base_url($url);
$config["total_rows"] = $rowscount;
$config["per_page"] = $per_page;