Skip to content

Instantly share code, notes, and snippets.

View acidka's full-sized avatar
🏠
Working from home

Andrii Rusovych acidka

🏠
Working from home
View GitHub Profile
@acidka
acidka / walk_array.php
Created November 28, 2022 12:51 — forked from mlconnor/walk_array.php
php function to walk an array/object recursively
/**
* works for json objects. will replace all
* keys and values with the result of the
* closure.
*/
function walk_recursive($obj, $closure) {
if ( is_object($obj) ) {
$newObj = new stdClass();
foreach ($obj as $property => $value) {
$newProperty = $closure($property);
@acidka
acidka / ssh-mysql-tunnel-test.php
Created October 23, 2019 12:35 — forked from petenelson/ssh-mysql-tunnel-test.php
WordPress: MySQL PDO command via SSH tunnel
<?php
/**
* Plugin Name: SSH Remote Test
*/
add_action( 'admin_init', 'ssh_remote_test', 1 );
function ssh_remote_test() {
@acidka
acidka / main.go
Created February 17, 2019 00:06 — forked from enricofoltran/main.go
A simple golang web server with basic logging, tracing, health check, graceful shutdown and zero dependencies
package main
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"
/**
* Функция возвращает окончание для множественного числа слова на основании числа и массива окончаний
* @param iNumber Integer Число на основе которого нужно сформировать окончание
* @param aEndings Array Массив слов или окончаний для чисел (1, 4, 5),
* например ['яблоко', 'яблока', 'яблок']
* @return String
*/
function formatByCount(number, form1, form2, form3)
{
var count = Math.abs(number) % 100;
@acidka
acidka / new_gist_file.js
Created September 10, 2018 11:57 — forked from nmsdvid/new_gist_file.js
Simple JavaScript Debounce Function
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
clearTimeout(timeout);
@acidka
acidka / INSTALLV8JS.md
Last active September 9, 2018 17:26 — forked from koriym/INSTALLV8JS.md
How to install PHP 7.2 and V8Js in Ubuntu
apt update
apt upgrade
apt-get install python-software-properties
add-apt-repository -y ppa:ondrej/php 
add-apt-repository -y ppa:pinepain/libv8-archived
apt update
apt-get install php7.2 php7.2-curl php7.2-dev php7.2-mbstring php7.2-zip php7.2-mysql libv8-dev
pecl -d php_suffix=7.2 install v8js
echo 'extension=v8js.so' &gt;&gt; /etc/php/7.2/cli/conf.d/20-v8js.ini 
@acidka
acidka / cleanup_uft8_class.php
Created August 21, 2018 15:59 — forked from zeroasterisk/cleanup_uft8_class.php
A PHP class to cleanup strings to be UTF8
<?php
/* Standardized data cleanup helper class */
class Cleanup {
/**
* Make a string into UTF8 compliant... cleans funcky input characters
* @param mixed $str
* @return mixed $str
*/
static function makeUTF8($str) {
if (is_array($str)) {
@acidka
acidka / spintax.php
Created August 12, 2018 13:52 — forked from irazasyed/spintax.php
PHP: Text Spinner Class - Nested spinning supported.
<?PHP
/**
* Spintax - A helper class to process Spintax strings.
* @name Spintax
* @author Jason Davis - https://www.codedevelopr.com/
* Tutorial: https://www.codedevelopr.com/articles/php-spintax-class/
*/
class Spintax
{
public function process($text)
@acidka
acidka / 1_README.md
Created March 12, 2018 18:03 — forked from sergeyfedotov/1_README.md
Nginx + Lua image resize
@acidka
acidka / nearby-coordinates.sql
Created January 1, 2018 15:55 — forked from statickidz/nearby-coordinates.sql
Ordering with SQL by nearest latitude & longitude coordinates (MySQL & SQLite)
---
METHOD 1
This should roughly sort the items on distance in MySQL, and should work in SQLite.
If you need to sort them preciser, you could try using the Pythagorean theorem (a^2 + b^2 = c^2) to get the exact distance.
---
SELECT *
FROM table
ORDER BY ((lat-$user_lat)*(lat-$user_lat)) + ((lng - $user_lng)*(lng - $user_lng)) ASC