Skip to content

Instantly share code, notes, and snippets.

View artoodetoo's full-sized avatar
:octocat:
gitting

Alexandr Materukhin artoodetoo

:octocat:
gitting
View GitHub Profile
<?php
class JpegSectionIterator implements \Iterator
{
const
UNKNOWN = 'unknown',
SOI = 'SOI', // Start Of Image
SOF0 = 'SOF0', // Start Of Frame (baseline DCT)
SOF1 = 'SOF1', // Start Of Frame (extended DCT)
SOF2 = 'SOF2', // Start Of Frame (progressive DCT)
@artoodetoo
artoodetoo / example.php
Created January 20, 2019 10:27
Laravel: run standalone console script without touching the project code
<?php
/*
* The code mostly peeped in artisan executable file.
* Put this file to project root (one level above DocumentRoot) and run
* $ php example.php
*/
if (php_sapi_name() !== 'cli') {
die('This file can be executed from console only');
}
@artoodetoo
artoodetoo / app.js
Last active January 20, 2019 10:12
Example webpack config to concat jQuery plugins but use external jQuery instance
window.moment = require('moment');
require('daterangepicker');
require('bootstrap-select');
@artoodetoo
artoodetoo / readme.txt
Last active May 23, 2018 23:11
DST problem demo
For timezone 'Australia/Melbourne':
2018-03-31 10:00:00
+ 24*60*60 == 2018-04-01 09:00:00
strtotime(+1 day) == 2018-04-01 10:00:00
DateTime->add(1d) == 2018-04-01 10:00:00
2018-10-06 10:00:00
+ 24*60*60 == 2018-10-07 11:00:00
strtotime(+1 day) == 2018-10-07 10:00:00
DateTime->add(1d) == 2018-10-07 10:00:00
@artoodetoo
artoodetoo / result.txt
Created January 21, 2018 11:46
Flatten PHP array
C:\>php flatten.php
array(4) {
[0]=>
int(11)
[1]=>
int(12)
[2]=>
int(13)
[3]=>
int(14)
@artoodetoo
artoodetoo / nogap.php
Last active April 1, 2023 22:19
Efficient Geo IP location in MySQL database
#!/usr/bin/env php
<?php
/*
* Filter to fill the IP gaps in a MaxMind GeoLite tables.
*
* For every missing range in the file it puts a dummy one.
*/
$types = [
'asnum' => [0, 0, 1, "%s,%s,\"-\"\n"],
'blocks' => [2, 0, 1, "\"%s\",\"%s\",\"1\"\n"],
@artoodetoo
artoodetoo / file_get_contents_ex.php
Created February 20, 2016 18:56
Use file_get_contents() with cookies and proxy (optionally with auth)
<?php
function file_get_contents_ex($url, $cookie = null, $proxy = null, $auth = null)
{
$opts = array(
'http' => array(
'method' => 'GET',
'user-agent'=> 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36',
'header' => "Accept-language: en\r\n" .
(!empty($auth) ? "Proxy-Authorization: Basic {$auth}\r\n" : '') .
@artoodetoo
artoodetoo / loop.php
Created February 12, 2016 17:33
Start infinite loop PHP from web
<?php
class FileHelper
{
public static function openAndLock($filename)
{
$fh = fopen($filename, 'r+');
if (!$fh || !flock($fh, LOCK_EX)) {
return false;
}
@artoodetoo
artoodetoo / deep_load.php
Created April 17, 2015 09:28
Unlimited dimensions INI file
<?php
/**
* Unroll dot-sequenced keys to new dimension
* @param array $source
* @return array
*/
function deep_load($source)
{
$result = [];
@artoodetoo
artoodetoo / .htaccess
Last active November 11, 2019 11:52
Image thumbnail helper
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/thumb/
RewriteRule ^(.*)$ thumb.php [QSA,L]
</IfModule>