Skip to content

Instantly share code, notes, and snippets.

View ivastly's full-sized avatar
💭
making the world a better place for someone else

Vasily Pyatykh ivastly

💭
making the world a better place for someone else
View GitHub Profile
@lisachenko
lisachenko / instantinators.php
Created August 1, 2018 08:11
Private class instantinators
<?php
/**
* Sealed class can not be created directly
*/
class Seal
{
private function __construct()
{
// private ctor prevents from direct creation of instance
}
@ivastly
ivastly / developer-tools-script.js
Created February 21, 2018 13:02
Script to spy for Whatsapp online status of your contacts even it is turned off in settings!
// just open web.whatsapp.com, navigate to the chat with victim and run this in developer tools. Once he/she becomes online,
// you will be notified in console NOTE if the language of your whatsapp interface is not english, change the 'online' string on line 6 accordingly
setInterval(function () {
if ($('span[title="online"]') !== null) {
console.info("ONLINE: " + (new Date()));
}
}, 20000);
@holmberd
holmberd / php-pools.md
Last active April 19, 2024 07:24
Adjusting child processes for PHP-FPM (Nginx)

Adjusting child processes for PHP-FPM (Nginx)

When setting these options consider the following:

  • How long is your average request?
  • What is the maximum number of simultaneous visitors the site(s) get?
  • How much memory on average does each child process consume?

Determine if the max_children limit has been reached.

  • sudo grep max_children /var/log/php?.?-fpm.log.1 /var/log/php?.?-fpm.log
@ManInTheBox
ManInTheBox / DateTimeImmutabilityExample.php
Created November 8, 2016 14:47
DateTime VS DateTimeImmutable example
<?php
class DateTimeImmutabilityExample
{
private $date;
/**
* Intentionaly no type hinting so you can test with both DateTime and DateTimeImmutable
*/
public function __construct($date)
@GhazanfarMir
GhazanfarMir / clear-images.sh
Last active January 21, 2024 19:27
Single shell script to remove all containers, images and volumes used by containers. The script first tries to stop containers if there is any running, then remove the containers, followed by images removal and finally the container volumes.
#!/bin/bash
###########################################
#
# Simple Shell script to clean/remove all container/images
#
# The script will
# - first stop all running containers (if any),
# - remove containers
# - remove images
# - remove volumes
@chuckreynolds
chuckreynolds / stopwatch.php
Created July 27, 2016 22:56
Simple "StopWatch" class to measure PHP execution time. The class can handle multiple separate timers at the same time
<?php
class StopWatch {
/**
* @var $startTimes array The start times of the StopWatches
*/
private static $startTimes = array();
/**
* Start the timer
*
@avtaniket
avtaniket / cors.php
Last active April 17, 2024 12:15
Handle CORS in PHP
<?php
/* Handle CORS */
// Specify domains from which requests are allowed
header('Access-Control-Allow-Origin: *');
// Specify which request methods are allowed
header('Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS');
@hkdobrev
hkdobrev / class-order.php
Last active September 7, 2023 09:08
PHP convention for the order in a class.
<?php namespace Vendor\Library;
use Another\Vendor\Library\ClassName;
abstract class ClassName extends AnotherClass implements Countable, Serializable
{
const CONSTANTS = 'top';
use someTrait, anotherTrait {
anotherTrait::traitMethod insteadof someTrait;
@tylerhall
tylerhall / strong-passwords.php
Created August 12, 2010 21:38
A user friendly, strong password generator PHP function.
<?PHP
// Generates a strong password of N length containing at least one lower case letter,
// one uppercase letter, one digit, and one special character. The remaining characters
// in the password are chosen at random from those four sets.
//
// The available characters in each set are user friendly - there are no ambiguous
// characters such as i, l, 1, o, 0, etc. This, coupled with the $add_dashes option,
// makes it much easier for users to manually type or speak their passwords.
//
// Note: the $add_dashes option will increase the length of the password by