Skip to content

Instantly share code, notes, and snippets.

@gregorychalenko
gregorychalenko / time_since
Last active August 29, 2015 13:56
time since. Pirms 5 stundam 20 minutem
<?php
function( $datestamp, $tail_length = 2 )
{
$interval = date_diff( date_create(), date_create( $datestamp ) );
$chunks = '%Y:%M:%d:%H:%i:%s';
$interval = array_filter(
array_combine( explode( ':', $chunks ), explode(":", $interval->format( $chunks ) ) ),
'intval'
);

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

/*
bootstrap multiple modal z-index fixer
*/
(function($){
// default zindex for modal
var zIndex=1070, zStep=10, recursion=0,
backgroundColor="black",
backdrop, nativeAppend = $.fn.appendTo;
$.fn.appendTo = function()
{
<?php
// server
class MySoapServer
{
public function getMessage()
{
return 'Hello,World!';
}
// tinyxhr by Shimon Doodkin - licanse: public doamin - https://gist.github.com/4706967
//
// tinyxhr("http://site.com/ajaxaction",function (err,data,xhr){ if (err) console.log("goterr ",err,'status='+xhr.status); console.log(data) });
// tinyxhr("http://site.com/ajaxaction",function (err,data,xhr){ if (err) console.log("goterr ",err,'status='+xhr.status); console.log(data) },'POST','value1=1&value2=2');
// tinyxhr("http://site.com/ajaxaction.json",function (err,data,xhr){ if (err) console.log("goterr ",err,'status='+xhr.status); console.log(data); console.log(JSON.parse(data)) },'POST',JSON.stringify({value:1}),'application/javascript');
// cb - a callback function like: function (err,data,XMLHttpRequestObject){ if (err) throw err; }
//
function tinyxhr(url,cb,method,post,contenttype)
{
@gregorychalenko
gregorychalenko / install-comodo-ssl-cert-for-nginx.rst
Created April 18, 2016 14:50 — forked from bradmontgomery/install-comodo-ssl-cert-for-nginx.rst
Steps to install a Comodo PositiveSSL certificate with Nginx.

Setting up a SSL Cert from Comodo

I use Namecheap.com as a registrar, and they resale SSL Certs from a number of other companies, including Comodo.

These are the steps I went through to set up an SSL cert.

Purchase the cert

@gregorychalenko
gregorychalenko / crontab entry
Created July 9, 2016 17:52
backup multiple database
# backup tasks
# database backups
0 0 * * * /path/to/mysql.backup.sh -m dayly
0 1 * * 0 /path/to/mysql.backup.sh -m weekly
0 2 1 * * /path/to/mysql.backup.sh -m monthly
0 3 1 1 * /path/to/mysql.backup.sh -m yearly
@gregorychalenko
gregorychalenko / example.com
Last active July 28, 2016 22:43
letsencrypt example:
server
{
listen 80;
listen 443 ssl;
server_name example.com www.example.com;
location ~ /.well-known {
allow all;
}
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
@gregorychalenko
gregorychalenko / gist:01dd5742aad71478ad687c94d1311f62
Created March 31, 2017 09:49 — forked from rlemon/gist:1780212
PHP get CPU information from /proc/stat
<?php
/* Gets individual core information */
function GetCoreInformation() {
$data = file('/proc/stat');
$cores = array();
foreach( $data as $line ) {
if( preg_match('/^cpu[0-9]/', $line) )
{
$info = explode(' ', $line );
$cores[] = array(
@gregorychalenko
gregorychalenko / install.sh
Created May 10, 2017 13:45 — forked from ziadoz/install.sh
Install ChromeDriver and Selenium on Ubuntu 16.04
#!/usr/bin/env bash
# https://developers.supportbee.com/blog/setting-up-cucumber-to-run-with-Chrome-on-Linux/
# https://gist.github.com/curtismcmullan/7be1a8c1c841a9d8db2c
# http://stackoverflow.com/questions/10792403/how-do-i-get-chrome-working-with-selenium-using-php-webdriver
# http://stackoverflow.com/questions/26133486/how-to-specify-binary-path-for-remote-chromedriver-in-codeception
# http://stackoverflow.com/questions/40262682/how-to-run-selenium-3-x-with-chrome-driver-through-terminal
# http://askubuntu.com/questions/760085/how-do-you-install-google-chrome-on-ubuntu-16-04
# Remove existing downloads and binaries so we can start from scratch.
rm ~/google-chrome-stable_current_amd64.deb