Skip to content

Instantly share code, notes, and snippets.

View nicklasos's full-sized avatar
💭
😅

Olkhovyk Mykyta nicklasos

💭
😅
View GitHub Profile
@nicklasos
nicklasos / download.php
Last active January 31, 2024 09:13
Curl PHP multiple files downloading
<?php
function multiple_download(array $urls, $save_path = '/tmp')
{
$multi_handle = curl_multi_init();
$file_pointers = [];
$curl_handles = [];
// Add curl multi handles, one per file we don't already have
foreach ($urls as $key => $url) {
@nicklasos
nicklasos / parallelforeach.php
Created November 5, 2014 10:03
php parallel fork
<?php
define('PROCESSES_NUM', 6);
/**
* @param array $arr
* @param callable $func
*/
function parallelForeach(array $arr, callable $func)
{
$pid = null;
apt-get install percona-toolkit
pt-online-schema-change --print --progress time,5 --max-load Threads_running=500 --critical-load Threads_running=5000 --chunk-time 5 --set-vars "innodb_lock_wait_timeout=600" --nocheck-plan --execute -h {localhost} -u {user} --p "{password}" --alter "ADD {column} varchar(32) DEFAULT NULL" D={database},t={table}
<?php
/*
* Convert seconds to human readable text.
* Found at: http://csl.sublevel3.org/php-secs-to-human-text/
*
*/
function secs_to_h($secs)
{
$units = [
SELECT
payments.paywall, paywall.views, payments.money
FROM
(SELECT p.paywall, concat("$", round(sum(p.productPrice)) AS money FROM payments AS p GROUP BY p.paywall) AS payments
LEFT JOIN
(SELECT pw.paywall, count(*) AS views FROM paywall AS pw GROUP BY pw.paywall) AS paywall ON payments.paywall = paywall.pay
@nicklasos
nicklasos / annotation_class.php
Last active February 4, 2018 16:22
php annotations
<?php
/**
* Class Person
* @Table people
*/
class Person
{
/**
* @Prop Yep
*/
@nicklasos
nicklasos / plists.erl
Last active November 14, 2017 10:40
Erlang. Parallel map
-module(plists).
-export([pmap/2,pforeach/2,npforeach/2, parmap/2]).
%%% Map
pmap(F, L) ->
S = self(),
Pids = lists:map(fun(I) -> spawn(fun() -> pmap_f(S, F, I) end) end, L),
pmap_gather(Pids).
@nicklasos
nicklasos / nginx.conf
Created November 11, 2017 12:18 — forked from AysadKozanoglu/jail.conf
fail2ban nginx 404 400 403 444 filter /etc/fail2ban/filter.d/nginx-4xx.conf
# nano /etc/fail2ban/filter.d/nginx-4xx.conf
#
[Definition]
failregex = ^<HOST>.*"(GET|POST).*" (404|444|403|400) .*$
ignoreregex =
@nicklasos
nicklasos / Permissions.php
Last active October 12, 2017 09:57
Laravel
<?php
namespace App\Services\Roles;
use App\User;
use Illuminate\Contracts\Auth\Access\Gate;
/**
* Class Permissions
* @package App\Services\Roles
*
@nicklasos
nicklasos / proxy.php
Last active October 12, 2017 09:55
php
<?php
if (($_SERVER['HTTP_PASSWORD'] ?? null) !== 'ProxyPassword') {
http_response_code(401);
exit();
}
$response = file_get_contents(urldecode($_GET['url']), false, stream_context_create([
'http' => [
'ignore_errors' => true,