Skip to content

Instantly share code, notes, and snippets.

@Chengings
Chengings / gist:9597366
Last active August 29, 2015 13:57
Convert number with unit byte to bytes unit & get maximum file upload size of php
<?php
/**
* Convert number with unit byte to bytes unit
* @link https://en.wikipedia.org/wiki/Metric_prefix
* @param string $value a number of bytes with optinal SI decimal prefix (e.g. 7k, 5mb, 3GB or 1 Tb)
* @return integer|float A number representation of the size in BYTES (can be 0). otherwise FALSE
*/
function str2bytes($value) {
// only string
@Chengings
Chengings / gist:9599473
Created March 17, 2014 13:48
Escape php string to javascript string
<?php
/**
* Escape php string to javascript string
* @param string $str
* @return string escaped string
*/
function escape_javascript_string($str){
// if php supports json_encode, use it (support utf-8)
if (function_exists('json_encode')) {
@Chengings
Chengings / gist:9605009
Created March 17, 2014 18:12
Search in array value with partial match
<?php
/**
* Seach in array value, similar to in_array(), but has ability to search with partial match
* @param string $needle searched value
* @param array $haystack target array
* @param string $return_key if third parameter is set to TRUE, the function will return array key
* @return boolean|int|string if found, function will return TRUE, string or int of first founded key (if return_key set to TRUE)
* otherwise FALSE
*/
@Chengings
Chengings / gist:c7a4d4cae5abeb01b782
Last active August 29, 2015 14:15
Insert the string output to log file
<?php
private function _logfile($logName, $str2log)
{
$file= sys_get_temp_dir() . '/mydebug-' . date('Y-m-d') . '.log';
if (!$handle = fopen($file, 'a')) {
throw new Exception('Could not open file!');
}
$str2log = print_r($str2log, true);
$olog = print_r("{$logName}: {$str2log}", true) . PHP_EOL;
@Chengings
Chengings / style.css
Created January 1, 2019 07:11
Generic UI font
{
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}
@Chengings
Chengings / generic.md
Last active July 24, 2019 15:13
Settings
@Chengings
Chengings / apple-tv.txt
Created March 1, 2020 16:26
How to get Apple TV screensavers
Source: https://github.com/JohnCoates/Aerial/blob/master/Documentation/OfflineMode.md
1) Download resource file..
2) Extract and check `entries.json`.
3) Check url-* and get what you want.
@Chengings
Chengings / gist:028e98fbece098a1a6f1020658e372fe
Last active September 11, 2020 10:45
Xdebug with docker project in PHPStorm

Prerequisite

Set xdebug.remote_host=host.docker.internal and xdebug.remote_enable=1 in php.ini

  1. Set host, port and use path maaping with project in PHP Server preferences.
  2. Open "Run/Debug Configurations" dialog and set
    1. Set server from 1st step
    2. Set IDE Key to PHPSTORM

References

https://www.jetbrains.com/help/phpstorm/configuring-xdebug.html

@Chengings
Chengings / Symfony.md
Last active January 25, 2021 13:41
Symfony