Skip to content

Instantly share code, notes, and snippets.

artoodetoo

  • Freelancer
Block or report user

Report or block artoodetoo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@artoodetoo
artoodetoo / example.php
Created Jan 20, 2019
Laravel: run standalone console script without touching the project code
View example.php
<?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 Jan 20, 2019
Example webpack config to concat jQuery plugins but use external jQuery instance
View app.js
window.moment = require('moment');
require('daterangepicker');
require('bootstrap-select');
@artoodetoo
artoodetoo / readme.txt
Last active May 23, 2018
DST problem demo
View readme.txt
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 Jan 21, 2018
Flatten PHP array
View result.txt
C:\>php flatten.php
array(4) {
[0]=>
int(11)
[1]=>
int(12)
[2]=>
int(13)
[3]=>
int(14)
@artoodetoo
artoodetoo / nogap.php
Last active Dec 29, 2018
Efficient Geo IP location in MySQL database
View nogap.php
#!/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 Feb 20, 2016
Use file_get_contents() with cookies and proxy (optionally with auth)
View file_get_contents_ex.php
<?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 Feb 12, 2016
Start infinite loop PHP from web
View loop.php
<?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 Apr 17, 2015
Unlimited dimensions INI file
View deep_load.php
<?php
/**
* Unroll dot-sequenced keys to new dimension
* @param array $source
* @return array
*/
function deep_load($source)
{
$result = [];
@artoodetoo
artoodetoo / .htaccess
Last active Aug 29, 2015
Image thumbnail helper
View .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/thumb/
RewriteRule ^(.*)$ thumb.php [QSA,L]
</IfModule>
@artoodetoo
artoodetoo / long_file_proceed.php
Last active Aug 29, 2015
Long XML file progress skeleton (CLI)
View long_file_proceed.php
<?php
/**
* Parse XML item with attributes. Typically dumped table row.
* @param string $buffer XML item
* @return array false| array [name => value, ...]
*/
function parse_row($buffer)
{
$buffer = trim($buffer);
You can’t perform that action at this time.