$mt = microtime(TRUE);
foreach($y as $k => $v) {$z->$k = $v;}
$a = microtime(TRUE) - $mt;
print "Execution Time: " . ($a) . "\n";
Monday, May 25, 2020
Friday, February 14, 2020
Are PHP Objects passed as a value?
Yes they are, but as a copy of a value of a reference. Same as in Java.
Example below is showing how the Person type arguments are passed. In the point of entry of the methods changeName() and changeNameToNull(), $person reference copy is made.
From that point, a new reference can change the $person object in changeName(), as it has a reference to it. On the other hand, changeNameToNull() shows it is a copy of a reference, as setting to NULL value just destroys the copied reference, but not the $person object, thus original reference also.
<?php class Person { public $name = 'Mike'; } class Change { public function changeName(Person $person): void { $person->name = 'Jack'; } public function setPersonToNull(Person $person): void { $person = null; } } //set person to NULL $person1 = new Person(); (new Change())->setPersonToNull($person1); var_dump($person1); //change name to Jack $person2 = new Person(); (new Change())->changeName($person2); var_dump($person2);
Result:
object(Person)#1 (1) {
["name"]=>
string(4) "Mike"
}
object(Person)#2 (1) {
["name"]=>
string(4) "Jack"
}
Wednesday, August 22, 2018
PHP Foreach Key by Pointer
Here is a way to add a new elements to a new array in PHP foreach function, by reference on a new element.
$items = Item::get(); $formattedItems = []; foreach ($items as $item) { $fm = &$formattedItems[]; $fm['id'] = $item->id; $fm['label'] = $item->label; $fm['icon'] = $item->icon; } var_dump($formattedItems);
Simple and clean.
Get Service Instance Anywhere in Laravel
Inject Service Instance by Constructor
Code Example:
Code Example:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class MyController extends Controller
{
protected $client;
public function __construct(Client $client)
{
$this->client = $client;
}
public function store(Request $request)
{
$response = $this->client->message()->send([
'text' => $request->input('text'),
]);
}
}
Tuesday, June 5, 2018
PHP - remove all except letters, numbers, dashes and blanks
PHP - remove all except letters, numbers, dashes and blanks for various cases, like cleaning user input for DB storage, further execution and making it safe.
It's very easy to remove special characters.
$search = preg_replace('/[^a-zA-Z0-9 -]/', '', $search);
Also, if you would like to check if search string contains some characters, it's like this:
if (preg_match('/[^a-zA-Z0-9 -]/', $search)) {
echo 'invalid';
} else {
echo 'valid';
}
Or in opposite case, to chech only for special characters:
preg_match('/[$&+,:;=?@#|\<>^*()%!]/', $userInput)
Labels:
clean input,
PHP,
regex,
remove special characters.
Wednesday, February 28, 2018
Image Meta Data&EXIF Removal
There are a lot of tools claiming to clean meta data from image, but this one called JPEG & PNG Stripper works just awesome! It provides super easy and efficient meta removal.
Need bulk image cleaning? It's a piece of cake with this software. Just select your images and drag&drop in the application window. Plus, you'll get old school software feeling, back in a days when software did it's purpose, nothing more or less.
JPEG & PNG Stripper link
Friday, December 7, 2012
Lee Scratch Perry movie - Vision of paradise
Well, this isn't Lee's movie, it's about the Lee Scratch Perry! Volker Schaner, a German guy is making the movie about Lee's life for last 13 years! Right now the project came to the final phase, where it should be done some final editing which costs minimum $40.000 $20.000.
The movie can be seen as a guide for how to change the world with music – with a positive attitude, mindset or as Lee Perry calls it: “vibration”.The interview on this project
I you like Lee's work , you can support this project. If you wish to donate, you can do it on this lee perry movie link.
If you don't know about Lee Perry, it's time to find him out. As he is a living legend, a great MAN, a great musician and a world's peace-fighter, Lee is surely human race avant-garde in every and each way.
update :
There is a new kickstarter page for this project: Lee Scratch Perrys - Vision of paradise
Facebook page: leescratchperrys.visionofparadise
Official website : visionofparadise.de
If you don't know about Lee Perry, it's time to find him out. As he is a living legend, a great MAN, a great musician and a world's peace-fighter, Lee is surely human race avant-garde in every and each way.
update :
There is a new kickstarter page for this project: Lee Scratch Perrys - Vision of paradise
Facebook page: leescratchperrys.visionofparadise
Official website : visionofparadise.de
Saturday, March 10, 2012
Homemade bread
Dough
Baked bread
Of course, if you wish you can use the same dough to make pizza, this one is with onions.
Tuesday, February 28, 2012
We couldn't reach you by email. Please enter a valid email address - Facebook
Recently I've got error a message on facebook.com which says "We couldn't reach you by email. Please enter a valid email address". Personally I don't use nor like Facebook, but it is very valuable tool for some kinds of web promotions.
Slightly looking over the answers on this error message "We couldn't reach you by email. Please enter a valid email address" didnt give me a proper reason for this message. Some people said that FB or their "frauding policy" is guilty for this, but in my case error was caused by the mail delivery failure.
FB account was registered using "some" mail address. "Some" mail address is double-quoted because website-company that registered my mail has shut down my forum nick and my mail with no reason! Couple of last months weird situations has been going about this internet company and has become a forum topics in community in Serbia. I don't want to write company name because they are total losers, in way of internet reasoning.
Anyway, FB didn't make any mistake( which lots of people says) in my case, got the message "You successfully updated your email address. Please check your email to confirm your new address."
Just changed my mail in FB user panel and sat back on the horse. AAAAAAaaaAAAaaaaaaa
Slightly looking over the answers on this error message "We couldn't reach you by email. Please enter a valid email address" didnt give me a proper reason for this message. Some people said that FB or their "frauding policy" is guilty for this, but in my case error was caused by the mail delivery failure.
FB account was registered using "some" mail address. "Some" mail address is double-quoted because website-company that registered my mail has shut down my forum nick and my mail with no reason! Couple of last months weird situations has been going about this internet company and has become a forum topics in community in Serbia. I don't want to write company name because they are total losers, in way of internet reasoning.
Anyway, FB didn't make any mistake( which lots of people says) in my case, got the message "You successfully updated your email address. Please check your email to confirm your new address."
Just changed my mail in FB user panel and sat back on the horse. AAAAAAaaaAAAaaaaaaa
Sunday, February 5, 2012
AdSense interface in custom language
Hi folks, this post is dealing with unwanted language selection of AdSense interface. If you want to set back your AdSense interface in custom language, just pop in.
I've experienced unwanted language selection in AdSense interface and wanted to get it back to English. Accidentally I've clicked on some link to AdSense, but the URL contained language sign which I didn't saw at the time. After that click, my interface started to showing up always in Serbian language. I've tried to change language in my user panel, searched for solution on the internet, find out that lots of people are dealing with the same problem, but not find the proper solution. I've tried to clear the cookies, cache, history..etc., didn't help.
Some suggested that I should check English language in AdSense interface, under the settings. The thing is, it was already checked to English/US and I thought that solution isn't proper. Repetition of language checking doesn't seem to be the solution and for some people it didn't worked, according to the comments.
Anyway, I've found simple solution for wrong language interface. Following method did the job for me, as some may say, as a charm.
Simplified explanation of the solution
Log out from AdSense user interface, on login page change language sign in URL, reload page with that value and login.
More detailed solution
First, just sign out from AdSense interface and you will be redirected to the page that says:
You are now logged out.
Thank you for using AdSense!
«Return to AdSense
Thank you for using AdSense!
«Return to AdSense
Click Return to AdSense link and you will be redirected to the sign in page which has heading that says:
AdSense
Maximize revenue from your online content".
On that page you will have similar URL to this one,
https://accounts.google.com/ServiceLogin?service=adsense...................................................destination%3D/adsense/v3/home&hl=en_US
At the end of that URL sausage, you can see HL variable, which stands for Hall Of Languages (I suppose). If you want to get your interface, lets say in English, just type the value of HL variable to en_US, or to any that your prefers.
On the page Google language tools (thanks to googlesystem.blogspot.com) you can see a list of supported languages, under the heading "Use the Google Interface in Your Language". Put pointer on the desired language and look on the pointing link. In Firefox, you can see in lower left corner. For every link/language there is different HL value. You can use one of those values on your AdSense URL to change laguage. Look for the desired HL value and just type it to URL on AdSense logging page. Then click browser GO button or simply press Enter key. By doing this you will reload logging page, but this time in desired
language, which will be saved in further usage. Login in desired
language and there you go.
AdSense user interface doesn't support all of the languages, like Zulu or Esperanto.
Most of the languages are supported in user interface.
Cheers!
Tuesday, September 13, 2011
Heroes 3 on Windows 7 / 64 bit
Legendary game Heroes of Might and Magic 3, originally dated from 1999 is still very popular and is being played even today. Playing this game on Windows 7 / 64 bit was unable due to problem which was.........................Windows registry!
According to many previous "solutions", the problem was on backward compatibility built in Win7, so advises were to check Winows XP compatybility for .exe files in game and to add administrator right to game files. Those weren't worked in my case.
It turned out that the only and ultimate solution is to change the paths in the Win registry. Smart guy who have found the problem and the solution says:
This guy also has made registry file which changes this paths! link:Registry patch for Heroes 3
It means, you can make Heroes 3 playable in a few clicks. Just download a file, double click and play.
According to many previous "solutions", the problem was on backward compatibility built in Win7, so advises were to check Winows XP compatybility for .exe files in game and to add administrator right to game files. Those weren't worked in my case.
It turned out that the only and ultimate solution is to change the paths in the Win registry. Smart guy who have found the problem and the solution says:
Today, through research and test, got the final solution (absolute playable) as below:link: Heroes 3 on Win 7 64 bit
The main reason is the registry file (11.reg, maybe other on your PC, but should be *.reg file) wrote HEROES III’s data to an improper registry location.
Open and compare 11.reg data and x64 Windows Registry, the modification method is obvious:
It can be seen clearly from the registry: all data of 32-bit programs are located at HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node, not located at HKEY_LOCAL_MACHINE\SOFTWARE directly.
This guy also has made registry file which changes this paths! link:Registry patch for Heroes 3
It means, you can make Heroes 3 playable in a few clicks. Just download a file, double click and play.
Wednesday, December 8, 2010
Olive leaf tea
So, you are interested in Olive leaf tea? The Olive leaf tea I make, is made of hand picked leafs in Montenegro, Europe. First, I have picked leaves from the olive tree, dried it, chopped it, and take it to the glass jar with the tiny holes on the cap.
It should be a little more leaves in the cup of boiled water, and it should remain a little bit longer in the water, than the usual tea. Cover cup with the small saucer.
Try it, it has interesting, mild and pleasant taste, some say it has healing effects, for sure it has nice taste. Olive tea color is very weak, it is something between green and orange-yellow. I suppose it should to be consumed with out any sugar, honey or other supplement.
Olive leaf and its extracts is being used in medicine.
Wikipedia says:
Natural olive leaf and olive leaf extracts (OLE), are now marketed as anti-aging, immunostimulators, and even antibiotics. Clinical evidence has proven the blood pressure lowering effects of carefully extracted olive leaf extracts. Bioassays support its antibacterial, antifungal, and anti-inflammatory effects at a laboratory level. A liquid extract made directly from fresh olive leaves recently gained international attention when it was shown to have an antioxidant capacity almost double green tea extract and 400% higher than vitamin C.
Friday, November 26, 2010
Google Chrome memory leak - flash plugin problem
Hello folks, i have been using Firefox for a few years, and i was adoring the orange fox and its very useful plugins. I remember , 5 years ago, i went on FF from Internet Explorer 6 because of plenty IE security and viruses problems.
Firefox in following years became too slow for my computer, which isn't to bad - AMD Turion X2, 3 gigs of RAM, ATI chip set, 7200rpm hard drive. Firefox&surfing became enough good for my appetites and preferences.
In the meanwhile Google Chrome showed up. At the first glance, it looked very unique because of its very simple and flat look. It looked like how popular and user friendly web browser should look like. Great, but enough for me, I thought, I already had my loved Firefox and i was 100% satisfied with it. I continued to use Firefox. But, used Chrome at my friend's and ex boss's computer sometimes.
Eventually, Firefox become so slow for me, so i softly started to use Google Chrome as my main web browser, whenever Firefox was too slow for usual everyday surfing.
So, nowdays I am using Chrome for everyday surfing, and Firefox only when I need some of it's features or plugins for webdesign, such as Firebug(god bless you and your developers). Firefox beta 4 isn't significantly faster, i have tried it.
I am running Windows 7, using Chrome for surfing, sun is shining, birds are singing, some people on earth are starving to death( sad true)... everything is in normal for me. But, my Windows started to inform me about the low memory problem!! I have clicked right click on task bar, selected Start Task Manager, gone to Proceses to see which program is voraciously eating my memory, and saw Chrome using significantly more than 1 gigabytes of my RAM!! WTF, i thought? In the same time a had a problems with the crashing of Adobe Shockwave Flash player on some web sites, i suppose due to memory problems.
It appears that Chrome has some serious memory leaking problem, and it is related to the Flash player. So i googleed for that problem and didn't find out some useful solution, i tried updating Chrome and Flash player to latest versions, but it didn't helped.
So, I've tried something on my own, and got the solution!
Firefox in following years became too slow for my computer, which isn't to bad - AMD Turion X2, 3 gigs of RAM, ATI chip set, 7200rpm hard drive. Firefox&surfing became enough good for my appetites and preferences.
In the meanwhile Google Chrome showed up. At the first glance, it looked very unique because of its very simple and flat look. It looked like how popular and user friendly web browser should look like. Great, but enough for me, I thought, I already had my loved Firefox and i was 100% satisfied with it. I continued to use Firefox. But, used Chrome at my friend's and ex boss's computer sometimes.
Eventually, Firefox become so slow for me, so i softly started to use Google Chrome as my main web browser, whenever Firefox was too slow for usual everyday surfing.
So, nowdays I am using Chrome for everyday surfing, and Firefox only when I need some of it's features or plugins for webdesign, such as Firebug(god bless you and your developers). Firefox beta 4 isn't significantly faster, i have tried it.
I am running Windows 7, using Chrome for surfing, sun is shining, birds are singing, some people on earth are starving to death( sad true)... everything is in normal for me. But, my Windows started to inform me about the low memory problem!! I have clicked right click on task bar, selected Start Task Manager, gone to Proceses to see which program is voraciously eating my memory, and saw Chrome using significantly more than 1 gigabytes of my RAM!! WTF, i thought? In the same time a had a problems with the crashing of Adobe Shockwave Flash player on some web sites, i suppose due to memory problems.
It appears that Chrome has some serious memory leaking problem, and it is related to the Flash player. So i googleed for that problem and didn't find out some useful solution, i tried updating Chrome and Flash player to latest versions, but it didn't helped.
So, I've tried something on my own, and got the solution!
- Click on the wrench icon in the top right corner of your favorite browser
- Options
- Content settings
- Plug-ins
- Disable individual plug-ins
- Click on the plus sign on the right side
- Find the plugins(mines are those versions) Flash (2 files) - Version: 10.1.103.19 Shockwave Flash 10.1 r103
- You will find two Shockwave plugins active on Google Chrome
- Disable the one with the properties -
Description: Shockwave Flash 10.1 r102
Location: C:\Windows\system32\Macromed\Flash\NPSWF32.dll - Restart your Chrome and enjoy!
This configuration i have been using for a days, and never get a low memoy alert or Flash Shockwave chrash.
Cheers to Chrome fans.
Subscribe to:
Posts (Atom)







